Skip to content
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

Tags added via micronaut.metrics.tags create a MeterFilter/Meter registration race #904

Open
jon-signal opened this issue Dec 17, 2024 · 1 comment

Comments

@jon-signal
Copy link

Expected Behavior

When tags are configured via the micronaut.metrics.tags property, the MeterFilter that applies those tags should be registered with the MeterRegistry before any Meters.

Actual Behaviour

When tags are configured via the micronaut.metrics.tags property, the MeterFilter that applies those tags is sometimes (but not always) registered after other metrics managed by the framework (e.g. jvm.buffer.memory.used).

Steps To Reproduce

  1. Create a new Micronaut project.
  2. Add the following to application.yml:
micronaut:
  metrics:
    enabled: true
    tags:
      example-tag: example-value
  1. Start the application

About 50% of the time, the following warning will appear in the logs:

A MeterFilter is being configured after a Meter has been registered to this registry. All MeterFilters should be configured before any Meters are registered. If that is not possible or you have a use case where it should be allowed, let the Micrometer maintainers know at micrometer-metrics/micrometer#4920. Enable DEBUG level logging on this logger to see a stack trace of the call configuring this MeterFilter.

Environment Information

Java 21, multiple architectures.

Example Application

No response

Version

4.7.1

@jon-signal
Copy link
Author

I wrote a minimal reproduction for this issue, but I hesitate to propose actually including it as a unit test because it contains no assertions. Still, for your convenience:

package io.micronaut.configuration.metrics;

import io.micrometer.core.instrument.MeterRegistry;
import io.micronaut.context.annotation.Property;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

@MicronautTest
@Property(name = "micronaut.metrics.enabled", value = "true")
@Property(name = "micronaut.metrics.binders.jvm.enabled", value = "true")
@Property(name = "micronaut.metrics.tags.test", value = "test")
public class MeterFilterRaceConditionTest {

    @SuppressWarnings("unused")
    @Inject
    MeterRegistry meterRegistry;

    @Test
    void testRegistrationRace() {
        // There isn't really anything to assert, but about 50% of the time, we'll get warnings
        // about MeterFilters being registered after a Meter.
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant