Skip to content

Don't apply MeterFilter to auto-configured composite registry #23381

@jkschneider

Description

@jkschneider

Met with a team today that is configuring two PrometheusMeterRegistry instances, one for platform metrics and the other for application metrics. They expose two different scrape endpoints from the application. The platform metrics should include framework-level metrics like CPU, GC, http request timings, etc. The application metrics endpoint is reserved for teams to record business metrics.

Both of these registries wind up under the CompositeMeterRegistry Spring Boot creates. (I hope you enjoy my senseless ascii art ;) ).

                             Composite
                     ----------/    \
                   /                 \
        Prometheus (platform)     Prometheus (app)

The problem is that PropertiesMeterFilter is added to the composite in addition to both sub-registries. So if an app team adds a property like management.metrics.enable.tomcat=false the composite denies Tomcat metrics before it ever reaches the platform registry.

I suggest we weaken PropertiesMeterFilter and only apply it to sub-registries. In this way, a user-crafted registry could add meter filters that take precedence over PropertiesMeterFilter, like this:

@Bean
PrometheusMeterRegistry platformRegistry() {
    PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
    prometheusMeterRegistry
            .config()
            .meterFilter(MeterFilter.acceptNameStartsWith("tomcat"))
            .meterFilter(MeterFilter.acceptNameStartsWith("jvm"));
    return prometheusMeterRegistry;
}

cc / @wangyf2010
cc / @shakuzen

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions