Skip to content

Conversation

tbradellis
Copy link
Contributor

@tbradellis tbradellis commented Jun 11, 2025

Before contributing, please read our contributing guidelines and code of conduct.

Overview

newrelic-java-agent/newrelic-agent/src/main/java/com/newrelic/agent/tracers/metricname/MetricNameFormats.java

Lines 21 to 23 in 4b53e4f

private static final Cache<MNFKey, MetricNameFormat> cmsToMnf = Caffeine.newBuilder()
.executor(Runnable::run)
.build();
If a customer were to create enough segments with extremely dynamic names, this cache could grow to an unreasonable size and appear to be a memory leak.

Related Github Issue

#1825

Considerations

This could optionally be bound by some weighting. However, seems like a simple count bound would probably work for this cache. Somewhat arbitrarily around 10K? Or do you have metrics showing distribution of common counts? This is essentially just every tracer right?

Would you want this configurable?

Any interest in recording stats for this cache? If not, will just remove recordStats()
and/or logging spikes?
if (cmsToMnf.stats().evictionCount() > threshold) {
logger.warn("High MetricNameFormat cache eviction rate detected!");
}

Testing

Dependent on complete changes

Checks

  • [ √] Your contributions are backwards compatible with relevant frameworks and APIs.
  • [ √] Your code does not contain any breaking changes. Otherwise please describe.
  • [√ ] Your code does not introduce any new dependencies. Otherwise please describe.

@jtduffy
Copy link
Contributor

jtduffy commented Jun 13, 2025

@tbradellis You've been around these parts before huh? :-)

We're going to keep this open and see if we can generate some stats on what the size max size of the cache should be. Thanks!

@kmudduluru kmudduluru moved this from Triage to Needs Review in Java Engineering Board Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

2 participants