From d9493ffa1bc0f774eeeb153407889d3148829fe3 Mon Sep 17 00:00:00 2001 From: Alvaro Cabanas Date: Tue, 24 Jan 2023 10:54:22 +0100 Subject: [PATCH] Add NRIA_STAGING to the agent if region is set to Staging (#25) * Add NRIA_STAGING to the agent if region is set to Staging * Bump up the number of retries * change new defaults to infra platform needs Co-authored-by: Juan Manuel Perez --- .github/workflows/push-code.yml | 13 ++++++------- .github/workflows/selftest.yml | 30 ++++++++++++++---------------- action.yml | 4 ++-- internal/agent/agent.go | 8 ++++++++ internal/agent/agent_test.go | 1 + main.go | 4 ++-- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.github/workflows/push-code.yml b/.github/workflows/push-code.yml index 24061d5..c683b74 100644 --- a/.github/workflows/push-code.yml +++ b/.github/workflows/push-code.yml @@ -15,14 +15,13 @@ on: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GO_VERSION: '1.18' jobs: static-analysis: name: Run all static analysis checks - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: newrelic/newrelic-infra-checkers@v1 - name: Semgrep uses: returntocorp/semgrep-action@v1 @@ -30,7 +29,7 @@ jobs: auditOn: push - uses: actions/setup-go@v2 with: - go-version: ${{env.GO_VERSION}} + go-version-file: go.mod - name: golangci-lint uses: golangci/golangci-lint-action@v3 continue-on-error: ${{ github.event_name != 'pull_request' }} @@ -38,7 +37,7 @@ jobs: only-new-issues: true snyk: name: Run security checks via snyk - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Login to DockerHub @@ -53,7 +52,7 @@ jobs: test-nix: name: Run unit tests on *Nix - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Login to DockerHub @@ -64,6 +63,6 @@ jobs: - name: Install Go uses: actions/setup-go@v2 with: - go-version: ${{env.GO_VERSION}} + go-version-file: go.mod - name: Unit tests run: make test diff --git a/.github/workflows/selftest.yml b/.github/workflows/selftest.yml index 85fccfb..05caf87 100644 --- a/.github/workflows/selftest.yml +++ b/.github/workflows/selftest.yml @@ -16,12 +16,10 @@ jobs: runs-on: ubuntu-latest name: Test run the e2e test on powerdns local testdata steps: - - name: checkout-repository - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v1 + - uses: actions/checkout@v3 + - uses: actions/setup-go@v2 with: - go-version: 1.18 + go-version-file: go.mod - name: Run action for PowerDNS (exporter based) uses: ./ with: @@ -33,12 +31,10 @@ jobs: runs-on: ubuntu-latest name: Test run the e2e test on kafka local testdata steps: - - name: checkout-repository - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v1 + - uses: actions/checkout@v3 + - uses: actions/setup-go@v2 with: - go-version: 1.18 + go-version-file: go.mod - name: Run action for Kafka (sample based) uses: ./ with: @@ -47,21 +43,23 @@ jobs: api_key: ${{ secrets.API_KEY }} license_key: ${{ secrets.LICENSE_KEY }} test_local_k8s: - runs-on: ubuntu-latest + # To be able to use driver=none we have to provide a CRI that kubelet allows. + # Or we do the research to use `ubuntu-latest` or we should keep to an old version of Ubuntu and Kubernetes + # so this test can run using Docker as a CRI. + runs-on: ubuntu-20.04 name: Test run the e2e test on k8s local testdata steps: - name: checkout-repository - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v1 + uses: actions/checkout@v3 + - uses: actions/setup-go@v2 with: - go-version: 1.18 + go-version-file: go.mod - name: Setup Minikube uses: manusa/actions-setup-minikube@v2.4.2 with: minikube version: v1.20.0 kubernetes version: v1.21.4 - driver: none # required for nri-kubernetes, as metrics gathered for the host are tested as well + driver: none # required for nri-kubernetes, as metrics gathered for the host are tested as well - name: Setup Helm run: | chmod go-r /home/runner/.kube/config diff --git a/action.yml b/action.yml index 4acc06b..9bb4d68 100644 --- a/action.yml +++ b/action.yml @@ -16,11 +16,11 @@ inputs: retry_seconds: description: Number of seconds to wait after retrying a test required: false - default: "30" + default: "60" retry_attempts: description: Number of attempts a failed test can be retried required: false - default: "10" + default: "15" agent_enabled: description: Enable the agent execution required: false diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 8220a13..70dc88a 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -25,6 +25,7 @@ const ( dockerCompose = "docker-compose.yml" defConfigFile = "nri-config.yml" container = "agent" + regionStaging = "Staging" ) //go:embed resources/docker-compose.yml @@ -69,6 +70,13 @@ func NewAgent(settings e2e.Settings) *agent { a.ExtraEnvVars = settings.SpecDefinition().AgentExtensions.EnvVars } + if settings.Region() == regionStaging { + if a.ExtraEnvVars == nil { + a.ExtraEnvVars = map[string]string{} + } + a.ExtraEnvVars["NRIA_STAGING"] = "1" + } + return &a } diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index 03c2b5d..1b9246c 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -31,6 +31,7 @@ func TestAgent_SetUp(t *testing.T) { settings, err := e2e.NewSettings( e2e.SettingsWithSpecPath(filepath.Join(specPath, "spec_file.yml")), + e2e.SettingsWithRegion("Staging"), ) require.NoError(t, err) diff --git a/main.go b/main.go index e58e8a5..fe91d75 100644 --- a/main.go +++ b/main.go @@ -30,8 +30,8 @@ func processCliArgs() (string, string, bool, string, int, int, int, string, logr verboseMode := flag.Bool(flagVerboseMode, false, "If true the debug level is enabled") apiKey := flag.String(flagApiKey, "", "New Relic Api Key") accountID := flag.Int(flagAccountID, 0, "New Relic accountID to be used") - retryAttempts := flag.Int(flagRetryAttempts, 10, "Number of attempts to retry a test") - retrySeconds := flag.Int(flagRetrySecons, 30, "Number of seconds before retrying a test") + retryAttempts := flag.Int(flagRetryAttempts, 15, "Number of attempts to retry a test") + retrySeconds := flag.Int(flagRetrySecons, 60, "Number of seconds before retrying a test") commitSha := flag.String(flagCommitSha, "", "Current commit sha") region := flag.String(flagRegion, "", "Current commit sha") flag.Parse()