generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 23
/
traces_service_name_test.go
143 lines (115 loc) · 5.69 KB
/
traces_service_name_test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//go:build e2e
package e2e
import (
"net/http"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/kyma-project/telemetry-manager/internal/testutils"
"github.com/kyma-project/telemetry-manager/test/testkit/assert"
kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s"
kitkyma "github.com/kyma-project/telemetry-manager/test/testkit/kyma"
. "github.com/kyma-project/telemetry-manager/test/testkit/matchers/trace"
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend"
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/servicenamebundle"
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/telemetrygen"
"github.com/kyma-project/telemetry-manager/test/testkit/periodic"
"github.com/kyma-project/telemetry-manager/test/testkit/suite"
)
var _ = Describe(suite.ID(), Label(suite.LabelTraces), func() {
var (
mockNs = suite.ID()
pipelineName = suite.ID()
backendExportURL string
)
makeResources := func() []client.Object {
var objs []client.Object
objs = append(objs, kitk8s.NewNamespace(mockNs).K8sObject())
backend := backend.New(mockNs, backend.SignalTypeTraces)
objs = append(objs, backend.K8sObjects()...)
backendExportURL = backend.ExportURL(proxyClient)
tracePipeline := testutils.NewTracePipelineBuilder().
WithName(pipelineName).
WithOTLPOutput(testutils.OTLPEndpoint(backend.Endpoint())).
Build()
objs = append(objs, &tracePipeline)
objs = append(objs, servicenamebundle.K8sObjects(mockNs, telemetrygen.SignalTypeTraces)...)
return objs
}
Context("When a TracePipeline exists", Ordered, func() {
BeforeAll(func() {
k8sObjects := makeResources()
DeferCleanup(func() {
Expect(kitk8s.DeleteObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed())
})
Expect(kitk8s.CreateObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed())
})
It("Should have a running trace gateway deployment", func() {
assert.DeploymentReady(ctx, k8sClient, kitkyma.TraceGatewayName)
})
It("Should have a trace backend running", func() {
assert.DeploymentReady(ctx, k8sClient, types.NamespacedName{Name: backend.DefaultName, Namespace: mockNs})
})
It("Should have a running pipeline", func() {
assert.TracePipelineHealthy(ctx, k8sClient, pipelineName)
})
verifyServiceNameAttr := func(givenPodPrefix, expectedServiceName string) {
Eventually(func(g Gomega) {
resp, err := proxyClient.Get(backendExportURL)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(resp).To(HaveHTTPStatus(http.StatusOK))
g.Expect(resp).To(HaveHTTPBody(
ContainTd(SatisfyAll(
ContainResourceAttrs(HaveKeyWithValue("service.name", expectedServiceName)),
ContainResourceAttrs(HaveKeyWithValue("k8s.pod.name", ContainSubstring(givenPodPrefix))),
)),
))
}, periodic.TelemetryEventuallyTimeout, periodic.TelemetryInterval).Should(Succeed())
}
It("Should set undefined service.name attribute to app.kubernetes.io/name label value", func() {
verifyServiceNameAttr(servicenamebundle.PodWithBothLabelsName, servicenamebundle.KubeAppLabelValue)
})
It("Should set undefined service.name attribute to app label value", func() {
verifyServiceNameAttr(servicenamebundle.PodWithAppLabelName, servicenamebundle.AppLabelValue)
})
It("Should set undefined service.name attribute to Deployment name", func() {
verifyServiceNameAttr(servicenamebundle.DeploymentName, servicenamebundle.DeploymentName)
})
It("Should set undefined service.name attribute to StatefulSet name", func() {
verifyServiceNameAttr(servicenamebundle.StatefulSetName, servicenamebundle.StatefulSetName)
})
It("Should set undefined service.name attribute to DaemonSet name", func() {
verifyServiceNameAttr(servicenamebundle.DaemonSetName, servicenamebundle.DaemonSetName)
})
It("Should set undefined service.name attribute to Job name", func() {
verifyServiceNameAttr(servicenamebundle.JobName, servicenamebundle.JobName)
})
It("Should set undefined service.name attribute to Pod name", func() {
verifyServiceNameAttr(servicenamebundle.PodWithNoLabelsName, servicenamebundle.PodWithNoLabelsName)
})
It("Should enrich service.name attribute when its value is unknown_service", func() {
verifyServiceNameAttr(servicenamebundle.PodWithUnknownServiceName, servicenamebundle.PodWithUnknownServiceName)
})
It("Should enrich service.name attribute when its value is following the unknown_service:<process.executable.name> pattern", func() {
verifyServiceNameAttr(servicenamebundle.PodWithUnknownServicePatternName, servicenamebundle.PodWithUnknownServicePatternName)
})
It("Should NOT enrich service.name attribute when its value is not following the unknown_service:<process.executable.name> pattern", func() {
verifyServiceNameAttr(servicenamebundle.PodWithInvalidStartForUnknownServicePatternName, servicenamebundle.AttrWithInvalidStartForUnknownServicePattern)
verifyServiceNameAttr(servicenamebundle.PodWithInvalidEndForUnknownServicePatternName, servicenamebundle.AttrWithInvalidEndForUnknownServicePattern)
verifyServiceNameAttr(servicenamebundle.PodWithMissingProcessForUnknownServicePatternName, servicenamebundle.AttrWithMissingProcessForUnknownServicePattern)
})
It("Should have no kyma resource attributes", func() {
Eventually(func(g Gomega) {
resp, err := proxyClient.Get(backendExportURL)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(resp).To(HaveHTTPStatus(http.StatusOK))
g.Expect(resp).To(HaveHTTPBody(
Not(ContainTd(
ContainResourceAttrs(HaveKey(ContainSubstring("kyma"))),
)),
))
}, periodic.EventuallyTimeout, periodic.TelemetryInterval).Should(Succeed())
})
})
})