-
Notifications
You must be signed in to change notification settings - Fork 131
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
fix: exclude_matching_metrics
is excluding non-ProcessSample
s
#1943
Conversation
f6aeccf
to
d22da5f
Compare
Commit bbe25a6 touches pretty ancient code to remove a check that we were performing in different sections of the logic and in a different way each time: if the sample is a These duplicate checks were removed at the cost of some duplication regarding the include/exclude behavior, though the code might be more explicit this way and thus easier to follow. I have doubts regarding behavior when feature flags are involved. To clarify these doubts I am counting on:
That issue aside, I'll be doing more manual tests for this and probably involve someone else to test live and caught potential issues. We need more eyes! |
d22da5f
to
bbe25a6
Compare
Last commit (92d3411) removed redundant checks that were made inside the Tested manually (both commits bbe25a6 and 92d3411) with all the combinations of:
The behavior is the same in both and the expected behavior.
Non- Queries used in tests for review and future reference: https://onenr.io/08jqegodOjl Ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I just left a NIT that is to add a comment pointing out the matchers only apply to ProcessSample, but overall I think now it's well tested and does what it's supposed to. This Matcher function was designed to be generic but is only applied to ProcessSample, and that has given an obfuscation that was error prone. I think your change adding the check explicitly add the beginning of the functions makes it much clearer, and the tests you added avoid this to happen again.
pkg/metrics/sampler/matcher.go
Outdated
return matcher | ||
// NewIncludeSampleMatchFn returns a function `func(sample) bool` that determinesif the sample | ||
// should be included (true) as an event or not (false). Note that this is NOT the negation | ||
// of `NewExcludeSampleMatchFn`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can also add a comment that it only works for ProcessSample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1a9f8d8!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic looks solid to me . I preferred your first approach to apply the sample filter on the Include fn rather than the matcher but is just a nit
internal/agent/agent.go
Outdated
// Decides wether an event will be included or not. | ||
// This kind of filtering only applies to ProcessSamples, | ||
// so that's what we check here. | ||
func (c *context) IncludeEvent(event any) bool { | ||
shouldInclude := c.shouldIncludeEvent(event) | ||
shouldExclude := c.shouldExcludeEvent(event) | ||
|
||
return shouldInclude || !shouldExclude | ||
switch event.(type) { | ||
// rule is applied to process samples | ||
case *process_sample_types.ProcessSample, *process_sample_types.FlatProcessSample: | ||
shouldInclude := c.shouldIncludeEvent(event) | ||
shouldExclude := c.shouldExcludeEvent(event) | ||
|
||
return shouldInclude || !shouldExclude | ||
default: | ||
// other samples are included | ||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I actually liked this approach to evaluate the type of sample even before calling the matcher functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have retrieved it in d386f89! LMKWYT
pkg/metrics/sampler/matcher.go
Outdated
|
||
mlog. | ||
WithField(config.TracesFieldName, config.FeatureTrace). | ||
Trace("EnableProcessMetrics is TRUE and rules are NOT defined, ALL process metrics will be ENABLED") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quite a minor thing but this log will be printed en case also when exclude matchers are added and no include ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the latest commit (d386f89) solve this? I reworded a bit.
This should make the current tests fail and uncover the source of the issue
There were many different places where it was checked that the sample was a process sample or not, and the implementations were different each time. At the cost of a little function duplication I have removed the redundant checks and (hopefully) streamlined code test: remove redundant test tested function will never be applied to non-processsamples fix: do not exclude when no exclusion rules are defined docs: improve function names and state purpose style: remove redundant function
style: print rich representation of excluded sample
the removed tests were checking the non-processsample exclusion + FF enabled behavior. Given the non-processsample check is now done elsewhere, these tests are now invalid
69333cc
to
303b9bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
This fixes NR-334472.
Due to how the logic for the
exclude_matching_metrics
option was implemented for 1.57.2, when this setting is present all samples that are notProcessSample
s are filtered out and not sent.This reworks the matcher logic to cover against this and add relevant unit tests to check for the inclusion or exclusion of non-
ProcessSample
events.