@Test public void getCounterVersionlessTest() { Map<String, String> attributes = ImmutableMap .of("document_namespace", "telemetry", "document_type", "core"); Counter counter = PerDocTypeCounter.getOrCreateCounter(attributes, "my-name"); assertEquals("telemetry/core/my_name", counter.getName().getName()); }
@VisibleForTesting static Counter getOrCreateCounter(@Nullable Map<String, String> attributes, String name) { if (attributes == null) { attributes = EMPTY_ATTRIBUTES; } String namespace = attributes.getOrDefault("document_namespace", "unknown_namespace"); String docType = attributes.getOrDefault("document_type", "unknown_doctype"); String version = attributes.get("document_version"); if (version != null) { docType = docType + "_v" + version; } String key = String.format("%s/%s/%s", namespace, docType, name) .replace("-", "_"); return counters.computeIfAbsent(key, k -> Metrics.counter(PerDocTypeCounter.class, k)); }
PerDocTypeCounter { @VisibleForTesting static Counter getOrCreateCounter(@Nullable Map<String, String> attributes, String name) { if (attributes == null) { attributes = EMPTY_ATTRIBUTES; } String namespace = attributes.getOrDefault("document_namespace", "unknown_namespace"); String docType = attributes.getOrDefault("document_type", "unknown_doctype"); String version = attributes.get("document_version"); if (version != null) { docType = docType + "_v" + version; } String key = String.format("%s/%s/%s", namespace, docType, name) .replace("-", "_"); return counters.computeIfAbsent(key, k -> Metrics.counter(PerDocTypeCounter.class, k)); } }
PerDocTypeCounter { @VisibleForTesting static Counter getOrCreateCounter(@Nullable Map<String, String> attributes, String name) { if (attributes == null) { attributes = EMPTY_ATTRIBUTES; } String namespace = attributes.getOrDefault("document_namespace", "unknown_namespace"); String docType = attributes.getOrDefault("document_type", "unknown_doctype"); String version = attributes.get("document_version"); if (version != null) { docType = docType + "_v" + version; } String key = String.format("%s/%s/%s", namespace, docType, name) .replace("-", "_"); return counters.computeIfAbsent(key, k -> Metrics.counter(PerDocTypeCounter.class, k)); }  }
PerDocTypeCounter { @VisibleForTesting static Counter getOrCreateCounter(@Nullable Map<String, String> attributes, String name) { if (attributes == null) { attributes = EMPTY_ATTRIBUTES; } String namespace = attributes.getOrDefault("document_namespace", "unknown_namespace"); String docType = attributes.getOrDefault("document_type", "unknown_doctype"); String version = attributes.get("document_version"); if (version != null) { docType = docType + "_v" + version; } String key = String.format("%s/%s/%s", namespace, docType, name) .replace("-", "_"); return counters.computeIfAbsent(key, k -> Metrics.counter(PerDocTypeCounter.class, k)); }  static void inc(@Nullable Map<String, String> attributes, String name); static void inc(@Nullable Map<String, String> attributes, String name, long n); }
PerDocTypeCounter { @VisibleForTesting static Counter getOrCreateCounter(@Nullable Map<String, String> attributes, String name) { if (attributes == null) { attributes = EMPTY_ATTRIBUTES; } String namespace = attributes.getOrDefault("document_namespace", "unknown_namespace"); String docType = attributes.getOrDefault("document_type", "unknown_doctype"); String version = attributes.get("document_version"); if (version != null) { docType = docType + "_v" + version; } String key = String.format("%s/%s/%s", namespace, docType, name) .replace("-", "_"); return counters.computeIfAbsent(key, k -> Metrics.counter(PerDocTypeCounter.class, k)); }  static void inc(@Nullable Map<String, String> attributes, String name); static void inc(@Nullable Map<String, String> attributes, String name, long n);  }