-
Notifications
You must be signed in to change notification settings - Fork 961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CompositeMeterRegistry fails to propagate Meter removals to a MeterRegistry that has Filters #2354
Comments
Thanks for the detailed report. The behavior of the remove method has changed since it was introduced - it used to apply While I think we should be able to fix this regardless, can share more details about your use case for removing meters? This is just so we have a more complete picture of the background behind the use case. |
Here is a unit test that I believe captures the scenario (written in @Test
@Issue("#2354")
void meterRemovedInChildRegistryWithModifyingFilter() {
this.simple.config().commonTags("host", "localhost");
this.composite.add(this.simple);
Counter counter = this.composite.counter("my.counter");
this.composite.remove(counter);
assertThat(this.composite.getMeters()).isEmpty();
assertThat(this.simple.getMeters()).isEmpty(); // this assertion fails
} |
We use Spring which configures and manages its own CompositeMeterRegistry, and reactor which simply writes to micrometer's globalRegistry, globalRegistry is not modified by Spring (aside from adding children), we end up with plenty of Meters from reactor that don't get removed over time. Test looks good to me. |
Please @shakuzen , take into consideration the PR https://github.com/micrometer-metrics/micrometer/pull/2281/files. This solves the problem. |
Child registries may have a `MeterFilter` configured that alter the Id of meters when registered. In this case, calling `remove` with the Id from the `CompositeMeterRegistry` will not match unless it also has the same `MeterFilter` configured. The behavior of the `remove` method has fluctuated as these cases come to light. This adds public API for removing a meter with its pre-mapped Id and clarifies the behavior in the JavaDoc of all `remove` methods. `CompositeMeterRegistry` can now use this new API to have the expected behavior. Resolves micrometer-metricsgh-2354
The fix for this is available now in snapshots for 1.3.16, 1.5.8, and 1.6.2. I will be releasing these soon, so feel free to test the snapshots now or the release versions once available to confirm the issue reported here is fixed. |
Hello,
Consider the simple set up:
Metrics.globalRegistry has no Filters applied
A DatadogMeterRegistry instance has a CommonTags Filter applied and is parented by Metrics.globalRegistry
When Meters are written to Metrics.globalRegistry, they are propagated to the DatadogMeterRegister instance and the Filters are applied
When Meters are removed from Metrics.globalRegistry, they are propagated to the DatadogMeterRegister instance but the Filters are not applied, causing the lookup to fail and them to not get properly deleted
This is caused by this event handler which calls this method, in which the filters are not applied.
This causes the equivalent of a memory leak and aggravates heavily with high-cardinality Meters (such as metrics from reactor executors while using "elastic" schedulers)
I don't have enough Java expertise to offer an accompanying fix and tests, apologies.
The text was updated successfully, but these errors were encountered: