Skip to content

Commit

Permalink
Enable integration only when datastreams are not defined (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrsMark authored Oct 10, 2022
1 parent b0a98e2 commit a3ea750
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
7 changes: 4 additions & 3 deletions internal/pkg/composable/providers/kubernetes/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ func GenerateHintsMapping(hints mapstr.M, kubeMeta mapstr.M, logger *logp.Logger
if integration == "" {
return hintsMapping
}
integrationHints := mapstr.M{
"enabled": true,
}
integrationHints := mapstr.M{}

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

dataStreams := builder.getDataStreams(hints)
if len(dataStreams) == 0 {
_, _ = integrationHints.Put("enabled", true)
}
for _, dataStream := range dataStreams {
streamHints := mapstr.M{
"enabled": true,
Expand Down
73 changes: 70 additions & 3 deletions internal/pkg/composable/providers/kubernetes/hints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func TestGenerateHintsMapping(t *testing.T) {

expected := mapstr.M{
"redis": mapstr.M{
"enabled": true,
"host": "127.0.0.5:6379",
"metrics_path": "/metrics",
"username": "username",
Expand Down Expand Up @@ -118,6 +117,76 @@ func TestGenerateHintsMapping(t *testing.T) {
assert.Equal(t, expected, hintsMapping)
}

func TestGenerateHintsMappingWithDefaults(t *testing.T) {
logger := getLogger()
pod := &kubernetes.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "testpod",
UID: types.UID(uid),
Namespace: "testns",
Labels: map[string]string{
"foo": "bar",
"with-dash": "dash-value",
"with/slash": "some/path",
},
Annotations: map[string]string{
"app": "production",
},
},
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
Spec: kubernetes.PodSpec{
NodeName: "testnode",
},
Status: kubernetes.PodStatus{PodIP: "127.0.0.5"},
}

mapping := map[string]interface{}{
"namespace": pod.GetNamespace(),
"pod": mapstr.M{
"uid": string(pod.GetUID()),
"name": pod.GetName(),
"ip": pod.Status.PodIP,
},
"namespace_annotations": mapstr.M{
"nsa": "nsb",
},
"labels": mapstr.M{
"foo": "bar",
"with-dash": "dash-value",
"with/slash": "some/path",
},
"annotations": mapstr.M{
"app": "production",
},
}
hints := mapstr.M{
"hints": mapstr.M{
"host": "${kubernetes.pod.ip}:6379",
"package": "redis",
"metrics_path": "/metrics",
"timeout": "42s",
"period": "42s",
},
}

expected := mapstr.M{
"redis": mapstr.M{
"enabled": true,
"host": "127.0.0.5:6379",
"metrics_path": "/metrics",
"timeout": "42s",
"period": "42s",
},
}

hintsMapping := GenerateHintsMapping(hints, mapping, logger, "")

assert.Equal(t, expected, hintsMapping)
}

func TestGenerateHintsMappingWithContainerID(t *testing.T) {
logger := getLogger()
pod := &kubernetes.Pod{
Expand Down Expand Up @@ -184,7 +253,6 @@ func TestGenerateHintsMappingWithContainerID(t *testing.T) {
"container_logs": mapstr.M{
"enabled": true,
},
"enabled": true,
"host": "127.0.0.5:6379",
"metrics_path": "/metrics",
"username": "username",
Expand Down Expand Up @@ -281,7 +349,6 @@ func TestGenerateHintsMappingWithLogStream(t *testing.T) {
expected := mapstr.M{
"container_id": "asdfghjkl",
"apache": mapstr.M{
"enabled": true,
"container_logs": mapstr.M{
"enabled": true,
},
Expand Down

0 comments on commit a3ea750

Please sign in to comment.