Skip to content

Commit

Permalink
Add job and instance as well-known attribute in prometheus receiver (#…
Browse files Browse the repository at this point in the history
…2897)

In Prometheus, `job` and `instance` are the two auto generated labels, however they are both dropped by prometheus receiver. Although these information is still available in `service.name` and `host`:`port`, it breaks the data contract for most Prometheus users (who use `job` and `instance` to consume metrics in their own system).
This PR adds `job` and `instance` as well-known labels in prometheus receiver to fix the issue.

**Link to tracking Issue:** 
#575
#2499
#2363
open-telemetry/prometheus-interoperability-spec#7
  • Loading branch information
bjrara authored Apr 16, 2021
1 parent a0ac16a commit 2b33043
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions receiver/prometheusreceiver/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ import (
)

const (
portAttr = "port"
schemeAttr = "scheme"
portAttr = "port"
schemeAttr = "scheme"
jobAttr = "job"
instanceAttr = "instance"

transport = "http"
dataformat = "prometheus"
Expand Down Expand Up @@ -227,8 +229,10 @@ func createNodeAndResource(job, instance, scheme string) (*commonpb.Node, *resou
}
resource := &resourcepb.Resource{
Labels: map[string]string{
portAttr: port,
schemeAttr: scheme,
jobAttr: job,
instanceAttr: instance,
portAttr: port,
schemeAttr: scheme,
},
}
return node, resource
Expand Down
6 changes: 4 additions & 2 deletions receiver/prometheusreceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ func setupMockPrometheus(tds ...*testData) (*mockPrometheus, *promcfg.Config, er
}
t.resource = &resourcepb.Resource{
Labels: map[string]string{
"scheme": "http",
"port": port,
"instance": u.Host,
"job": t.name,
"scheme": "http",
"port": port,
},
}
}
Expand Down

0 comments on commit 2b33043

Please sign in to comment.