diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistry.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistry.java index 008c59ec77..3635763cb8 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistry.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistry.java @@ -71,6 +71,11 @@ public DropwizardMeterRegistry(DropwizardConfig config, MetricRegistry registry, private void onMeterRemoved(Meter meter) { registry.remove(hierarchicalName(meter.getId())); + if (meter instanceof LongTaskTimer) { + for (Statistic statistic : Statistic.values()) { + registry.remove(hierarchicalName(meter.getId().withTag(statistic))); + } + } } public MetricRegistry getDropwizardRegistry() { diff --git a/micrometer-core/src/test/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistryTest.java b/micrometer-core/src/test/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistryTest.java index 0f03c5da7d..ba26eb2da2 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistryTest.java +++ b/micrometer-core/src/test/java/io/micrometer/core/instrument/dropwizard/DropwizardMeterRegistryTest.java @@ -111,4 +111,13 @@ void removeShouldWork() { assertThat(registry.getDropwizardRegistry().getMeters()).isEmpty(); } + @Issue("#2924") + @Test + void removeShouldWorkForLongTaskTimer() { + LongTaskTimer timer = LongTaskTimer.builder("foo").register(registry); + assertThat(registry.getDropwizardRegistry().getGauges()).hasSize(3); + registry.remove(timer); + assertThat(registry.getDropwizardRegistry().getGauges()).isEmpty(); + } + }