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

[prometheusexporter] Add job and instance labels to match federated prometheus #8355

Closed
dashpole opened this issue Mar 9, 2022 · 2 comments · Fixed by #9115
Closed

[prometheusexporter] Add job and instance labels to match federated prometheus #8355

dashpole opened this issue Mar 9, 2022 · 2 comments · Fixed by #9115
Assignees
Labels
comp:prometheus Prometheus related issues enhancement New feature or request spec:metrics

Comments

@dashpole
Copy link
Contributor

dashpole commented Mar 9, 2022

Description
As described in the OpenTelemetry -> prometheus conversion specification, prometheus exporters must add job and instance labels to exported metrics in the collector:

In the collector Prometheus exporters, the service.name and service.namespace 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.

This allows a user to scrape the prometheuxexporter's endpoint with honor_labels: true to preserve the original job and instance labels as described in https://prometheus.io/docs/prometheus/latest/federation/#configuring-federation.

Currently, the prometheus exporter only adds metric attributes:

func (c *collector) getMetricMetadata(metric pdata.Metric, attributes pdata.AttributeMap) (*prometheus.Desc, []string) {
keys := make([]string, 0, attributes.Len())
values := make([]string, 0, attributes.Len())
attributes.Range(func(k string, v pdata.AttributeValue) bool {
keys = append(keys, sanitize(k, c.skipSanitizeLabel))
values = append(values, v.AsString())
return true
})
return prometheus.NewDesc(
c.metricName(c.namespace, metric),
metric.Description(),
keys,
c.constLabels,
), values
}

@dashpole dashpole added enhancement New feature or request spec:metrics comp:prometheus Prometheus related issues labels Mar 9, 2022
@gouthamve
Copy link
Member

Hi, I am working on this issue. Just to make sure there are not others working on it as well :)

@dashpole
Copy link
Contributor Author

Hey @gouthamve, I see your comment on #5757 (comment). For manual testing of honor_labels, you use an upstream prometheus server. For unit testing, can we just make sure job and instance appear correctly on scraped metrics without using the prometheus receiver?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:prometheus Prometheus related issues enhancement New feature or request spec:metrics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants