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

aggregateutil: allow filtering against empty attribute set #35006

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

braydonk
Copy link
Contributor

@braydonk braydonk commented Sep 4, 2024

Description:
It is a valid use case to aggregate against an empty label set, which will functionally clear all attributes. This behaviour was removed in #33655, which simplified the check to len() == 0, which covers the case of the label set being nil and having 0 elements as the same scenario. However, these are not the same scenario and have different meanings. This PR reintroduces the original behaviour, but in a more efficient way by recognizing a label set with 0 elements and clearing the attributes, which would be the logical conclusion after running the filter anyway.

Link to tracking Issue: #34430

Testing:

Documentation:

It is a valid use case to aggregate against an empty label set, which
will functionally clear all attributes. This behaviour was removed in a
previous PR, which simplified the check to `len() == 0`, which covers
the case of the label set being `nil` and having 0 elements the same.
However, these are not the same scenario and have different meanings.
This PR reintroduces the original behaviour, but in a more efficient way
by recognizing a label set with 0 elements and clearing the attributes,
which would be the logical conclusion after running the filter anyway.
@braydonk
Copy link
Contributor Author

braydonk commented Sep 4, 2024

CC @odubajDT

@braydonk
Copy link
Contributor Author

braydonk commented Sep 4, 2024

Integration test looks like a flake to me. I don't have authority to re-run the CI with the button but I can force-push if I need to re-run.

@odubajDT
Copy link
Contributor

odubajDT commented Sep 5, 2024

cc @evan-bradley @TylerHelmuth

@odubajDT
Copy link
Contributor

odubajDT commented Sep 5, 2024

please run make genotelcontribcol and commit the changes in this PR. Otherwise this change makes sense to me, if the codeowners agree with it

@github-actions github-actions bot added the cmd/otelcontribcol otelcontribcol command label Sep 5, 2024
@braydonk
Copy link
Contributor Author

Is there any chance this PR can be reviewed?

Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@braydonk to make sure the functionality is the same as before can you also restore any tests to the metricstransformprocessor that covers this scenario.

Adds empty and nil label set tests. Exposed something I didn't notice in
the way the code is called when calling from metricstransform processor
compared to using the aggregateutil package functions directly.
@braydonk braydonk requested review from dmitryax and a team as code owners September 20, 2024 20:30
@github-actions github-actions bot added the processor/metricstransform Metrics Transform processor label Sep 20, 2024
@braydonk
Copy link
Contributor Author

This is done in f7c46ce. Thanks for calling it out, I should have thought of that and it did expose a problem that I fixed in that commit as well.

While manually testing this along with the unit tests, I found something interesting. While in the previous version of the filterAttrs function acted differently if the filterAttrKeys argument was nil, metricstransform actually would never pass nil through that far. In the config building code, nil and [] would both end up resulting in [] thanks to this code path.

In f7c46ce I adjusted it to check for nil explicitly, allowing these cases to be treated differently. Should I keep this completely with the old behaviour? (i.e. not specifying label_set and explicitly setting label_set: [] both having the same result)

@TylerHelmuth
Copy link
Member

Should I keep this completely with the old behaviour? (i.e. not specifying label_set and explicitly setting label_set: [] both having the same result)

Ya lets restore the previous behavior, it doesn't sound like the way metricstransform was doing this before was a bug.

Even before the aggregateutil change, metricstransform never passed a
nil label_set to `aggregateLabelsOp`; a nil label_set would always be
changed to empty slice anyway. This commit restores that behaviour.
The length of the attributes array can always be a known value. This
commit pre-allocates that space to save on allocations.
@braydonk
Copy link
Contributor Author

Fine by me. Having a nil label_set is a weird use of that operation anyway.

Restored in debfca5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd/otelcontribcol otelcontribcol command internal/core processor/metricstransform Metrics Transform processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants