-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
utils.go
41 lines (34 loc) · 1.18 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package prometheusexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter"
import (
"fmt"
"go.opentelemetry.io/collector/pdata/pcommon"
conventions "go.opentelemetry.io/collector/semconv/v1.25.0"
)
func resourceSignature(attributes pcommon.Map) string {
job, _ := extractJob(attributes)
instance, _ := extractInstance(attributes)
if job == "" || instance == "" {
return ""
}
return job + separatorString + instance
}
func extractInstance(attributes pcommon.Map) (string, bool) {
// Map service.instance.id to instance
if inst, ok := attributes.Get(conventions.AttributeServiceInstanceID); ok {
return inst.AsString(), true
}
return "", false
}
func extractJob(attributes pcommon.Map) (string, bool) {
// Map service.name + service.namespace to job
if serviceName, ok := attributes.Get(conventions.AttributeServiceName); ok {
job := serviceName.AsString()
if serviceNamespace, ok := attributes.Get(conventions.AttributeServiceNamespace); ok {
job = fmt.Sprintf("%s/%s", serviceNamespace.AsString(), job)
}
return job, true
}
return "", false
}