in spectator-ext-ipc/src/main/java/com/netflix/spectator/ipc/IpcMetric.java [420:458]
public void validate(Id id, boolean strict) {
assertTrue(metricName.equals(id.name()), "%s != %s", metricName, id.name());
// Check that required dimensions are present
EnumSet<IpcTagKey> dimensions = requiredDimensions.clone();
dimensions.forEach(k -> {
String value = Utils.getTagValue(id, k.key());
assertTrue(value != null, "[%s] is missing required dimension %s", id, k.key());
});
// Check the values are correct for enum keys
validateValues(id, IpcTagKey.attemptFinal.key(), ATTEMPT_FINAL_VALUES);
validateValues(id, IpcTagKey.attempt.key(), IpcAttempt.class);
validateValues(id, IpcTagKey.result.key(), IpcResult.class);
validateValues(id, IpcTagKey.status.key(), IpcStatus.class);
validateValues(id, IpcTagKey.failureInjected.key(), IpcFailureInjection.class);
// Check that result and status are consistent
String status = Utils.getTagValue(id, IpcTagKey.status.key());
if (status != null) {
IpcResult expected = IpcStatus.valueOf(status).result();
IpcResult actual = IpcResult.valueOf(Utils.getTagValue(id, IpcTagKey.result.key()));
assertTrue(actual == expected, "[%s] result is inconsistent with status", id);
}
// Check that only allowed dimensions are used on the id
if (strict) {
Set<String> allowedDimensions = new HashSet<>();
allowedDimensions.add("statistic");
allowedDimensions.add("percentile");
requiredDimensions.forEach(d -> allowedDimensions.add(d.key()));
optionalDimensions.forEach(d -> allowedDimensions.add(d.key()));
for (Tag tag : id.tags()) {
assertTrue(allowedDimensions.contains(tag.key()),
"[%s] has unspecified dimension %s",
id, tag.key());
}
}
}