com.netflix.spectator.api.Registry.propagate()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中com.netflix.spectator.api.Registry.propagate方法的一些代码示例,展示了Registry.propagate的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry.propagate方法的具体详情如下:
包路径:com.netflix.spectator.api.Registry
类名称:Registry
方法名:propagate

Registry.propagate介绍

[英]Log a warning and if enabled propagate the exception t. As a general rule instrumentation code should degrade gracefully and avoid impacting the core application. If the user makes a mistake and causes something to break, then it should not impact the application unless that mistake triggers a problem outside of the instrumentation code. However, in test code it is often better to throw so that mistakes are caught and corrected. This method is used to handle exceptions internal to the instrumentation code. Propagation is controlled by the RegistryConfig#propagateWarnings() setting. If the setting is true, then the exception will be propagated. Otherwise the exception will only get logged as a warning.
[中]记录警告,如果启用,则传播异常t。作为一般规则,检测代码应该正常降级,避免影响核心应用程序。如果用户犯了一个错误并导致某些东西损坏,那么它不应该影响应用程序,除非该错误触发了检测代码之外的问题。然而,在测试代码中,抛出错误通常更好,这样错误就会被发现并纠正。此方法用于处理插装代码内部的异常。传播由RegistryConfig#propagateWarnings()设置控制。如果设置为true,则会传播异常。否则,异常只会作为警告记录。

代码示例

代码示例来源:origin: org.springframework.metrics/spring-metrics

@Override
public void propagate(String msg, Throwable t) {
  composite.propagate(msg, t);
}

代码示例来源:origin: org.springframework.metrics/spring-metrics

@Override
public void propagate(Throwable t) {
  composite.propagate(t);
}

代码示例来源:origin: Netflix/spectator

/**
  * Log a warning using the message from the exception and if enabled propagate the
  * exception {@code t}. For more information see {@link #propagate(String, Throwable)}.
  *
  * @param t
  *     Exception to log and optionally propagate.
  */
 default void propagate(Throwable t) {
  propagate(t.getMessage(), t);
 }
}

代码示例来源:origin: com.netflix.spectator/spectator-api

/**
  * Log a warning using the message from the exception and if enabled propagate the
  * exception {@code t}. For more information see {@link #propagate(String, Throwable)}.
  *
  * @param t
  *     Exception to log and optionally propagate.
  */
 default void propagate(Throwable t) {
  propagate(t.getMessage(), t);
 }
}

代码示例来源:origin: Netflix/spectator

/**
 * Propagate a type error exception. Used in situations where an existing id has already
 * been registered but with a different class.
 */
public static void propagateTypeError(
  Registry registry, Id id, Class<?> desiredClass, Class<?> actualClass) {
 final String dType = desiredClass.getName();
 final String aType = actualClass.getName();
 final String msg = String.format("cannot access '%s' as a %s, it already exists as a %s",
   id, dType, aType);
 registry.propagate(new IllegalStateException(msg));
}

代码示例来源:origin: com.netflix.spectator/spectator-api

/**
 * Propagate a type error exception. Used in situations where an existing id has already
 * been registered but with a different class.
 */
public static void propagateTypeError(
  Registry registry, Id id, Class<?> desiredClass, Class<?> actualClass) {
 final String dType = desiredClass.getName();
 final String aType = actualClass.getName();
 final String msg = String.format("cannot access '%s' as a %s, it already exists as a %s",
   id, dType, aType);
 registry.propagate(new IllegalStateException(msg));
}

代码示例来源:origin: com.netflix.spectator/spectator-api

/** Return a method supplying a value for a gauge. */
static Method getGaugeMethod(Registry registry, Id id, Object obj, String method) {
 try {
  final Method m = Utils.getMethod(obj.getClass(), method);
  try {
   // Make sure we can cast the response to a Number
   final Number n = (Number) m.invoke(obj);
   REGISTRY_LOGGER.debug(
     "registering gauge {}, using method [{}], with initial value {}", id, m, n);
   return m;
  } catch (Exception e) {
   final String msg = "exception thrown invoking method [" + m
     + "], skipping registration of gauge " + id;
   registry.propagate(msg, e);
  }
 } catch (NoSuchMethodException e) {
  final String mname = obj.getClass().getName() + "." + method;
  final String msg = "invalid method [" + mname + "], skipping registration of gauge " + id;
  registry.propagate(msg, e);
 }
 return null;
}

代码示例来源:origin: Netflix/spectator

/** Return a method supplying a value for a gauge. */
static Method getGaugeMethod(Registry registry, Id id, Object obj, String method) {
 try {
  final Method m = Utils.getMethod(obj.getClass(), method);
  try {
   // Make sure we can cast the response to a Number
   final Number n = (Number) m.invoke(obj);
   REGISTRY_LOGGER.debug(
     "registering gauge {}, using method [{}], with initial value {}", id, m, n);
   return m;
  } catch (Exception e) {
   final String msg = "exception thrown invoking method [" + m
     + "], skipping registration of gauge " + id;
   registry.propagate(msg, e);
  }
 } catch (NoSuchMethodException e) {
  final String mname = obj.getClass().getName() + "." + method;
  final String msg = "invalid method [" + mname + "], skipping registration of gauge " + id;
  registry.propagate(msg, e);
 }
 return null;
}

代码示例来源:origin: com.netflix.spectator/spectator-ext-aws

/**
 * Constructs a new instance. Custom tags provided by the user will be applied to every metric.
 * Overriding built-in tags is not allowed.
 */
public SpectatorRequestMetricCollector(Registry registry, Map<String, String> customTags) {
 super();
 this.registry = Preconditions.checkNotNull(registry, "registry");
 Preconditions.checkNotNull(customTags, "customTags");
 this.customTags = new HashMap<>();
 customTags.forEach((key, value) -> {
  if (ALL_DEFAULT_TAGS.contains(key)) {
   registry.propagate(new IllegalArgumentException("Invalid custom tag " + key
      + " - cannot override built-in tag"));
  } else {
   this.customTags.put(key, value);
  }
 });
}

代码示例来源:origin: Netflix/spectator

/**
 * Constructs a new instance. Custom tags provided by the user will be applied to every metric.
 * Overriding built-in tags is not allowed.
 */
public SpectatorRequestMetricCollector(Registry registry, Map<String, String> customTags) {
 super();
 this.registry = Preconditions.checkNotNull(registry, "registry");
 Preconditions.checkNotNull(customTags, "customTags");
 this.customTags = new HashMap<>();
 customTags.forEach((key, value) -> {
  if (ALL_DEFAULT_TAGS.contains(key)) {
   registry.propagate(new IllegalArgumentException("Invalid custom tag " + key
      + " - cannot override built-in tag"));
  } else {
   this.customTags.put(key, value);
  }
 });
}

代码示例来源:origin: Netflix/spectator

/**
 * Constructs a new instance. Custom tags provided by the user will be applied to every metric.
 * Overriding built-in tags is not allowed.
 */
public SpectatorRequestMetricCollector(Registry registry, Map<String, String> customTags) {
 super();
 this.registry = Preconditions.checkNotNull(registry, "registry");
 Preconditions.checkNotNull(customTags, "customTags");
 this.customTags = new HashMap<>();
 customTags.forEach((key, value) -> {
  if (ALL_DEFAULT_TAGS.contains(key)) {
   registry.propagate(new IllegalArgumentException("Invalid custom tag " + key
      + " - cannot override built-in tag"));
  } else {
   this.customTags.put(key, value);
  }
 });
}

代码示例来源:origin: Netflix/spectator

@Test
public void propagateWarningsFalse() {
 RegistryConfig config = k -> "propagateWarnings".equals(k) ? "false" : null;
 Registry r = new DefaultRegistry(Clock.SYSTEM, config);
 r.propagate("foo", new RuntimeException("test"));
}

代码示例来源:origin: Netflix/spectator

@Test
public void propagateWarningsDefault() {
 RegistryConfig config = k -> null;
 Registry r = new DefaultRegistry(Clock.SYSTEM, config);
 r.propagate("foo", new RuntimeException("test"));
}

代码示例来源:origin: Netflix/spectator

@Test
public void propagateWarningsTrue() {
 Assertions.assertThrows(RuntimeException.class, () -> {
  RegistryConfig config = k -> "propagateWarnings".equals(k) ? "true" : null;
  Registry r = new DefaultRegistry(Clock.SYSTEM, config);
  r.propagate("foo", new RuntimeException("test"));
 });
}

相关文章