Skip to content

Commit a3ea750

Browse files
authored
Enable integration only when datastreams are not defined (#1456)
1 parent b0a98e2 commit a3ea750

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

internal/pkg/composable/providers/kubernetes/hints.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ func GenerateHintsMapping(hints mapstr.M, kubeMeta mapstr.M, logger *logp.Logger
144144
if integration == "" {
145145
return hintsMapping
146146
}
147-
integrationHints := mapstr.M{
148-
"enabled": true,
149-
}
147+
integrationHints := mapstr.M{}
150148

151149
if containerID != "" {
152150
_, _ = hintsMapping.Put("container_id", containerID)
@@ -194,6 +192,9 @@ func GenerateHintsMapping(hints mapstr.M, kubeMeta mapstr.M, logger *logp.Logger
194192
}
195193

196194
dataStreams := builder.getDataStreams(hints)
195+
if len(dataStreams) == 0 {
196+
_, _ = integrationHints.Put("enabled", true)
197+
}
197198
for _, dataStream := range dataStreams {
198199
streamHints := mapstr.M{
199200
"enabled": true,

internal/pkg/composable/providers/kubernetes/hints_test.go

+70-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func TestGenerateHintsMapping(t *testing.T) {
7878

7979
expected := mapstr.M{
8080
"redis": mapstr.M{
81-
"enabled": true,
8281
"host": "127.0.0.5:6379",
8382
"metrics_path": "/metrics",
8483
"username": "username",
@@ -118,6 +117,76 @@ func TestGenerateHintsMapping(t *testing.T) {
118117
assert.Equal(t, expected, hintsMapping)
119118
}
120119

120+
func TestGenerateHintsMappingWithDefaults(t *testing.T) {
121+
logger := getLogger()
122+
pod := &kubernetes.Pod{
123+
ObjectMeta: metav1.ObjectMeta{
124+
Name: "testpod",
125+
UID: types.UID(uid),
126+
Namespace: "testns",
127+
Labels: map[string]string{
128+
"foo": "bar",
129+
"with-dash": "dash-value",
130+
"with/slash": "some/path",
131+
},
132+
Annotations: map[string]string{
133+
"app": "production",
134+
},
135+
},
136+
TypeMeta: metav1.TypeMeta{
137+
Kind: "Pod",
138+
APIVersion: "v1",
139+
},
140+
Spec: kubernetes.PodSpec{
141+
NodeName: "testnode",
142+
},
143+
Status: kubernetes.PodStatus{PodIP: "127.0.0.5"},
144+
}
145+
146+
mapping := map[string]interface{}{
147+
"namespace": pod.GetNamespace(),
148+
"pod": mapstr.M{
149+
"uid": string(pod.GetUID()),
150+
"name": pod.GetName(),
151+
"ip": pod.Status.PodIP,
152+
},
153+
"namespace_annotations": mapstr.M{
154+
"nsa": "nsb",
155+
},
156+
"labels": mapstr.M{
157+
"foo": "bar",
158+
"with-dash": "dash-value",
159+
"with/slash": "some/path",
160+
},
161+
"annotations": mapstr.M{
162+
"app": "production",
163+
},
164+
}
165+
hints := mapstr.M{
166+
"hints": mapstr.M{
167+
"host": "${kubernetes.pod.ip}:6379",
168+
"package": "redis",
169+
"metrics_path": "/metrics",
170+
"timeout": "42s",
171+
"period": "42s",
172+
},
173+
}
174+
175+
expected := mapstr.M{
176+
"redis": mapstr.M{
177+
"enabled": true,
178+
"host": "127.0.0.5:6379",
179+
"metrics_path": "/metrics",
180+
"timeout": "42s",
181+
"period": "42s",
182+
},
183+
}
184+
185+
hintsMapping := GenerateHintsMapping(hints, mapping, logger, "")
186+
187+
assert.Equal(t, expected, hintsMapping)
188+
}
189+
121190
func TestGenerateHintsMappingWithContainerID(t *testing.T) {
122191
logger := getLogger()
123192
pod := &kubernetes.Pod{
@@ -184,7 +253,6 @@ func TestGenerateHintsMappingWithContainerID(t *testing.T) {
184253
"container_logs": mapstr.M{
185254
"enabled": true,
186255
},
187-
"enabled": true,
188256
"host": "127.0.0.5:6379",
189257
"metrics_path": "/metrics",
190258
"username": "username",
@@ -281,7 +349,6 @@ func TestGenerateHintsMappingWithLogStream(t *testing.T) {
281349
expected := mapstr.M{
282350
"container_id": "asdfghjkl",
283351
"apache": mapstr.M{
284-
"enabled": true,
285352
"container_logs": mapstr.M{
286353
"enabled": true,
287354
},

0 commit comments

Comments
 (0)