Skip to content

Commit

Permalink
verify k8s version before checking local service traces
Browse files Browse the repository at this point in the history
  • Loading branch information
tbavelier committed Jan 10, 2025
1 parent 8ee16e0 commit c3c50d1
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions test/e2e/tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,33 @@ func VerifyAgentPodLogs(c *assert.CollectT, collectorOutput string) {
assert.True(c, tailedIntegrations >= totalIntegrations*80/100, "Expected at least 80%% of integrations to be tailed, got %d/%d", tailedIntegrations, totalIntegrations)
}

// isInternalTrafficPolicySupported checks if the internalTrafficPolicy field is supported in the current Kubernetes version.
// This is accomplished by checking if the Kubernetes minor version is >= 22.
func isInternalTrafficPolicySupported() bool {
k8sVersion := common.K8sVersion
splits := strings.Split(k8sVersion, ".")
// Avoid panics by checking if the version is in the expected format (X.Y)
if len(splits) < 2 {
return false
}
minorVersion, err := strconv.Atoi(splits[1])
if err != nil {
return false
}
return minorVersion >= 22
}

func VerifyAgentTraces(c *assert.CollectT, collectorOutput string) {
apmAgentJson := common.ParseCollectorJson(collectorOutput)
// The order of services in the Agent JSON output is not guaranteed.
// We use a map to assert that we have received traces for all expected services.
expectedServices := map[string]bool{
"e2e-test-apm-hostip": true,
"e2e-test-apm-socket": true,
"e2e-test-apm-agent-service": true,
"e2e-test-apm-hostip": true,
"e2e-test-apm-socket": true,
}
// On Kubernetes >= 1.22, the node Agent k8s service is created since internalTrafficPolicy is supported.
if isInternalTrafficPolicySupported() {
expectedServices["e2e-test-apm-agent-service"] = true
}
// Track found services
foundServices := map[string]bool{}
Expand Down

0 comments on commit c3c50d1

Please sign in to comment.