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

Merged
merged 13 commits into from
Oct 11, 2024

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

@StefanKurek
Copy link
Contributor

@TylerHelmuth @braydonk is there anything else holding up this fix? I'm just wondering on the ETA to get this into a release.

@braydonk
Copy link
Contributor Author

braydonk commented Oct 7, 2024

It is only held up by review at the moment. I will resolve the conflict when the review is done; it's just a matter of doing make genotelcontribcol as close to merge as possible.

@evan-bradley
Copy link
Contributor

@braydonk The generated code for the contrib distro has been removed from the repo for now, so you can delete the go.mod file and don't have to worry about running make genotelcontribcol.

Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

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

A agree with the proposed change. Please address the comments

I called `make` in a way that pre-fills the slice rather than just
setting the capacity.
@braydonk
Copy link
Contributor Author

braydonk commented Oct 8, 2024

so you can delete the go.mod file and don't have to worry about running make genotelcontribcol.

Done in 2d6985e

@braydonk
Copy link
Contributor Author

braydonk commented Oct 8, 2024

Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Thank you for catching and addressing this.

@braydonk
Copy link
Contributor Author

braydonk commented Oct 11, 2024

@open-telemetry/collector-contrib-maintainers The vulncheck workflows are now passing on this PR. I think this just needs a maintainer approval and would be ready to merge.

@TylerHelmuth TylerHelmuth merged commit b6a28a3 into open-telemetry:main Oct 11, 2024
158 checks passed
@github-actions github-actions bot added this to the next release milestone Oct 11, 2024
@braydonk braydonk deleted the aggregate_labels_empty branch October 11, 2024 19:17
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this pull request Dec 17, 2024
…metry#35006)

**Description:** <Describe what has changed.>
It is a valid use case to aggregate against an empty label set, which
will functionally clear all attributes. This behaviour was removed in
open-telemetry#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:** open-telemetry#34430

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>

---------

Co-authored-by: Tyler Helmuth <[email protected]>
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.

7 participants