From 4a6cb76243704f96dfc02ff312b57e4d0ced0d84 Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Tue, 20 Jun 2023 17:01:24 +0300 Subject: [PATCH] connectivity: Add checks for drops due to missed tail calls The test case is protected with --include-upgrade-test, as it's only relevant in the context of Cilium upgrades. Signed-off-by: Martynas Pumputis --- connectivity/suite.go | 2 ++ connectivity/tests/errors.go | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/connectivity/suite.go b/connectivity/suite.go index c25688c200..079a26f085 100644 --- a/connectivity/suite.go +++ b/connectivity/suite.go @@ -217,6 +217,8 @@ func Run(ctx context.Context, ct *check.ConnectivityTest, addExtraTests func(*ch // include --include-upgrade-tests" return ct.Run(ctx) } + + ct.NewTest("no-missed-tail-calls").WithScenarios(tests.NoMissedTailCalls()) } // Run all tests without any policies in place. diff --git a/connectivity/tests/errors.go b/connectivity/tests/errors.go index 779a3958d1..1b9f1bc89e 100644 --- a/connectivity/tests/errors.go +++ b/connectivity/tests/errors.go @@ -5,10 +5,12 @@ package tests import ( "context" + "strconv" "strings" "time" "github.com/cilium/cilium-cli/connectivity/check" + "github.com/cilium/cilium-cli/defaults" ) // NoErrorsInLogs checks whether there are no error messages in cilium-agent @@ -39,6 +41,48 @@ func (n *noErrorsInLogs) Run(ctx context.Context, t *check.Test) { } +// NoMissedTailCalls checks whether there were no drops due to missed (BPF) +// tail calls. +func NoMissedTailCalls() check.Scenario { + return &noMissedTailCalls{} +} + +type noMissedTailCalls struct{} + +func (n *noMissedTailCalls) Name() string { + return "no-missed-tail-calls" +} + +func (n *noMissedTailCalls) Run(ctx context.Context, t *check.Test) { + ct := t.Context() + cmd := []string{ + "/bin/sh", "-c", + "cilium metrics list -o json | jq '.[] | select( .name == \"cilium_drop_count_total\" and .labels.reason == \"Missed tail call\" ).value'", + } + + for _, pod := range ct.CiliumPods() { + pod := pod + stdout, err := pod.K8sClient.ExecInPod(ctx, pod.Pod.Namespace, pod.Pod.Name, defaults.AgentContainerName, cmd) + if err != nil { + t.Fatalf("Error fetching missed tail call drop counts: %s", err) + } + countStr := stdout.String() + if countStr == "" { + return + } + + count, err := strconv.Atoi(countStr) + if err != nil { + t.Fatalf("Failed to convert missed tail call drops %q to int: %s", countStr, err) + } + + if count != 0 { + t.Fatalf("Detected drops due to missed tail calls: %d", count) + } + } + +} + func checkErrorsInLogs(logs string, t *check.Test) { uniqueFailures := make(map[string]int) for _, msg := range strings.Split(logs, "\n") {