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

groupbyattrsprocessor drops metric metadata #33419

Closed
braydonk opened this issue Jun 6, 2024 · 13 comments
Closed

groupbyattrsprocessor drops metric metadata #33419

braydonk opened this issue Jun 6, 2024 · 13 comments
Assignees
Labels
bug Something isn't working processor/groupbyattrs Group By Attributes processor Stale

Comments

@braydonk
Copy link
Contributor

braydonk commented Jun 6, 2024

Component(s)

processor/groupbyattrs

What happened?

Description

When groupbyattrsprocessor makes a new metric, it does not copy the metric metadata. I assume this is because Metadata is a relatively new field and isn't fully respected everywhere yet.

Steps to Reproduce

Found this by testing the new untyped metric support in Prometheus. It adds a Metadata key called prometheus.type. So that's the easiest way to see the effect. Create a pipeline from prometheusreceiver to groupbyattrsprocessor to debugexporter and have it scrape some manner of metrics.

Expected Result

The prometheus.type metadata should still be present when the value is seen in debugexporter.

Actual Result

It's gone.

Other notes

Collector version

v0.102.0

Environment information

Environment

OS: Debian 12
Compiler(if manually compiled): go 1.22.3

OpenTelemetry Collector configuration

No response

Log output

Nothing of note.

Additional context

Should there be an actual API in pdata for making full metric copies like this? What the groupbyattrsprocessor has to do here is pretty brittle for exactly this reason, and I'm not sure if there are other processors doing something similar.

@braydonk braydonk added bug Something isn't working needs triage New item requiring triage labels Jun 6, 2024
Copy link
Contributor

github-actions bot commented Jun 6, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the processor/groupbyattrs Group By Attributes processor label Jun 6, 2024
@braydonk
Copy link
Contributor Author

braydonk commented Jun 6, 2024

FYI @dashpole @ridwanmsharif

@dashpole
Copy link
Contributor

dashpole commented Jun 6, 2024

There is a CopyTo function for metrics, but i'm not sure if that is what is needed here.

@braydonk
Copy link
Contributor Author

braydonk commented Jun 6, 2024

For reference, this is the spot that does not copy metadata:

// We're here, which means that we haven't found our metric, so we need to create a new one, with the same name and type
metric := ilm.Metrics().AppendEmpty()
metric.SetDescription(searchedMetric.Description())
metric.SetName(searchedMetric.Name())
metric.SetUnit(searchedMetric.Unit())

@rnishtala-sumo
Copy link
Contributor

rnishtala-sumo commented Jun 10, 2024

@braydonk looks like this could done using - https://pkg.go.dev/go.opentelemetry.io/collector/pdata@v1.9.0/pmetric#Metric.CopyTo

as suggested previously. I think the ask here makes sense. Please go ahead If you'd like to make the change. I can review the changes when ready.

@crobert-1
Copy link
Member

Removing needs triage based on code owner feedback.

@crobert-1 crobert-1 removed the needs triage New item requiring triage label Jun 10, 2024
@odubajDT
Copy link
Contributor

If nobody is working on this issue, I would like to take it cc @evan-bradley

@odubajDT
Copy link
Contributor

odubajDT commented Jun 26, 2024

@braydonk looks like this could done using - https://pkg.go.dev/go.opentelemetry.io/collector/pdata@v1.9.0/pmetric#Metric.CopyTo

as suggested previously. I think the ask here makes sense. Please go ahead If you'd like to make the change. I can review the changes when ready.

After some investigation, using Metric.CopyTo() function is problematic here. The function copies also the datapoints from the original metric which goes exactly against the purpose of this processor, where datapoints are moved in between metrics. Therefore when creating new metric here (with empty datapoint slice) and using the CopyTo() function with it will lead to adding datapoints which are in the input and should not be present on output.

Therefore I would suggest adding the missing CopyTo() function only for metadata here unless we want to do a major refactoring of the code of the processor.

I am opened for suggestions

@braydonk
Copy link
Contributor Author

Thanks for taking on this issue!

Might be naive, but perhaps the datapoints could just be deleted from the copy of the metric? If that won't work then it's fine to just do the metadata copy. Just would be nice if the full metric CopyTo function would work just to avoid this kind of thing happening again.

@odubajDT
Copy link
Contributor

Thanks for taking on this issue!

Might be naive, but perhaps the datapoints could just be deleted from the copy of the metric? If that won't work then it's fine to just do the metadata copy. Just would be nice if the full metric CopyTo function would work just to avoid this kind of thing happening again.

This should work, but when deleting datapoints, we still need to first find out, what type are we dealing with (sum/gauge/histogram...) and firstly then delete the appropiate datapoints (these are also different types - numeric value/ histogram value/...).

Therefore I do not see any improvement in the logic here, since still the logic determining the type for the metric needs to stay in place and instead of creating empty metrics, we will copy them and them delete parts of them.

@braydonk
Copy link
Contributor Author

Ah okay I understand the issue now. Probably fine to just use the metadata copy then; it's probably sufficiently rare for that metric proto to change much for this kind of thing to happen again. Thanks!

evan-bradley pushed a commit that referenced this issue Jul 15, 2024
…g metrics (#33781)

**Description:**
Fixes the metadata dropping when processing metrics

**Link to tracking Issue:** #33419 

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

---------

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
Copy link
Contributor

github-actions bot commented Sep 2, 2024

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label Sep 2, 2024
@dashpole
Copy link
Contributor

dashpole commented Sep 3, 2024

Fixed by #33781

@dashpole dashpole closed this as completed Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working processor/groupbyattrs Group By Attributes processor Stale
Projects
None yet
Development

No branches or pull requests

6 participants