@Test public void testMicroProfileScopeInTagsWithExtendedMetadata() { OpenMetricsExporter exporter = new OpenMetricsExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = new ExtendedMetadata("mycounter", "mycounter", "awesome", MetricType.COUNTER, "none", null, false, Optional.of(false)); Tag colourTag = new Tag("color", "blue"); Counter counterWithTag = registry.counter(metadata, colourTag); Counter counterWithoutTag = registry.counter(metadata); counterWithTag.inc(10); counterWithoutTag.inc(20); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mycounter").toString(); System.out.println(result); Tag microProfileScopeTag = new Tag("microprofile_scope", MetricRegistry.Type.APPLICATION.getName().toLowerCase()); assertHasTypeLineExactlyOnce(result, "mycounter_total", "counter"); assertHasHelpLineExactlyOnce(result, "mycounter_total", "awesome"); assertHasValueLineExactlyOnce(result, "mycounter_total", "10.0", colourTag, microProfileScopeTag); assertHasValueLineExactlyOnce(result, "mycounter_total", "20.0", microProfileScopeTag); }
@Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } OpenMetricsExporter(); }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } OpenMetricsExporter(); @Override StringBuilder exportOneScope(MetricRegistry.Type scope); @Override StringBuilder exportAllScopes(); @Override StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID); @Override StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name); @Override String getContentType(); static String quoteHelpText(String value); static String quoteValue(String value); }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } OpenMetricsExporter(); @Override StringBuilder exportOneScope(MetricRegistry.Type scope); @Override StringBuilder exportAllScopes(); @Override StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID); @Override StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name); @Override String getContentType(); static String quoteHelpText(String value); static String quoteValue(String value); static final String SMALLRYE_METRICS_USE_PREFIX_FOR_SCOPE; }