-
Notifications
You must be signed in to change notification settings - Fork 3.1k
receiver/prometheus: Populate scope attributes from labels instead of otel_scope_info #40060
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
receiver/prometheus: Populate scope attributes from labels instead of otel_scope_info #40060
Conversation
82b3f12 to
85a566c
Compare
|
PoC ready for review! |
|
Has it been tested together with open-telemetry/opentelemetry-go#5947? This is what I guess from: open-telemetry/opentelemetry-go#5947 (comment) |
|
@pellared What I tested was that the Go SDK's Prometheus exporter runs properly when the Collector emits internal metrics that only differ in their scope attributes. I haven't tested Contrib's receiver. |
|
I'll run some tests today with the full pipeline: Go-SDK -> Prometheus Receiver -> Prometheus Exporter/ Debug Exporter |
|
Manual tests are showing that I broke the current behavior that extracts attributes from Back to draft |
176be90 to
9faa9a7
Compare
|
Still working on this and still strugging to fix it. I've changed the test strategy to something that tests more end2end, and this one triggers the nilpointers I'm seeing when doing manual tests with the whole pipeline go-sdk->prom-receiver->debug exporter |
Fixes #4223 Prototypes: - open-telemetry/opentelemetry-go#5947 - open-telemetry/opentelemetry-go#6770 - open-telemetry/opentelemetry-java#7356 - open-telemetry/opentelemetry-collector-contrib#40060 - open-telemetry/opentelemetry-collector-contrib#40004 ## Changes Currently (before this PR) [Prometheus and OpenMetrics Compatibility](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md) assumes that only scope name and scope version are identifying. However, with #4161 this is no longer true. Therefore, this PR updates the Prometheus and OpenMetrics Compatibility specification to add the scope name, version, schema URL, scope attributes to all metrics. This also removes the `otel_scope_info` as it looks that it won't be useful. See: #4223 (comment). This change important for Collector open-telemetry/opentelemetry-go#5846 (comment). It is also is necessary towards stabilization of OTel-Prom/OpenMetrics compatibility) and the Prometheus exporter. _Initially, I thought about [splitting it into a few PRs](#4223 (comment)). However, it looks like doing it in one PR would be a more complete approach (also there are not that many changes)._ --------- Co-authored-by: Jade Guiton <[email protected]> Co-authored-by: Carlos Alberto Cortez <[email protected]>
Fixes #4223 Prototypes: - open-telemetry/opentelemetry-go#5947 - open-telemetry/opentelemetry-go#6770 - open-telemetry/opentelemetry-java#7356 - open-telemetry/opentelemetry-collector-contrib#40060 - open-telemetry/opentelemetry-collector-contrib#40004 ## Changes Currently (before this PR) [Prometheus and OpenMetrics Compatibility](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md) assumes that only scope name and scope version are identifying. However, with #4161 this is no longer true. Therefore, this PR updates the Prometheus and OpenMetrics Compatibility specification to add the scope name, version, schema URL, scope attributes to all metrics. This also removes the `otel_scope_info` as it looks that it won't be useful. See: #4223 (comment). This change important for Collector open-telemetry/opentelemetry-go#5846 (comment). It is also is necessary towards stabilization of OTel-Prom/OpenMetrics compatibility) and the Prometheus exporter. _Initially, I thought about [splitting it into a few PRs](#4223 (comment)). However, it looks like doing it in one PR would be a more complete approach (also there are not that many changes)._ --------- Co-authored-by: Jade Guiton <[email protected]> Co-authored-by: Carlos Alberto Cortez <[email protected]>
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
|
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
9faa9a7 to
f9d9614
Compare
f9d9614 to
3f8b8cc
Compare
|
I think we should proceed with whatever you have working, and open an issue with your profiles, etc to look into optimizing that code path. |
c721b63 to
f40b998
Compare
0b034b8 to
f49d021
Compare
Once the |
979c23d to
eb9b37c
Compare
| var emptyScopeID scopeID | ||
| // ScopeIdentifier represents an identifier for a metric scope, which can include | ||
| // just the basic scope information or also include scope attributes. | ||
| type ScopeIdentifier interface { |
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 would rather define a hash function on a metric scope if we can, and use maps of uint64. String appending is very expensive--especially compared to hashing. Maybe we could add it to https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/5404f7c2434387d8b68f3be6010a72fded822d85/pkg/pdatautil/hash.go?
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'm not sure I understand what you mean here 😬, could you give a code example?
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.
func ScopeHash64(scope pcommon.InstrumentationScope) uint64 {
return pdatautil.Hash64(pdatautil.WithString(scope.Name()), pdatautil.WithString(scope.Version()), pdatautil.WithMap(scope.Attributes())
}Your code would use the uint64 hash as the map key for the scope:
- Construct the InstrumentationScope from the metric's labels.
- Compute the hash of the scope.
- Lookup the ScopeMetrics using the hash
- Append the metric to that ScopeMetrics.
Does that make sense?
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.
Map lookups with a uint64 is MUCH faster than with a data structure, although collisions are possible. We could do the same for the ResourceMetrics lookup if we made a hash function for the resource.
| scopeMap map[resourceKey]map[string]ScopeIdentifier | ||
| scopeAttributes map[resourceKey]map[LegacyScopeID]pcommon.Map // Legacy mode only |
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.
Why do we need both of these? Can't we just have a map[resourceKey]map[string]ScopeIdentifier?
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.
The "ID" string can just be constructed differently depending on whether the feature gate is enabled or not. For legacy, the id string is just the name + version. For the new approach, it would be constructed with the entire scope.
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 imagine people will have a mix of clients for some time. Some will use the new scope attributes on metrics, and others will still be using otel_scope_info. I think we should always add otel_scope_foo attributes as scope attributes, and use the feature gate to remove special handling of otel_scope_info.
Hmmm, good point. Let me change that |
Signed-off-by: Arthur Silva Sens <[email protected]>
…cope_info Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
… labels from otel_scope_info metric Signed-off-by: Arthur Silva Sens <[email protected]>
eb9b37c to
0d4282d
Compare
|
Okay, I've added a commit changing the behavior of the feature gate. Now, we're always parsing attributes from labels prefixed with Could we first review this part, and if necessary, we can refactor the duplicate map(#40060 (comment)) after this review? |
Sure |
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
|
Closed as inactive. Feel free to reopen if this PR is still being worked on. |


Description
This PR is a PoC for the spec change described at open-telemetry/opentelemetry-specification#4223.
In the specification change, it's proposed that Prometheus exporters stop generating the metric
otel_scope_infowith all the scope attributes and instead add all scope information as labels, turning the Scope information "identifying".For the receiver, this means that Scope should no longer be populated from the
otel_scope_infobut should instead be looked for metrics with the same labels prefixed withotel_scope_.For users who still haven't updated to newer versions of the SDK that adhere to the spec change, ignoring the
otel_scope_infometric would be a breaking change from this receiver's perspective. For that reason, this change is being made through feature flags.If an exporter exposes
otel_scope_infoand the feature gatereceiver.prometheusreceiver.RemoteScopeInfois enabled, thenotel_scope_infowill be transformed into a metric like all others instead of being cached and used to generate ScopeMetrics informationFixes #41502