From 365450625287fe635dd5d702c9306d142985fac1 Mon Sep 17 00:00:00 2001 From: Shawn Wang Date: Wed, 30 Nov 2022 03:34:40 -0800 Subject: [PATCH] Add e2e test for support bundle collection Signed-off-by: Shawn Wang --- ci/jenkins/test-vmc.sh | 2 +- ci/kind/test-e2e-kind.sh | 2 +- test/e2e/flowvisibility_test.go | 6 ++ test/e2e/supportbundle_test.go | 141 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 test/e2e/supportbundle_test.go diff --git a/ci/jenkins/test-vmc.sh b/ci/jenkins/test-vmc.sh index a1005808c..3d10c63b4 100644 --- a/ci/jenkins/test-vmc.sh +++ b/ci/jenkins/test-vmc.sh @@ -337,7 +337,7 @@ function deliver_antrea { control_plane_ip="$(kubectl get nodes -o wide --no-headers=true | awk -v role="$CONTROL_PLANE_NODE_ROLE" '$3 ~ role {print $6}')" - ${GIT_CHECKOUT_DIR}/hack/generate-manifest.sh --ch-size 100Mi --ch-monitor-threshold 0.1 > ${GIT_CHECKOUT_DIR}/build/yamls/flow-visibility.yml + ${GIT_CHECKOUT_DIR}/hack/generate-manifest.sh --ch-size 100Mi --ch-monitor-threshold 0.1 --theia-manager > ${GIT_CHECKOUT_DIR}/build/yamls/flow-visibility.yml ${GIT_CHECKOUT_DIR}/hack/generate-manifest.sh --no-grafana --spark-operator --theia-manager > ${GIT_CHECKOUT_DIR}/build/yamls/flow-visibility-with-spark.yml ${GIT_CHECKOUT_DIR}/hack/generate-manifest.sh --no-grafana --theia-manager > ${GIT_CHECKOUT_DIR}/build/yamls/flow-visibility-ch-only.yml diff --git a/ci/kind/test-e2e-kind.sh b/ci/kind/test-e2e-kind.sh index 2b47abf16..0c0639bd6 100755 --- a/ci/kind/test-e2e-kind.sh +++ b/ci/kind/test-e2e-kind.sh @@ -38,7 +38,7 @@ function print_usage { TESTBED_CMD=$(dirname $0)"/kind-setup.sh" YML_DIR=$(dirname $0)"/../../build/yamls" -FLOW_VISIBILITY_CMD=$(dirname $0)"/../../hack/generate-manifest.sh --ch-size 100Mi --ch-monitor-threshold 0.1" +FLOW_VISIBILITY_CMD=$(dirname $0)"/../../hack/generate-manifest.sh --ch-size 100Mi --ch-monitor-threshold 0.1 --theia-manager" FLOW_VISIBILITY_WITH_SPARK_CMD=$(dirname $0)"/../../hack/generate-manifest.sh --no-grafana --spark-operator --theia-manager" FLOW_VISIBILITY_CH_ONLY_CMD=$(dirname $0)"/../../hack/generate-manifest.sh --no-grafana --theia-manager" CH_OPERATOR_YML=$(dirname $0)"/../../build/charts/theia/crds/clickhouse-operator-install-bundle.yaml" diff --git a/test/e2e/flowvisibility_test.go b/test/e2e/flowvisibility_test.go index 2341a3ce9..02aaa4f20 100644 --- a/test/e2e/flowvisibility_test.go +++ b/test/e2e/flowvisibility_test.go @@ -518,6 +518,12 @@ func testHelper(t *testing.T, data *TestData, podAIPs, podBIPs, podCIPs, podDIPs } checkClickHouseMonitor(t, data, isIPv6, flow) }) + + // SupportBundle tests collection of log bundle via Theia CLI is successful + // and contains log files from common components in the test setup. + t.Run("SupportBundle", func(t *testing.T) { + testSupportBundleCollection(t, data) + }) } func checkGrafanaQueryResults(t *testing.T, data *TestData, dashboardName, dashboardUid string, queryList *[]query) { diff --git a/test/e2e/supportbundle_test.go b/test/e2e/supportbundle_test.go new file mode 100644 index 000000000..2b3bb8699 --- /dev/null +++ b/test/e2e/supportbundle_test.go @@ -0,0 +1,141 @@ +// Copyright 2022 Antrea Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "fmt" + "regexp" + "strings" + "testing" + + log "github.com/sirupsen/logrus" + "github.com/stretchr/testify/require" +) + +const ( + bundleCollectCmd = "./theia supportbundle -d ./support-bundle" + bundleExpandCmd = "tar -xvzf ./support-bundle/theia-support-bundle.tar.gz -C ./support-bundle" + bundleDeleteCmd = "rm -rf ./support-bundle" +) + +type supportBundleTestCase struct { + filePath string + filenames []string +} + +var supportBundleTestCases = []supportBundleTestCase{ + { + filePath: "clickhouse-server/chi-clickhouse-clickhouse-[a-z0-9-]+", + filenames: []string{ + "clickhouse-server.err.log", + "clickhouse-server.log", + }, + }, + { + filePath: "flow-aggregator/flow-aggregator-[a-z0-9-]+", + filenames: []string{ + "flow-aggregator.flow-aggregator-[a-z0-9-]+.root.log.(INFO|WARNING|ERROR|FATAL).[0-9.-]+", + }, + }, + { + filePath: "grafana/grafana-[a-z0-9-]+", + filenames: []string{ + "grafana.log", + }, + }, + { + filePath: "theia-manager", + filenames: []string{ + "theia-manager.theia-manager-[a-z0-9-]+.root.log.(INFO|WARNING|ERROR|FATAL).[0-9.-]+", + }, + }, + { + filePath: "zookeeper/zookeeper-[a-z0-9-]+", + filenames: []string{ + "zookeeper-[a-z0-9-]+.log", + }, + }, +} + +func testSupportBundleCollection(t *testing.T, data *TestData) { + defer cleanupSupportBundle(t, data) + + log.Infof("Collecting support bundle") + filesCollected, err := collectBundle(t, data) + require.NoError(t, err) + log.Infof("Support bundle collected") + + filePathRegexMap := parseFilePathRegex("logs", supportBundleTestCases) + for _, file := range filesCollected { + for filePathRegex := range filePathRegexMap { + matchResult := filePathRegex.MatchString(file) + if matchResult { + filePathRegexMap[filePathRegex] = true + break + } + } + } + + filesNotMatched := make([]string, 0) + for filePathRegex, matched := range filePathRegexMap { + if !matched { + filesNotMatched = append(filesNotMatched, filePathRegex.String()) + } + } + if len(filesNotMatched) > 0 { + err = fmt.Errorf("expected files not found in support bundle: %s", filesNotMatched) + failOnError(err, t, data) + } +} + +func collectBundle(t *testing.T, data *TestData) ([]string, error) { + files := make([]string, 0) + cmd := "chmod +x ./theia" + rc, stdout, stderr, err := data.RunCommandOnNode(controlPlaneNodeName(), cmd) + if err != nil || rc != 0 { + return files, fmt.Errorf("error when running %s from %s: %v\nstdout:%s\nstderr:%s", cmd, controlPlaneNodeName(), err, stdout, stderr) + } + rc, stdout, stderr, err = data.RunCommandOnNode(controlPlaneNodeName(), bundleCollectCmd) + if err != nil || rc != 0 { + return files, fmt.Errorf("error when running %s from %s: %v\nstdout:%s\nstderr:%s", cmd, controlPlaneNodeName(), err, stdout, stderr) + } + rc, stdout, stderr, err = data.RunCommandOnNode(controlPlaneNodeName(), bundleExpandCmd) + if err != nil || rc != 0 { + return files, fmt.Errorf("error when running %s from %s: %v\nstdout:%s\nstderr:%s", cmd, controlPlaneNodeName(), err, stdout, stderr) + } + log.Infof("Files expanded:\n%s", stdout) + stdout = strings.TrimSuffix(stdout, "\n") + files = strings.Split(stdout, "\n") + return files, nil +} + +func cleanupSupportBundle(t *testing.T, data *TestData) { + rc, _, stderr, err := data.RunCommandOnNode(controlPlaneNodeName(), bundleDeleteCmd) + if err != nil || rc != 0 { + log.Errorf("Failed to cleanup support bundle: %v\nstderr: %s", err, stderr) + } +} + +func parseFilePathRegex(baseDir string, testcases []supportBundleTestCase) map[*regexp.Regexp]bool { + fileChecker := make(map[*regexp.Regexp]bool) + for _, tc := range testcases { + dir := baseDir + "/" + tc.filePath + for _, filename := range tc.filenames { + re := regexp.MustCompile(fmt.Sprintf("^%s/%s$", dir, filename)) + fileChecker[re] = false + } + } + return fileChecker +}