Repository navigation
Prometheus: improve the conversion of metric labels to data point and resource attributes #5356
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
dcdb927
e89b7d4
6709a74
933ed01
80b9712
a119e89
1cb54d4
2377f29
86ff3b9
5c438ee
528d2d6
264eda5
56b5c6e
7cdfcf6
713c587
7a9dadd
3eed842
6c4c1ea
eebb6a8
401d5cc
6c6e850
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ aliases: | |
| * [Dropped Types](#dropped-types) | ||
| * [Exemplars](#exemplars) | ||
| * [Instrumentation Scope](#instrumentation-scope) | ||
| * [Metric Attributes](#metric-attributes) | ||
| * [Resource Attributes](#resource-attributes) | ||
| - [OTLP Metric points to Prometheus](#otlp-metric-points-to-prometheus) | ||
| * [Metric Metadata](#metric-metadata-1) | ||
|
|
@@ -40,7 +41,7 @@ aliases: | |
| + [Histograms as Prometheus NHCB](#histograms-as-prometheus-nhcb) | ||
| * [Exponential Histograms](#exponential-histograms) | ||
| * [Summaries](#summaries-1) | ||
| * [Metric Attributes](#metric-attributes) | ||
| * [Metric Attributes](#metric-attributes-1) | ||
| * [Exemplar Conversion](#exemplar-conversion) | ||
| * [Resource Attributes](#resource-attributes-1) | ||
|
|
||
|
|
@@ -368,42 +369,90 @@ MUST be assigned an instrumentation scope identifying the entity performing | |
| the translation from Prometheus to OpenTelemetry (e.g. the collector's | ||
| Prometheus receiver). | ||
|
|
||
| ### Metric Attributes | ||
|
krajorama marked this conversation as resolved.
Resolved
|
||
|
|
||
| **Status**: [Development](../document-status.md) | ||
|
|
||
| Labels of metrics MUST be copied to data point attributes, except for the | ||
| following labels, which MUST NOT be copied: | ||
|
|
||
| - `__name__`, | ||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| - `job` and `instance`, | ||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| - the `le` label of classic Prometheus histogram buckets, | ||
| - the `quantile` label of Prometheus summaries, | ||
| - labels with the `otel_scope_` prefix, which are handled according to the | ||
| [Instrumentation Scope](#instrumentation-scope) rules. | ||
|
|
||
| Labels of the `target` info metric are implicitly excluded, as `target` info | ||
| metric samples are not turned into data points. | ||
|
|
||
| ### Resource Attributes | ||
|
|
||
| **Status**: [Development](../document-status.md) | ||
|
|
||
| When scraping a Prometheus endpoint, resource attributes MUST be added to the | ||
|
dashpole marked this conversation as resolved.
Resolved
dashpole marked this conversation as resolved.
Resolved
|
||
| scraped metrics to distinguish them from metrics from other Prometheus | ||
| endpoints. In particular, `service.name` and `service.instance.id`, are needed | ||
| to ensure Prometheus exporters can disambiguate metrics using | ||
| [`job` and `instance` labels](https://prometheus.io/docs/concepts/jobs_instances/) | ||
| as [described below](#resource-attributes-1). | ||
| endpoints. | ||
|
|
||
| The following attributes MUST be associated with scraped metrics as resource | ||
| attributes, and MUST NOT be added as metric attributes: | ||
| In Prometheus metrics the `job` and `instance` are considered identifying, | ||
|
dashpole marked this conversation as resolved.
Resolved
krajorama marked this conversation as resolved.
Resolved
|
||
| therefore a new resource MUST be created for each `job` and `instance` pair | ||
| encountered in the metrics labels, except for the `target` info metric. | ||
|
|
||
| | OTLP Resource Attribute | Description | | ||
| | ----------------------- | ----------- | | ||
| | `service.name` | The configured name of the service that the target belongs to | | ||
| | `service.instance.id` | A unique identifier of the target. By default, it should be the `<host>:<port>` of the scraped URL | | ||
| If there is no `job` label on a metric and the metrics are being scraped, | ||
| then the `job` label MUST be considered to be equal to the `job` label of the | ||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| scrape target. During scrape, the `job` label of the target may be equal to the scrape | ||
| job name or customized by relabel rules. | ||
|
krajorama marked this conversation as resolved.
Resolved
|
||
|
|
||
| If there is no `job` label on a metric and there is no `job` label for the | ||
| scrape target, the scrape MUST fail. Note that this is different from the | ||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| Prometheus behavior that still scrapes the metrics without `job`. | ||
|
|
||
| If there is no `instance` label and the metrics are being scraped, the | ||
| `instance` label MUST be considered to be equal to the `instance` label of the | ||
| scrape target. Note that the `instance` label of the target may be equal to the | ||
| `__address__` of the target or customized by relabel rules. | ||
|
krajorama marked this conversation as resolved.
Resolved
|
||
|
|
||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| For each resource the `service.name` attribute MUST be set to the | ||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| `service.name` label in `target` info metric, if that label exists in the | ||
| `target` info metric with the same `job` and `instance` key as the resource. | ||
| Otherwise `service.name` MUST be set to the value of the `job` label. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| For each resource the `service.instance.id` attribute MUST be set to the | ||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| `service.instance.id` label in `target` info metric, if that label exists in the | ||
| `target` info metric with the same `job` and `instance` key as the resource. | ||
| Otherwise `service.instance.id` MUST be set to the value of the `instance` | ||
| label. | ||
|
|
||
| The following attributes SHOULD be associated with scraped metrics as resource | ||
| attributes, and MUST NOT be added as metric attributes: | ||
| attributes, and MUST NOT be added as metric | ||
| attributes: | ||
|
|
||
| | OTLP Resource Attribute | Description | | ||
|
krajorama marked this conversation as resolved.
Resolved
|
||
| | ----------------------- | ----------- | | ||
| | `server.address` | The `<host>` portion of the target's URL that was scraped | | ||
| | `server.port` | The `<port>` portion of the target's URL that was scraped | | ||
| | `url.scheme` | `http` or `https` | | ||
| | `server.address` | The `<host>` portion of the `instance` unless it is localhost, a loopback address, or an unspecified address | | ||
|
dashpole marked this conversation as resolved.
Resolved
krajorama marked this conversation as resolved.
Resolved
|
||
| | `server.port` | The `<port>` portion of the `instance` | | ||
|
dashpole marked this conversation as resolved.
Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO open issue/PR
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the existing spec on
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds like a plan, let's discuss in the meeting and I can make the change back or whatever we decide to write here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the meeting: we don't want to do this in the remote write receiver, prefer to set at scrape time only as original data
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also found from my review that we should preserve
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dashpole opened open-telemetry/opentelemetry-collector-contrib#52570
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that open-telemetry/opentelemetry-collector-contrib#52570 is merged, we can update
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in eebb6a8 |
||
| | `url.scheme` | `http` or `https` from the `__scheme__` label on the target | | ||
|
krajorama marked this conversation as resolved.
Resolved
|
||
|
|
||
| Further attributes (such as from K8s service discovery metadata labels) MAY be | ||
|
krajorama marked this conversation as resolved.
Resolved
|
||
| added to the resource attributes. Labels from the `target` info metric take | ||
| precedence over all derived resource attributes. | ||
|
|
||
| To summarize, `service.name` and `service.instance.id`, are needed | ||
|
dashpole marked this conversation as resolved.
Resolved
|
||
| to ensure Prometheus exporters can disambiguate metrics using | ||
| [`job` and `instance` labels](https://prometheus.io/docs/concepts/jobs_instances/) | ||
| as [described below](#resource-attributes-1), therefore this specification | ||
| ensures that `service.name` and `service.instance.id` are always defined. | ||
|
|
||
| In addition to the attributes above, the | ||
| [target](https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems) | ||
| [`target`](https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems) | ||
| info metric is used to supply additional resource attributes. If present, | ||
| the `target` info metric MUST be dropped from the batch of metrics, and all labels from | ||
| the `target` info metric MUST be converted to resource attributes | ||
| attached to all other metrics which are part of the scrape. By default, label | ||
| keys and values MUST NOT be altered (such as replacing `_` with `.` characters | ||
| in keys). | ||
| the `target` info metric MUST be dropped from the batch of metrics, and all labels | ||
| except `job`, `instance` and `__name__` from the `target` info metric MUST be | ||
| converted to resource attributes attached to all other metrics which are part of | ||
| the same resource identified by `job` and `instance`. | ||
|
krajorama marked this conversation as resolved.
Resolved
|
||
|
|
||
| By default, label keys and values of the `target` info metric MUST NOT be | ||
| altered (such as replacing `_` with `.` characters in keys). | ||
|
|
||
| ## OTLP Metric points to Prometheus | ||
|
|
||
|
|
@@ -774,6 +823,7 @@ attributes MUST be combined as `<service.namespace>/<service.name>`, or | |
| `<service.name>` if namespace is empty, to form the `job` metric label. The | ||
| `service.instance.id` attribute, if present, MUST be converted to the | ||
| `instance` label; otherwise, `instance` should be added with an empty value. | ||
|
|
||
|
krajorama marked this conversation as resolved.
Resolved
|
||
| Other resource attributes SHOULD be converted to a | ||
| [target](https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems) | ||
| info metric, or MUST be dropped. The `target` metric is an info-typed metric | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.