Skip to content

Commit

Permalink
test: add integration test for partial routing
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Rosiek <[email protected]>
  • Loading branch information
Dominik Rosiek committed May 23, 2024
1 parent e35edd9 commit 5f7b588
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 1 deletion.
122 changes: 122 additions & 0 deletions tests/integration/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func GetAdditionalLogsFeature() features.Feature {
},
waitDuration,
tickDuration,
false,
)).
Assess("logs from log generator daemonset present", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
logsGeneratorCount,
Expand All @@ -433,6 +434,7 @@ func GetAdditionalLogsFeature() features.Feature {
},
waitDuration,
tickDuration,
false,
)).
Assess("expected container log metadata is present for log generator deployment", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
logsGeneratorCount,
Expand Down Expand Up @@ -465,6 +467,7 @@ func GetAdditionalLogsFeature() features.Feature {
},
waitDuration,
tickDuration,
false,
)).
Assess("expected container log metadata is present for log generator daemonset", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
logsGeneratorCount,
Expand Down Expand Up @@ -496,6 +499,7 @@ func GetAdditionalLogsFeature() features.Feature {
},
waitDuration,
tickDuration,
false,
)).
Assess("logs from node systemd present", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
10, // we don't really control this, just want to check if the logs show up
Expand All @@ -507,6 +511,7 @@ func GetAdditionalLogsFeature() features.Feature {
},
waitDuration,
tickDuration,
false,
)).
Assess("logs from kubelet present", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
1, // we don't really control this, just want to check if the logs show up
Expand All @@ -518,6 +523,123 @@ func GetAdditionalLogsFeature() features.Feature {
},
waitDuration,
tickDuration,
false,
)).
Feature()
}

func GetAdditionalPartiallyLogsFeature() features.Feature {
return features.New("additional exporter logs").
Assess("logs from log generator deployment present", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
logsGeneratorCount,
map[string]string{
"namespace": internal.LogsGeneratorName,
"pod_labels_app": internal.LogsGeneratorName,
"deployment": internal.LogsGeneratorName,
},
waitDuration,
tickDuration,
false,
)).
Assess("logs from log generator daemonset present", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
0,
map[string]string{
"namespace": internal.LogsGeneratorName,
"pod_labels_app": internal.LogsGeneratorName,
"daemonset": internal.LogsGeneratorName,
},
waitDuration,
tickDuration,
true,
)).
Assess("expected container log metadata is present for log generator deployment", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
0,
map[string]string{
"cluster": internal.ClusterName,
// TODO: uncomment this after v4 release
// or make it depend on the metadata provider
// "_collector": internal.ClusterName,
"namespace": internal.LogsGeneratorName,
"pod_labels_app": internal.LogsGeneratorName,
"container": internal.LogsGeneratorName,
"deployment": internal.LogsGeneratorName,
"pod": fmt.Sprintf("%s%s", internal.LogsGeneratorName, internal.PodDeploymentSuffixRegex),
"host": internal.NodeNameRegex,
"node": internal.NodeNameRegex,
"_sourceName": fmt.Sprintf(
"%s\\.%s%s\\.%s",
internal.LogsGeneratorNamespace,
internal.LogsGeneratorName,
internal.PodDeploymentSuffixRegex,
internal.LogsGeneratorName,
),
"_sourceCategory": fmt.Sprintf(
"%s/%s/%s", // dashes instead of hyphens due to sourceCategoryReplaceDash
internal.ClusterName,
strings.ReplaceAll(internal.LogsGeneratorNamespace, "-", "/"),
strings.ReplaceAll(internal.LogsGeneratorName, "-", "/"), // this is the pod name prefix, in this case the deployment name
),
"_sourceHost": internal.EmptyRegex,
},
waitDuration,
tickDuration,
true,
)).
Assess("expected container log metadata is present for log generator daemonset", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
0,
map[string]string{
// TODO: uncomment this after v4 release
// or make it depend on the metadata provider
// "_collector": "kubernetes",
"namespace": internal.LogsGeneratorName,
"pod_labels_app": internal.LogsGeneratorName,
"container": internal.LogsGeneratorName,
"daemonset": internal.LogsGeneratorName,
"pod": fmt.Sprintf("%s%s", internal.LogsGeneratorName, internal.PodDaemonSetSuffixRegex),
"host": internal.NodeNameRegex,
"node": internal.NodeNameRegex,
"_sourceName": fmt.Sprintf(
"%s\\.%s%s\\.%s",
internal.LogsGeneratorNamespace,
internal.LogsGeneratorName,
internal.PodDaemonSetSuffixRegex,
internal.LogsGeneratorName,
),
"_sourceCategory": fmt.Sprintf(
"%s/%s/%s", // dashes instead of hyphens due to sourceCategoryReplaceDash
internal.ClusterName,
strings.ReplaceAll(internal.LogsGeneratorNamespace, "-", "/"),
strings.ReplaceAll(internal.LogsGeneratorName, "-", "/"), // this is the pod name prefix, in this case the DaemonSet name
),
"_sourceHost": internal.EmptyRegex,
},
waitDuration,
tickDuration,
true,
)).
Assess("logs from node systemd present", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
0,
map[string]string{
"cluster": "kubernetes",
"_sourceName": internal.NotUndefinedRegex,
"_sourceCategory": "kubernetes/system",
"_sourceHost": internal.NodeNameRegex,
},
waitDuration,
tickDuration,
true,
)).
Assess("logs from kubelet present", stepfuncs.WaitUntilExpectedAdditionalLogsPresent(
0,
map[string]string{
"cluster": "kubernetes",
"_sourceName": "k8s_kubelet",
"_sourceCategory": "kubernetes/kubelet",
"_sourceHost": internal.NodeNameRegex,
},
waitDuration,
tickDuration,
true,
)).
Feature()
}
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/helm_ot_routing_additional_partially_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build allversions
// +build allversions

package integration

import (
"testing"
)

func Test_Helm_Routing_Additional_Partially_OT(t *testing.T) {

installChecks := []featureCheck{
CheckOtelcolMetadataLogsInstall,
CheckOtelcolLogsCollectorInstall,
}

featInstall := GetInstallFeature(installChecks)

featLogs := GetLogsFeature()
featAdditionalLogs := GetAdditionalPartiallyLogsFeature()

featDeployMock := DeployAdditionalSumologicMock()
featDeleteMock := DeleteAdditionalSumologicMock()

testenv.Test(t, featInstall, featDeployMock, featLogs, featAdditionalLogs, featDeleteMock)
}
12 changes: 11 additions & 1 deletion tests/integration/internal/stepfuncs/assess_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func WaitUntilExpectedAdditionalLogsPresent(
expectedLogsMetadata map[string]string,
waitDuration time.Duration,
tickDuration time.Duration,
exactValue bool,
) features.Func {
return func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
newCtx := ctxopts.WithNamespace(ctx, internal.AdditionalSumologicMockNamespace)
Expand All @@ -428,14 +429,23 @@ func WaitUntilExpectedAdditionalLogsPresent(
log.ErrorS(err, "failed getting log counts from sumologic-mock")
return false
}
if logsCount < expectedLogsCount {
if !exactValue && logsCount < expectedLogsCount {
log.InfoS(
"received logs, less than expected",
"received", logsCount,
"expected", expectedLogsCount,
)
return false
}

if exactValue && logsCount != expectedLogsCount {
log.InfoS(
"received logs, not the same like expected",
"received", logsCount,
"expected", expectedLogsCount,
)
return false
}
log.InfoS(
"received enough logs",
"received", logsCount,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sumologic:
logs:
otelcol:
extraExporters:
sumologic/additional-sumologic-mock:
endpoint: http://sumologic-mock.additional-sumologic-mock:3000/receiver
routing:
table:
- exporter: sumologic/additional-sumologic-mock
statement: route() where resource.attributes["deployment"] == "logs-generator"

0 comments on commit 5f7b588

Please sign in to comment.