@Override public void propagate(String msg, Throwable t) { composite.propagate(msg, t); }
@Override public void propagate(Throwable t) { composite.propagate(t); }
/** * 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); } }
/** * 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); } }
/** * 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)); }
/** * 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)); }
/** 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; }
/** 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; }
/** * 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); } }); }
/** * 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); } }); }
/** * 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); } }); }
@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")); }
@Test public void propagateWarningsDefault() { RegistryConfig config = k -> null; Registry r = new DefaultRegistry(Clock.SYSTEM, config); r.propagate("foo", new RuntimeException("test")); }
@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")); }); }