Skip to content

Commit

Permalink
test(integration): add tailing sidecar test
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Rosiek <[email protected]>
  • Loading branch information
Dominik Rosiek committed Jul 12, 2023
1 parent 7e9bc97 commit 067c3f6
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 12 deletions.
57 changes: 45 additions & 12 deletions tests/integration/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ import (
type MetricsCollector string

const (
tickDuration = 3 * time.Second
waitDuration = 1 * time.Minute
expectedEventCount uint = 50 // number determined experimentally
logsGeneratorCount uint = 1000
logRecords = 4 // number of log records in single loop, see: tests/integration/yamls/pod_multiline_long_lines.yaml
logLoops = 500 // number of loops in which logs are generated, see: tests/integration/yamls/pod_multiline_long_lines.yaml
multilineLogCount uint = logRecords * logLoops
tracesPerExporter uint = 5 // number of traces generated per exporter
spansPerTrace uint = 2
Prometheus MetricsCollector = "prometheus"
Otelcol MetricsCollector = "otelcol"
Fluentd MetricsCollector = "fluentd"
tickDuration = 3 * time.Second
waitDuration = 1 * time.Minute
expectedEventCount uint = 50 // number determined experimentally
logsGeneratorCount uint = 1000
logRecords = 4 // number of log records in single loop, see: tests/integration/yamls/pod_multiline_long_lines.yaml
logLoops = 500 // number of loops in which logs are generated, see: tests/integration/yamls/pod_multiline_long_lines.yaml
multilineLogCount uint = logRecords * logLoops
tracesPerExporter uint = 5 // number of traces generated per exporter
spansPerTrace uint = 2
Prometheus MetricsCollector = "prometheus"
Otelcol MetricsCollector = "otelcol"
Fluentd MetricsCollector = "fluentd"
TailingSidecarCount uint = 150 // number of logs generated by tailing sidecar test (50 * 3), see: tests/inegration/yamls/tailing-sidecar-test.yaml
)

func GetMetricsFeature(expectedMetrics []string, metricsCollector MetricsCollector) features.Feature {
Expand Down Expand Up @@ -482,6 +483,25 @@ func GetTracesFeature() features.Feature {
Feature()
}

func GetTailingSidecarFeature() features.Feature {
return features.New("tailing sidecar test").
Setup(stepfuncs.KubectlApplyFOpt(internal.TailingSidecarTest, internal.TailingSidecarTestNamespace)).
Assess("tailing sidecar test logs present", stepfuncs.WaitUntilExpectedLogsPresent(
TailingSidecarCount,
map[string]string{
"namespace": internal.TailingSidecarTestNamespace,
"deployment": internal.TailingSidecarTestDeploymentName,
},
internal.ReceiverMockNamespace,
internal.ReceiverMockServiceName,
internal.ReceiverMockServicePort,
waitDuration,
tickDuration,
)).
Teardown(stepfuncs.KubectlDeleteFOpt(internal.TailingSidecarTest, internal.TailingSidecarTestNamespace)).
Feature()
}

type featureCheck func(*features.FeatureBuilder) *features.FeatureBuilder

func GetInstallFeature(installChecks []featureCheck) features.Feature {
Expand Down Expand Up @@ -877,3 +897,16 @@ func CheckFluentdEventsInstall(builder *features.FeatureBuilder) *features.Featu
return ctx
})
}

func CheckTailingSidecarOperatorInstall(builder *features.FeatureBuilder) *features.FeatureBuilder {
return builder.
Assess("tailing sidecar deployment is ready",
stepfuncs.WaitUntilDeploymentIsReady(
waitDuration,
tickDuration,
stepfuncs.WithNameF(
stepfuncs.ReleaseFormatter("%s-tailing-sidecar-operator"),
),
),
)
}
21 changes: 21 additions & 0 deletions tests/integration/helm_tailing_sidecar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build onlylatest
// +build onlylatest

package integration

import (
"testing"
)

func Test_Helm_Tailing_Sidecar(t *testing.T) {
installChecks := []featureCheck{
CheckOtelcolMetadataLogsInstall,
CheckTailingSidecarOperatorInstall,
}

featInstall := GetInstallFeature(installChecks)

featTailingSidecarTest := GetTailingSidecarFeature()

testenv.Test(t, featInstall, featTailingSidecarTest)
}
4 changes: 4 additions & 0 deletions tests/integration/internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const (
MultilineLogsPodName = "multiline-logs-generator"
MultilineLogsGenerator = "yamls/multiline-logs-generator.yaml"

TailingSidecarTestNamespace = "tailing-sidecar"
TailingSidecarTest = "yamls/tailing-sidecar-test.yaml"
TailingSidecarTestDeploymentName = "test-tailing-sidecar-operator"

// useful regular expressions for matching metadata
PodDeploymentSuffixRegex = "-[a-z0-9]{9,10}-[a-z0-9]{4,5}" // the Pod suffix for Deployments
PodDaemonSetSuffixRegex = "-[a-z0-9]{4,5}"
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/values/values_helm_tailing_sidecar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sumologic:
events:
enabled: false
metrics:
enabled: false
traces:
enabled: false

tailing-sidecar-operator:
enabled: true
76 changes: 76 additions & 0 deletions tests/integration/yamls/tailing-sidecar-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: tailing-sidecar
---
apiVersion: tailing-sidecar.sumologic.com/v1
kind: TailingSidecarConfig
metadata:
name: test-tailing-sidecar-operator
namespace: tailing-sidecar
spec:
podSelector:
matchLabels:
test-tailing-sidecar: "true"
configs:
test-sidecar:
volumeMount:
name: varlogconfig
mountPath: /varconfig/log
path: /varconfig/log/example2.log
annotations:
sourceCategory: test-sidecar
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-tailing-sidecar-operator
namespace: tailing-sidecar
labels:
app: test-tailing-sidecar-operator
spec:
replicas: 1
selector:
matchLabels:
tailing-sidecar: "true"
test-tailing-sidecar: "true"
app: test-tailing-sidecar-operator
template:
metadata:
name: test-tailing-sidecar-operator
namespace: tailing-sidecar
annotations:
tailing-sidecar: varlog:/var/log/example0.log;named-container:varlog:/var/log/example1.log
labels:
tailing-sidecar: "true"
test-tailing-sidecar: "true"
app: test-tailing-sidecar-operator
spec:
containers:
- name: count
image: bash
args:
- /usr/local/bin/bash
- -c
- >
i=0; for i in {1..50}; do
echo "example0: $i $(date)" >> /var/log/example0.log;
echo "example1: $i $(date)" >> /var/log/example1.log;
echo "example2: $i $(date)" >> /varconfig/log/example2.log;
sleep 1;
done; while true; do
sleep 1;
done;
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlogconfig
mountPath: /varconfig/log
volumes:
- name: varlog
emptyDir: {}
- name: varlogconfig
emptyDir: {}
securityContext:
runAsUser: 1000

0 comments on commit 067c3f6

Please sign in to comment.