From ab1703d463fce1efa95314d6eaebde69c55c37e1 Mon Sep 17 00:00:00 2001 From: "Mateusz \"mat\" Rumian" <58699800+mat-rumian@users.noreply.github.com> Date: Thu, 19 Nov 2020 09:47:37 +0100 Subject: [PATCH] Config update (#289) CircleCI configuration update and linter fixes --- .circleci/config.yml | 279 ++++++++++++++++-- .../tailsamplingprocessor/config_test.go | 20 +- .../sampling/cascading.go | 8 +- .../sampling/span_properties_filter.go | 2 +- 4 files changed, 262 insertions(+), 47 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4e03bfb6f54d..8acc4afd680b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,5 @@ version: 2.1 + parameters: run-build-publish: type: boolean @@ -10,6 +11,9 @@ parameters: type: string default: "" +orbs: + win: circleci/windows@2.4.0 + executors: golang: docker: @@ -19,6 +23,34 @@ executors: image: ubuntu-1604:201903-01 commands: + verify_dist_files_exist: + parameters: + files: + type: string + default: | + bin/otelcontribcol_darwin_amd64 + bin/otelcontribcol_linux_arm64 + bin/otelcontribcol_linux_amd64 + bin/otelcontribcol_windows_amd64.exe + dist/otel-contrib-collector-*.arm64.rpm + dist/otel-contrib-collector_*_amd64.deb + dist/otel-contrib-collector-*.x86_64.rpm + dist/otel-contrib-collector_*_arm64.deb + dist/otel-contrib-collector-*amd64.msi + steps: + - run: + name: Check if distribution files exist + command: | + files="<< parameters.files >>" + for f in $files; do + if [[ ! -f $f ]] + then + echo "$f does not exist." + exit 1 + fi + done + + setup: steps: - checkout @@ -59,7 +91,7 @@ commands: save_module_cache: steps: - save_cache: - key: cimg-go-pkg-mod-{{ checksum "go.sum" }}-v4 + key: cimg-go-pkg-mod-{{ arch }}-{{ checksum "go.sum" }}-v4 paths: - "/home/circleci/go/pkg/mod" @@ -70,7 +102,7 @@ commands: command: mkdir -p ~/go/pkg/mod - restore_cache: # restores saved cache if no changes are detected since last run keys: - - cimg-go-pkg-mod-{{ checksum "go.sum" }}-v4 + - cimg-go-pkg-mod-{{ arch }}-{{ checksum "go.sum" }}-v4 publish_docker_images: parameters: @@ -103,12 +135,12 @@ workflows: - setup: requires: - checkout-commit - - build: + - cross-compile: requires: - setup - run-stability-tests: requires: - - build + - cross-compile - publish-dev: requires: - run-stability-tests @@ -116,17 +148,15 @@ workflows: build-publish: when: << pipeline.parameters.run-build-publish >> jobs: + - windows-test: + filters: + tags: + only: /.*/ - setup: filters: tags: only: /.*/ -# - lint: -# requires: -# - setup -# filters: -# tags: -# only: /.*/ - - build: + - lint: requires: - setup filters: @@ -144,23 +174,84 @@ workflows: filters: tags: only: /.*/ + - loadtest: + requires: + - cross-compile + filters: + tags: + only: /.*/ - unit-tests: requires: - setup filters: tags: only: /.*/ + - windows-msi: + requires: + - cross-compile + filters: + tags: + only: /.*/ + - publish-check: + requires: + - lint + - unit-tests + - integration-tests + - cross-compile + - loadtest + - windows-test + - windows-msi + - deb-package + - rpm-package - publish-stable: requires: -# - lint + - lint + - unit-tests + - integration-tests + - cross-compile + - loadtest + - windows-test + - windows-msi + - deb-package + - rpm-package + filters: + branches: + ignore: /.*/ + tags: + only: /.*/ + - spawn-stability-tests-job: + requires: + - lint - unit-tests - - build + - loadtest + - windows-test + - integration-tests - cross-compile filters: branches: + only: /master|release\/.+/ + tags: ignore: /.*/ + - integration-tests: + filters: + tags: + only: /.*/ + - build-package: + name: deb-package + package_type: deb + requires: + - cross-compile + filters: tags: - only: /^v[0-9].[0-9]+.[0-9]+.*/ + only: /.*/ + - build-package: + name: rpm-package + package_type: rpm + requires: + - cross-compile + filters: + tags: + only: /.*/ jobs: @@ -173,27 +264,16 @@ jobs: paths: - project - go/bin -# lint: -# executor: golang -# steps: -# - restore_workspace -# - run: -# name: Lint -# command: make -j8 for-all-target TARGET=lint -# - run: -# name: Checks -# command: make -j4 checklicense impi misspell - - build: + lint: executor: golang steps: - restore_workspace - run: - name: Build collector for linux_amd64 - command: make otelcontribcol - - persist_to_workspace: - root: ~/ - paths: project/bin + name: Lint + command: make -j2 for-all-target TARGET=lint + - run: + name: Checks + command: make -j4 checklicense impi misspell build-examples: docker: @@ -213,6 +293,9 @@ jobs: - run: name: Build collector for all archs command: grep ^otelcontribcol-all-sys Makefile|fmt -w 1|tail -n +2|circleci tests split|xargs make + - persist_to_workspace: + root: ~/ + paths: project/bin unit-tests: executor: golang @@ -239,13 +322,71 @@ jobs: path: testbed/tests/results - store_test_results: path: testbed/tests/results/junit - - github_issue_generator + + windows-test: + executor: + name: win/default + shell: powershell.exe + environment: + GOPATH=~/go + steps: + - checkout + - restore_module_cache + - run: + name: Upgrade golang + command: | + choco upgrade golang --version=1.15 + refreshenv + - run: + name: Unit tests + command: (Get-Childitem -Include go.mod -Recurse) | ForEach-Object { cd (Split-Path $_ -Parent); go test ./...; if ($LastExitCode -gt 0) { exit $LastExitCode } } + - save_module_cache + + windows-msi: + executor: + name: win/default + shell: powershell.exe + steps: + - attach_to_workspace + - run: + command: mkdir -p dist + - run: + name: Install Wix Toolset + command: .\internal\buildscripts\packaging\msi\make.ps1 Install-Tools + - run: + name: Build MSI + command: | + $Version = if ($env:CIRCLE_TAG -match '^v(\d+\.\d+\.\d+)') { $Matches[1] } else { "0.0.1" } + .\internal\buildscripts\packaging\msi\make.ps1 New-MSI -Version $Version + - run: + name: Validate MSI + command: .\internal\buildscripts\packaging\msi\make.ps1 Confirm-MSI + - persist_to_workspace: + root: ~/ + paths: project/dist/*.msi + + publish-check: + docker: + - image: cimg/go:1.14 + steps: + - attach_to_workspace + - setup_remote_docker + - verify_dist_files_exist + - run: + name: Check passed + command: echo "publish check passed meaning release CI jobs should work as expected" + when: on_success + - run: + name: Check failed + command: echo "publish check failed. This means release CI jobs will likely fail as well" + when: on_fail publish-stable: docker: - image: cimg/go:1.14 steps: - restore_workspace + - verify_dist_files_exist - setup_remote_docker - publish_docker_images: repo: opentelemetry-collector @@ -261,6 +402,12 @@ jobs: executor: golang steps: - restore_workspace + - verify_dist_files_exist: + files: | + bin/otelcontribcol_darwin_amd64 + bin/otelcontribcol_linux_arm64 + bin/otelcontribcol_linux_amd64 + bin/otelcontribcol_windows_amd64.exe - setup_remote_docker - publish_docker_images: repo: opentelemetry-collector-dev @@ -297,6 +444,8 @@ jobs: executor: golang resource_class: medium+ parallelism: << parameters.runners-number >> + environment: + TEST_RESULTS: testbed/stabilitytests/results/junit/results.xml steps: - restore_workspace - run: @@ -328,3 +477,69 @@ jobs: }' when: on_fail + integration-tests: + executor: machine + environment: + GOPATH: /home/circleci/go + steps: + - setup_go + - setup + - run: + name: Integration tests with coverage + command: | + mkdir -p test-results/junit + trap "go-junit-report -set-exit-code < test-results/go-integration-tests.out > test-results/junit/results.xml" EXIT + make integration-tests-with-cover | tee test-results/go-integration-tests.out + - run: + name: Upload integration test coverage + command: bash <(curl -s https://codecov.io/bash) -F integration + - store_test_results: + path: test-results/junit + - store_artifacts: + path: test-results + - run: + name: Run on fail status + command: | + curl --request POST \ + --url https://api.github.com/repos/SumoLogic/opentelemetry-collector-contrib/issues \ + --header "authorization: Bearer ${GITHUB_TOKEN}" \ + --header "content-type: application/json" \ + --data '{ + "title": "Stability tests failed in branch '"${CIRCLE_BRANCH}"' for commit << pipeline.parameters.collector-sha >>", + "body": "Link to failed job: '"${CIRCLE_BUILD_URL}"'." + }' + when: on_fail + + build-package: + machine: + image: ubuntu-1604:202007-01 + parameters: + package_type: + type: enum + enum: ["deb", "rpm"] + steps: + - checkout + - attach_to_workspace + - run: + name: Install fpm and dependencies + command: | + sudo apt-get update + sudo apt-get install -y ruby ruby-dev rubygems build-essential rpm + gem install --no-document fpm -v 1.11.0 + - run: + name: Build << parameters.package_type >> amd64 package + command: ./internal/buildscripts/packaging/fpm/<< parameters.package_type >>/build.sh "${CIRCLE_TAG:-}" "amd64" "./dist/" + - run: + name: Build << parameters.package_type >> arm64 package + command: ./internal/buildscripts/packaging/fpm/<< parameters.package_type >>/build.sh "${CIRCLE_TAG:-}" "arm64" "./dist/" + - run: + name: Test << parameters.package_type >> package installation + command: | + if [[ "<< parameters.package_type >>" = "deb" ]]; then + ./internal/buildscripts/packaging/fpm/test.sh dist/otel-contrib-collector*amd64.deb examples/tracing/otel-collector-config.yml + else + ./internal/buildscripts/packaging/fpm/test.sh dist/otel-contrib-collector*x86_64.rpm examples/tracing/otel-collector-config.yml + fi + - persist_to_workspace: + root: ~/ + paths: project/dist/*.<< parameters.package_type >> \ No newline at end of file diff --git a/processor/tailsamplingprocessor/config_test.go b/processor/tailsamplingprocessor/config_test.go index 0b2521186d96..2acf9ca07f1d 100644 --- a/processor/tailsamplingprocessor/config_test.go +++ b/processor/tailsamplingprocessor/config_test.go @@ -73,36 +73,36 @@ func TestLoadConfig(t *testing.T) { RateLimitingCfg: config.RateLimitingCfg{SpansPerSecond: 35}, }, { - Name: "test-policy-5", - Type: config.Cascading, + Name: "test-policy-5", + Type: config.Cascading, SpansPerSecond: 1000, - Rules: []config.CascadingRuleCfg{ + Rules: []config.CascadingRuleCfg{ { - Name: "num", + Name: "num", SpansPerSecond: 123, NumericAttributeCfg: &config.NumericAttributeCfg{ Key: "key1", MinValue: 50, MaxValue: 100}, }, { - Name: "dur", + Name: "dur", SpansPerSecond: 50, PropertiesCfg: &config.PropertiesCfg{ MinDurationMicros: &minDurationValue, }, }, { - Name: "everything_else", + Name: "everything_else", SpansPerSecond: -1, }, }, }, { - Name: "test-policy-6", - Type: config.Properties, + Name: "test-policy-6", + Type: config.Properties, PropertiesCfg: config.PropertiesCfg{ - NamePattern: &namePatternValue, + NamePattern: &namePatternValue, MinDurationMicros: &minDurationValue, - MinNumberOfSpans: &minSpansValue, + MinNumberOfSpans: &minSpansValue, }, }, }, diff --git a/processor/tailsamplingprocessor/sampling/cascading.go b/processor/tailsamplingprocessor/sampling/cascading.go index b05dbeaf3b01..13d8743e502d 100644 --- a/processor/tailsamplingprocessor/sampling/cascading.go +++ b/processor/tailsamplingprocessor/sampling/cascading.go @@ -119,13 +119,13 @@ func NewCascadingFilter(logger *zap.Logger, cfg *config.PolicyCfg) (PolicyEvalua for _, ruleCfg := range cfg.Rules { attributesSet := 0 if ruleCfg.StringAttributeCfg != nil { - attributesSet += 1 + attributesSet++ } if ruleCfg.NumericAttributeCfg != nil { - attributesSet += 1 + attributesSet++ } if ruleCfg.PropertiesCfg != nil { - attributesSet += 1 + attributesSet++ } if attributesSet > 1 { @@ -211,7 +211,7 @@ func (cp *cascadingPolicy) Evaluate(traceID pdata.TraceID, trace *TraceData) (De } // This will ensure it's not sampled (otherwise it would get into SecondChance) - // This behaviour might be worth giving a deeper thought, as it effective removes matching + // This behavior might be worth giving a deeper thought, as it effective removes matching // traces from the SecondChance pool. recordSampled(rule.context, "matched", NotSampled) return NotSampled, nil diff --git a/processor/tailsamplingprocessor/sampling/span_properties_filter.go b/processor/tailsamplingprocessor/sampling/span_properties_filter.go index 6e134dad25f3..78f7b563df40 100644 --- a/processor/tailsamplingprocessor/sampling/span_properties_filter.go +++ b/processor/tailsamplingprocessor/sampling/span_properties_filter.go @@ -78,7 +78,7 @@ func (df *spanPropertiesFilter) EvaluateSecondChance(_ pdata.TraceID, trace *Tra } func tsToMicros(ts pdata.TimestampUnixNano) int64 { - return int64(ts/1000) + return int64(ts / 1000) } // Evaluate looks at the trace data and returns a corresponding SamplingDecision.