From d57af0e81b9552e1e71fb944c75d4334457b6a01 Mon Sep 17 00:00:00 2001 From: Marco Braga Date: Fri, 8 Mar 2024 00:06:27 -0300 Subject: [PATCH] ci: e2e for opct adm parsers Introduce new CI/GHA jobs to test new opct adm commands. --- .github/workflows/go.yaml | 155 +++++++++++++++++++++++++++++++------- 1 file changed, 128 insertions(+), 27 deletions(-) diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index cc1476cc..974ac02d 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -9,35 +9,47 @@ on: tags: - '*' +env: + GO_VERSION: 1.22 + ACTION_IMAGE_GOLANGCI_LINT: golangci/golangci-lint-action@v4 + GOLANGCI_LINT_VERSION: v6.0.1 + ACTION_IMAGE_CHECKOUT: actions/checkout@v4 + ACTION_IMAGE_SETUP_GO: actions/setup-go@v5 + ACTION_IMAGE_SETUP_GO_FASTER: WillAbides/setup-go-faster@v1.14.0 + ACTION_IMAGE_STATICCHECK: dominikh/staticcheck-action@v1.3.0 + STATIC_CHECK_VERSION: 2023.1.7 + ACTION_IMAGE_UPLOAD_ARTIFACT: actions/upload-artifact@v4 + ACTION_IMAGE_DOWNLOAD_ARTIFACT: actions/download-artifact@v4 + jobs: go-lint: name: go-lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: ${{ env.ACTION_IMAGE_CHECKOUT }} + - uses: ${{ env.ACTION_IMAGE_SETUP_GO }} with: - go-version: '1.22' + go-version: ${{ env.GO_VERSION }} cache: false # https://github.com/golangci/golangci-lint-action - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: ${{ env.ACTION_IMAGE_GOLANGCI_LINT }} with: - version: v1.55.2 + version: ${{ env.GOLANGCI_LINT_VERSION }} args: --timeout=10m go-static: name: "go-staticcheck" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: WillAbides/setup-go-faster@v1.14.0 + - uses: ${{ env.ACTION_IMAGE_CHECKOUT }} + - uses: ${{ env.ACTION_IMAGE_SETUP_GO_FASTER }} with: - go-version: '1.22' + go-version: ${{ env.GO_VERSION }} - name: Run static code analysis - uses: dominikh/staticcheck-action@v1.3.0 + uses: ${{ env.ACTION_IMAGE_STATICCHECK }} with: - version: "2023.1.7" + version: "${{ env.STATIC_CHECK_VERSION }}" install-go: false go-test: @@ -47,10 +59,10 @@ jobs: - go-lint - go-static steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: ${{ env.ACTION_IMAGE_CHECKOUT }} + - uses: ${{ env.ACTION_IMAGE_SETUP_GO }} with: - go-version: '1.22' + go-version: ${{ env.GO_VERSION }} - name: Run unit tests run: make test @@ -61,10 +73,10 @@ jobs: - go-lint - go-static steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: ${{ env.ACTION_IMAGE_CHECKOUT }} + - uses: ${{ env.ACTION_IMAGE_SETUP_GO }} with: - go-version: '1.22' + go-version: ${{ env.GO_VERSION }} - name: Run go vet run: make vet @@ -75,13 +87,10 @@ jobs: - go-test - go-vet steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v4 + - uses: ${{ env.ACTION_IMAGE_CHECKOUT }} + - uses: ${{ env.ACTION_IMAGE_SETUP_GO }} with: - go-version: 1.22 + go-version: ${{ env.GO_VERSION }} - name: Install dependencies run: | @@ -97,7 +106,7 @@ jobs: make build-${OS_ARCH} - name: Save artifacts (OS=linux-amd64) - uses: actions/upload-artifact@v3 + uses: ${{ env.ACTION_IMAGE_UPLOAD_ARTIFACT }} with: name: opct-linux-amd64 path: | @@ -111,19 +120,19 @@ jobs: make build-${OS_ARCH} - name: Save artifacts (OS=darwin-arm64) - uses: actions/upload-artifact@v3 + uses: ${{ env.ACTION_IMAGE_UPLOAD_ARTIFACT }} with: name: opct-darwin-arm64 path: | build/opct-* - cmd-report: - name: "run-report" + e2e-cmd_report: + name: "e2e-cmd_report" runs-on: ubuntu-latest needs: - build steps: - name: Download artifacts - uses: actions/download-artifact@v3 + uses: ${{ env.ACTION_IMAGE_DOWNLOAD_ARTIFACT }} with: name: opct-linux-amd64 path: /tmp/build/ @@ -142,3 +151,95 @@ jobs: echo "> Running OPCT report:" ${CUSTOM_BUILD_PATH} report /tmp/result.tar.gz + + e2e-cmd_adm-parse-etcd-logs: + name: "e2e-cmd_adm-parse-etcd-logs" + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download artifacts + uses: ${{ env.ACTION_IMAGE_DOWNLOAD_ARTIFACT }} + with: + name: opct-linux-amd64 + path: /tmp/build/ + + - name: Preparing testdata + env: + RESULT_ARTIFACT_URL: "https://openshift-provider-certification.s3.us-west-2.amazonaws.com" + RESULT_ARTIFACT_VERSION: "testdata/must-gather-etcd-logs.tar.gz" + CUSTOM_BUILD_PATH: /tmp/build/opct-linux-amd64 + LOCAL_TEST_DATA: /tmp/must-gather.tar.gz + LOCAL_TEST_DATA_DIR: /tmp/must-gather + run: | + echo "> Downloading sample artifact: ${RESULT_ARTIFACT_URL}/${RESULT_ARTIFACT_VERSION}" + wget -qO ${LOCAL_TEST_DATA} "${RESULT_ARTIFACT_URL}/${RESULT_ARTIFACT_VERSION}" + + echo "> Setting run permissions to OPCT:" + chmod u+x ${CUSTOM_BUILD_PATH} + + echo "> Extracting testdata:" + mkdir ${LOCAL_TEST_DATA_DIR} + tar xfz ${LOCAL_TEST_DATA} -C ${LOCAL_TEST_DATA_DIR} + + - name: "e2e stdin reader: cat | opct adm parse-etcd-logs" + env: + CUSTOM_BUILD_PATH: /tmp/build/opct-linux-amd64 + LOCAL_TEST_DATA_DIR: /tmp/must-gather + run: | + cat ${LOCAL_TEST_DATA_DIR}/*/*/namespaces/openshift-etcd/pods/*/etcd/etcd/logs/*.log | \ + ${CUSTOM_BUILD_PATH} adm parse-etcd-logs + + - name: "e2e must-gather dir: opct adm parse-etcd-logs " + env: + CUSTOM_BUILD_PATH: /tmp/build/opct-linux-amd64 + LOCAL_TEST_DATA_DIR: /tmp/must-gather + run: | + ${CUSTOM_BUILD_PATH} adm parse-etcd-logs ${LOCAL_TEST_DATA_DIR} + + - name: "e2e aggregate by hour: opct adm parse-etcd-logs --aggregator hour " + env: + CUSTOM_BUILD_PATH: /tmp/build/opct-linux-amd64 + LOCAL_TEST_DATA_DIR: /tmp/must-gather + run: | + ${CUSTOM_BUILD_PATH} adm parse-etcd-logs --aggregator hour ${LOCAL_TEST_DATA_DIR} + + - name: "e2e ignore error counters: opct adm parse-etcd-logs --skip-error-counter=true " + env: + CUSTOM_BUILD_PATH: /tmp/build/opct-linux-amd64 + LOCAL_TEST_DATA_DIR: /tmp/must-gather + run: | + ${CUSTOM_BUILD_PATH} adm parse-etcd-logs --skip-error-counter=true ${LOCAL_TEST_DATA_DIR} + + e2e-cmd_adm-parse-metrics: + name: "e2e-cmd_adm-parse-metrics" + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download artifacts + uses: ${{ env.ACTION_IMAGE_DOWNLOAD_ARTIFACT }} + with: + name: opct-linux-amd64 + path: /tmp/build/ + + - name: Preparing testdata + env: + RESULT_ARTIFACT_URL: "https://openshift-provider-certification.s3.us-west-2.amazonaws.com" + RESULT_ARTIFACT_VERSION: "testdata/ci-external-aws-ccm_1757495441294888960-artifacts_must-gather-metrics.tar.xz" + CUSTOM_BUILD_PATH: /tmp/build/opct-linux-amd64 + LOCAL_TEST_DATA: /tmp/opct-metrics.tar.xz + run: | + echo "> Downloading sample artifact: ${RESULT_ARTIFACT_URL}/${RESULT_ARTIFACT_VERSION}" + wget -qO ${LOCAL_TEST_DATA} "${RESULT_ARTIFACT_URL}/${RESULT_ARTIFACT_VERSION}" + + echo "> Setting run permissions to OPCT:" + chmod u+x ${CUSTOM_BUILD_PATH} + + - name: "e2e parse metrics: opct adm parse-etcd-logs " + env: + CUSTOM_BUILD_PATH: /tmp/build/opct-linux-amd64 + LOCAL_TEST_DATA: /tmp/opct-metrics.tar.xz + run: | + ${CUSTOM_BUILD_PATH} adm parse-metrics --input ${LOCAL_TEST_DATA} --output /tmp/metrics + tree /tmp/metrics