-
Notifications
You must be signed in to change notification settings - Fork 487
/
target.go
35 lines (31 loc) · 977 Bytes
/
target.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
package java
import (
"fmt"
"github.com/grafana/agent/component/discovery"
)
const (
labelServiceName = "service_name"
labelServiceNameK8s = "__meta_kubernetes_pod_annotation_pyroscope_io_service_name"
)
func inferServiceName(target discovery.Target) string {
k8sServiceName := target[labelServiceNameK8s]
if k8sServiceName != "" {
return k8sServiceName
}
k8sNamespace := target["__meta_kubernetes_namespace"]
k8sContainer := target["__meta_kubernetes_pod_container_name"]
if k8sNamespace != "" && k8sContainer != "" {
return fmt.Sprintf("java/%s/%s", k8sNamespace, k8sContainer)
}
dockerContainer := target["__meta_docker_container_name"]
if dockerContainer != "" {
return dockerContainer
}
if swarmService := target["__meta_dockerswarm_container_label_service_name"]; swarmService != "" {
return swarmService
}
if swarmService := target["__meta_dockerswarm_service_name"]; swarmService != "" {
return swarmService
}
return "unspecified"
}