protected void readMeasurement(String name, Setter setter) { MeasurementNode node = tree.findChild(name); if (node == null) { return; } for (Measurement measurement : node.getMeasurements()) { String threadPoolName = Utils.getTagValue(measurement.id(), ThreadPoolMonitor.ID_TAG_NAME); if (threadPoolName == null) { continue; } ThreadPoolPublishModel model = threadPools.computeIfAbsent(threadPoolName, tpn -> { return new ThreadPoolPublishModel(); }); setter.set(model, measurement); } } }
private static boolean isPercentile(Id id) { final String stat = Utils.getTagValue(id, "statistic"); return "percentile".equals(stat); }
private static boolean isPercentile(Id id) { final String stat = Utils.getTagValue(id, "statistic"); return "percentile".equals(stat); }
private void validateValues(Id id, String key, SortedSet<String> allowedValues) { String value = Utils.getTagValue(id, key); if (value != null && !allowedValues.contains(value)) { String values = allowedValues.stream() .collect(Collectors.joining(", ")); throw new IllegalArgumentException(String.format( "[%s] invalid value for dimension %s, acceptable values are (%s)", id, key, values)); } }
@SuppressWarnings("PMD.PreserveStackTrace") private <T extends Enum<T>> void validateValues(Id id, String key, Class<T> cls) { String value = Utils.getTagValue(id, key); if (value != null) { try { Enum.valueOf(cls, value); } catch (Exception e) { String values = Arrays.stream(cls.getEnumConstants()) .map(Enum::name) .collect(Collectors.joining(", ")); throw new IllegalArgumentException(String.format( "[%s] invalid value for dimension %s, acceptable values are (%s)", id, key, values)); } } }
private void validateValues(Id id, String key, SortedSet<String> allowedValues) { String value = Utils.getTagValue(id, key); if (value != null && !allowedValues.contains(value)) { String values = allowedValues.stream() .collect(Collectors.joining(", ")); throw new IllegalArgumentException(String.format( "[%s] invalid value for dimension %s, acceptable values are (%s)", id, key, values)); } }
/** * Returns the first measurement with a given tag value. * * @param ms * A set of measurements. * @param k * Key to search for. * @param v * Value that should be associated with k on the ids. * @return * Measurement or null if no matches are found. */ public static Measurement first(final Iterable<Measurement> ms, final String k, final String v) { return first(ms, value -> v.equals(getTagValue(value.id(), k))); }
/** * Returns a new iterable restricted to measurements that match the predicate. * * @param ms * A set of measurements. * @param k * Key to search for. * @param v * Value that should be associated with k on the ids. * @return * Measurements matching the predicate. */ public static Iterable<Measurement> filter( final Iterable<Measurement> ms, final String k, final String v) { return filter(ms, value -> v.equals(getTagValue(value.id(), k))); }
/** * Returns the value associated with with a given key or null if no such key is present in the * set of tags. * * @param id * Identifier with a set of tags to search. * @param k * Key to search for. * @return * Value for the key or null if the key is not present. */ public static String getTagValue(Id id, String k) { Preconditions.checkNotNull(id, "id"); return getTagValue(id.tags(), k); }
/** * Returns the value associated with with a given key or null if no such key is present in the * set of tags. * * @param id * Identifier with a set of tags to search. * @param k * Key to search for. * @return * Value for the key or null if the key is not present. */ public static String getTagValue(Id id, String k) { Preconditions.checkNotNull(id, "id"); return getTagValue(id.tags(), k); }
/** Returns a set of all values for a given tag key. */ private Set<String> valueSet(String k) { return registry.stream() .map(m -> Utils.getTagValue(m.id(), k)) .filter(v -> v != null) .collect(Collectors.toSet()); }
/** Returns a set of all values for a given tag key. */ private Set<String> valueSet(String k) { return registry.stream() .map(m -> Utils.getTagValue(m.id(), k)) .filter(v -> v != null) .collect(Collectors.toSet()); }
static void checkResult(Id id, String expected) { String endpoint = Utils.getTagValue(id, IpcTagKey.result.key()); Assertions.assertEquals(expected, endpoint); }
static void checkStatus(Id id, String expected) { String endpoint = Utils.getTagValue(id, IpcTagKey.httpStatus.key()); Assertions.assertEquals(expected, endpoint); }
static void checkErrorReason(Id id, String expected) { String endpoint = Utils.getTagValue(id, IpcTagKey.statusDetail.key()); Assertions.assertEquals(expected, endpoint); }
static void checkEndpoint(Id id, String expected) { String endpoint = Utils.getTagValue(id, IpcTagKey.endpoint.key()); Assertions.assertEquals(expected, endpoint); }
static void checkMethod(Id id, String expected) { String endpoint = Utils.getTagValue(id, IpcTagKey.httpMethod.key()); Assertions.assertEquals(expected, endpoint); }
@Test public void getTagValueId() { Registry r = new DefaultRegistry(); Id id = r.createId("foo", "bar", "baz", "abc", "def"); Assertions.assertEquals("def", Utils.getTagValue(id, "abc")); Assertions.assertEquals("baz", Utils.getTagValue(id, "bar")); }
@Test public void getTagValueIdNoTags() { Registry r = new DefaultRegistry(); Id id = r.createId("foo"); Assertions.assertEquals(null, Utils.getTagValue(id, "abc")); }
@Test public void endpointUnknownIfNotSet() { Registry registry = new DefaultRegistry(); IpcLogger logger = new IpcLogger(registry, clock, LoggerFactory.getLogger(getClass())); logger.createServerEntry() .withOwner("test") .markStart() .markEnd() .log(); registry.counters().forEach(c -> { Assertions.assertEquals("unknown", Utils.getTagValue(c.id(), "ipc.endpoint")); }); } }