Skip to content

Commit

Permalink
Add e2e test for support bundle collection
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Wang <wshaoquan@vmware.com>
  • Loading branch information
wsquan171 committed Dec 1, 2022
1 parent 4ee1d27 commit 1477caa
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ci/jenkins/test-vmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ci/kind/test-e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/flowvisibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
141 changes: 141 additions & 0 deletions test/e2e/supportbundle_test.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1477caa

Please sign in to comment.