forked from kyma-project/telemetry-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve_service_name_proc.go
60 lines (50 loc) · 1.83 KB
/
resolve_service_name_proc.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gatewayprocs
import (
"fmt"
"github.com/kyma-project/telemetry-manager/internal/otelcollector/config"
"github.com/kyma-project/telemetry-manager/internal/otelcollector/config/ottlexpr"
)
func ResolveServiceNameStatements() []config.TransformProcessorStatements {
attributes := []string{
"kyma.kubernetes_io_app_name",
"kyma.app_name",
"k8s.deployment.name",
"k8s.daemonset.name",
"k8s.statefulset.name",
"k8s.job.name",
"k8s.pod.name",
}
var statements []string
for _, attr := range attributes {
statements = append(statements, inferServiceNameFromAttr(attr))
}
statements = append(statements, setDefaultServiceName())
return []config.TransformProcessorStatements{
{
Statements: statements,
},
}
}
// serviceNameNotDefinedBasicCondition specifies the cases for which the service.name attribute is not defined
// without considering the "unknown_service" and the "unknown_service:<process.executable.name>" cases
const serviceNameNotDefinedBasicCondition = "resource.attributes[\"service.name\"] == nil or resource.attributes[\"service.name\"] == \"\""
func inferServiceNameFromAttr(attrKey string) string {
// serviceNameNotDefinedCondition builds up on the serviceNameNotDefinedBasicCondition
// to consider the "unknown_service" and the "unknown_service:<process.executable.name>" cases
serviceNameNotDefinedCondition := fmt.Sprintf(
"%s or %s",
serviceNameNotDefinedBasicCondition,
ottlexpr.IsMatch("resource.attributes[\"service.name\"]", "^unknown_service(:.+)?$"),
)
return fmt.Sprintf(
"set(resource.attributes[\"service.name\"], resource.attributes[\"%s\"]) where %s",
attrKey,
serviceNameNotDefinedCondition,
)
}
func setDefaultServiceName() string {
return fmt.Sprintf(
"set(resource.attributes[\"service.name\"], \"unknown_service\") where %s",
serviceNameNotDefinedBasicCondition,
)
}