From b3874b3cb2cca29633142a24294d0051e7ed3d1d Mon Sep 17 00:00:00 2001 From: JulesFaucherre Date: Thu, 7 Sep 2023 13:37:59 +0200 Subject: [PATCH] Reintroduce telemetry (#1004) * Revert "revert: "feat: Put back telemetry" (#1001)" This reverts commit a5168722b9dca079fa6f2b9be4725366282e351c. * fix: Fix runner token telemetry event * fix: Allow runner commands to run their PersistentPreRun With cobra, when you define a PersistentPreRun in a child command, you overwrite all the command's parents PersistentPreRun. When introducing telemetry, we used the PersistentPreRun to send the events, this made the runner commands not call the PersistentPreRun in cmd/runner/runner.go which defines the 'opts.r' value. In the commands the 'opts.r' was nil, thus causing nil pointer deference panic. This commit uses the PreRunE to send the telemetry event instead of the PersistentPreRun to avoid this issue. --- .circleci/config.yml | 6 + Makefile | 2 +- README.md | 20 +- Taskfile.yml | 10 +- api/api.go | 19 ++ clitest/clitest.go | 22 +- clitest/telemetry.go | 19 ++ cmd/build.go | 10 +- cmd/cmd_suite_test.go | 3 + cmd/completion.go | 10 +- cmd/config.go | 31 ++- cmd/config_test.go | 32 ++- cmd/create_telemetry.go | 206 +++++++++++++++++++ cmd/create_telemetry_test.go | 321 +++++++++++++++++++++++++++++ cmd/diagnostic.go | 12 +- cmd/diagnostic_test.go | 19 ++ cmd/follow.go | 12 +- cmd/info/info.go | 10 +- cmd/info/info_test.go | 58 +++++- cmd/namespace.go | 10 +- cmd/namespace_test.go | 37 ++++ cmd/open.go | 17 +- cmd/orb.go | 6 + cmd/orb_test.go | 52 +++++ cmd/policy/policy.go | 18 +- cmd/policy/policy_test.go | 11 +- cmd/root.go | 34 +++- cmd/root_test.go | 8 +- cmd/runner/instance.go | 13 +- cmd/runner/resource_class.go | 18 +- cmd/runner/telemetry_test.go | 62 ++++++ cmd/runner/token.go | 19 +- cmd/setup.go | 9 +- cmd/setup_test.go | 32 +++ cmd/telemetry.go | 79 ++++++++ cmd/telemetry_test.go | 58 ++++++ cmd/telemetry_unit_test.go | 143 +++++++++++++ cmd/update.go | 17 +- cmd/update_test.go | 65 ++++++ cmd/version.go | 14 +- cmd/version_test.go | 39 ++++ go.mod | 5 + go.sum | 377 +++++++++++++++++++++++++++++++++++ main.go | 6 +- prompt/prompt.go | 11 + settings/settings.go | 84 ++++++-- telemetry/context.go | 16 ++ telemetry/events.go | 149 ++++++++++++++ telemetry/telemetry.go | 197 ++++++++++++++++++ telemetry/utils.go | 31 +++ 50 files changed, 2363 insertions(+), 96 deletions(-) create mode 100644 clitest/telemetry.go create mode 100644 cmd/create_telemetry.go create mode 100644 cmd/create_telemetry_test.go create mode 100644 cmd/runner/telemetry_test.go create mode 100644 cmd/telemetry.go create mode 100644 cmd/telemetry_test.go create mode 100644 cmd/telemetry_unit_test.go create mode 100644 cmd/version_test.go create mode 100644 telemetry/context.go create mode 100644 telemetry/events.go create mode 100644 telemetry/telemetry.go create mode 100644 telemetry/utils.go diff --git a/.circleci/config.yml b/.circleci/config.yml index edd87a19d..8a1b5456c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -137,6 +137,10 @@ jobs: working_directory: integration_tests environment: TESTING: "true" + - run: + name: "Make sure simple command do not cause any timeout" + command: circleci version + test: executor: go steps: @@ -378,12 +382,14 @@ workflows: - devex-release - deploy: requires: + - cucumber - test - test_mac - coverage - lint - deploy-test - shellcheck/check + - vulnerability-scan filters: branches: only: main diff --git a/Makefile b/Makefile index 604d50148..a51a58c4a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) build: always - go build -o build/$(GOOS)/$(GOARCH)/circleci + go build -o build/$(GOOS)/$(GOARCH)/circleci -ldflags='-X github.com/CircleCI-Public/circleci-cli/telemetry.SegmentEndpoint=https://api.segment.io' build-all: build/linux/amd64/circleci build/darwin/amd64/circleci diff --git a/README.md b/README.md index a955cff70..b57b73873 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,20 @@ Please see the [documentation](https://circleci-public.github.io/circleci-cli) o ## Server compatibility -There are some difference of behavior depending on the version you use: - - config validation will use the GraphQL API until **Server v4.0.5, v4.1.3, v4.2.0**. The above versions will use the new route `compile-config-with-defaults` - - `circleci orb validate` will only allow you to validate orbs using other private orbs with the option `--org-slug` from version **Server v4.2.0** +| Functionality | Impacted commands | Change description | Compatibility with Server | +| --- | --- | --- | --- | +| Config compilation and validation |