DropwizardMeterRegistries { public static DropwizardMeterRegistry newRegistry() { return newRegistry(new MetricRegistry(), DEFAULT_NAME_MAPPER); } private  DropwizardMeterRegistries(); static DropwizardMeterRegistry newRegistry(); static DropwizardMeterRegistry newRegistry(MetricRegistry registry); static DropwizardMeterRegistry newRegistry(HierarchicalNameMapper nameMapper); static DropwizardMeterRegistry newRegistry(MetricRegistry registry,
                                                      HierarchicalNameMapper nameMapper); static DropwizardMeterRegistry newRegistry(HierarchicalNameMapper nameMapper, Clock clock); static DropwizardMeterRegistry newRegistry(MetricRegistry registry,
                                                      HierarchicalNameMapper nameMapper,
                                                      Clock clock); static T configureRegistry(T meterRegistry);  }
@Test void unwantedGaugesAreFilteredOut() { final DropwizardMeterRegistry micrometer = DropwizardMeterRegistries.newRegistry(); final MetricRegistry dropwizard = micrometer.getDropwizardRegistry(); final DistributionSummary percentileSummary = DistributionSummary.builder("percentileSummary") .publishPercentiles(0.5, 0.99) .register(micrometer); final DistributionSummary histogramSummary = DistributionSummary.builder("histogramSummary") .sla(10, 100) .register(micrometer); final Timer percentileTimer = Timer.builder("percentileTimer") .publishPercentiles(0.5, 0.99) .register(micrometer); final Timer histogramTimer = Timer.builder("histogramTimer") .sla(Duration.ofSeconds(10), Duration.ofSeconds(100)) .register(micrometer); percentileSummary.record(42); histogramSummary.record(42); percentileTimer.record(42, TimeUnit.SECONDS); histogramTimer.record(42, TimeUnit.SECONDS); final Map<String, Double> measurements = MoreMeters.measureAll(micrometer); measurements.forEach((key, value) -> assertThat(key).doesNotContain(".percentile") .doesNotContain(".histogram") .doesNotContain("phi=") .doesNotContain("le=")); assertThat(dropwizard.getHistograms()).hasSize(2); assertThat(dropwizard.getTimers()).hasSize(2); }
@Test void filteredGaugesDoNotAffectOthers() { final CompositeMeterRegistry micrometer = new CompositeMeterRegistry(); final PrometheusMeterRegistry prometheus = PrometheusMeterRegistries.newRegistry(); final DropwizardMeterRegistry dropwizard = DropwizardMeterRegistries.newRegistry(); micrometer.add(prometheus).add(dropwizard); final DistributionSummary summary = DistributionSummary.builder("summary") .publishPercentiles(0.5, 0.99) .register(micrometer); summary.record(42); assertThat(dropwizard.getDropwizardRegistry().getMetrics()).containsOnlyKeys("summary"); final MetricFamilySamples prometheusSamples = findPrometheusSample(prometheus, "summary"); assertThat(prometheusSamples.samples).containsExactly( new Sample("summary", ImmutableList.of("quantile"), ImmutableList.of("0.5"), 42), new Sample("summary", ImmutableList.of("quantile"), ImmutableList.of("0.99"), 42), new Sample("summary_count", ImmutableList.of(), ImmutableList.of(), 1), new Sample("summary_sum", ImmutableList.of(), ImmutableList.of(), 42)); }