Skip to content

Remove metrics when shutting down InstrumentedQueuedThreadPool #4000

@wakingrufus

Description

@wakingrufus

remove metrics from MeterRegistry when shutting down InstrumentedQueuedThreadPool
Something like:

    @Override
    protected void doStop() throws Exception {
       Set<Tag> tagSet = new HashSet<>();
        tags.forEach(tagSet::add);
        Stream.of("jetty.threads.config.min",
                        "jetty.threads.config.max",
                        "jetty.threads.busy",
                        "jetty.threads.jobs",
                        "jetty.threads.current",
                        "jetty.threads.idle")
                .flatMap(name -> meterRegistry.find(name).meters().stream())
                .map(Meter::getId)
                .filter(id -> new HashSet<>(id.getTags()).containsAll(tagSet))
                .forEach(meterRegistry::remove);
        super.doStop();
    }

Rationale
Clean up resources when not needed anymore

Additional context
The dropwizard metrics jetty InstrumentedQueuedThreadPool does something similar, and it seems like a good idea to do here as well.

I am happy to open a PR for this with tests if it is agreed that this should exist.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions