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

Positive match to a rule should not consume the metric #901

Open
vbence opened this issue Jan 2, 2024 · 1 comment
Open

Positive match to a rule should not consume the metric #901

vbence opened this issue Jan 2, 2024 · 1 comment

Comments

@vbence
Copy link

vbence commented Jan 2, 2024

The exporter's current behavior is that the first matching rule consumes the metric which will not be visible to subsequent matches. In the example below only the first rule will display any metrics from MyLegacyMetricsBean.

# The old way when I had a single class
- pattern: 'com.example.myproduct.metrics<type=MyLegacyMetricsBean><>([^:]+)'
  name: myproduct_$1
  ...
# The new way with multiple classes
- pattern: 'com.example.myproduct.metrics<type=(.*)><>([^:]+)'
  name: myproduct_$1_$2
  ...

I am doing a refactoring of my metrics and I would like to support the old and the new metrics for the foreseeable future. These overlapping rules would provide backward compatibility while also exposing the legacy metrics on the new naming convention.

I recommend a property settable on the rule level to override the current behavior (e.g. consume which defaults to true).

@dhoard
Copy link
Collaborator

dhoard commented Jan 23, 2024

@vbence Looking at the code...

(

if (rule.cache) {
MatchedRule cachedRule = config.rulesCache.get(rule, matchName);
if (cachedRule != null) {
stalenessTracker.add(rule, matchName);
if (cachedRule.isMatched()) {
matchedRule = cachedRule;
break;
}
// The bean was cached earlier, but did not match the current rule.
// Skip it to avoid matching against the same pattern again
continue;
}
}
)

... if cache is false (default) it looks like it should work as you expect.

Are you setting cache: true on the specific rules?

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

No branches or pull requests

2 participants