From 9efb49199cf5eb4230f5280321f95c4cd92b5b56 Mon Sep 17 00:00:00 2001 From: nicufk Date: Thu, 21 Mar 2024 13:41:12 -0300 Subject: [PATCH] fix: add telemetry cli context (#5226) (#5229) --- pkg/telemetry/payload.go | 2 ++ pkg/telemetry/telemetry.go | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/pkg/telemetry/payload.go b/pkg/telemetry/payload.go index 675e354d9ef..5f0006c25ae 100644 --- a/pkg/telemetry/payload.go +++ b/pkg/telemetry/payload.go @@ -29,6 +29,7 @@ type Params struct { TestSuiteSteps int32 `json:"test_suite_steps,omitempty"` Context RunContext `json:"context,omitempty"` ClusterType string `json:"cluster_type,omitempty"` + CliContext string `json:"cli_context,omitempty"` Error string `json:"error,omitempty"` ErrorType string `json:"error_type,omitempty"` ErrorStackTrace string `json:"error_stacktrace,omitempty"` @@ -113,6 +114,7 @@ func NewCLIPayload(context RunContext, id, name, version, category, clusterType Architecture: runtime.GOARCH, Context: context, ClusterType: clusterType, + CliContext: GetCliRunContext(), }, }}, } diff --git a/pkg/telemetry/telemetry.go b/pkg/telemetry/telemetry.go index a5dc11b5127..bf34ef0ea64 100644 --- a/pkg/telemetry/telemetry.go +++ b/pkg/telemetry/telemetry.go @@ -3,6 +3,7 @@ package telemetry import ( "context" "net/http" + "os" "runtime" "sync" @@ -231,3 +232,65 @@ func GetClusterType() string { return "others" } + +func GetCliRunContext() string { + if value, ok := os.LookupEnv("GITHUB_ACTIONS"); ok { + if value == "true" { + return "github-actions" + } + } + + if _, ok := os.LookupEnv("TF_BUILD"); ok { + return "azure-pipelines" + } + + if _, ok := os.LookupEnv("JENKINS_URL"); ok { + return "jenkins" + } + + if _, ok := os.LookupEnv("JENKINS_HOME"); ok { + return "jenkins" + } + + if _, ok := os.LookupEnv("CIRCLECI"); ok { + return "circleci" + } + + if _, ok := os.LookupEnv("GITLAB_CI"); ok { + return "gitlab-ci" + } + + if _, ok := os.LookupEnv("BUILDKITE"); ok { + return "buildkite" + } + + if _, ok := os.LookupEnv("TRAVIS"); ok { + return "travis-ci" + } + + if _, ok := os.LookupEnv("AIRFLOW_HOME"); ok { + return "airflow" + } + + if _, ok := os.LookupEnv("TEAMCITY_VERSION"); ok { + return "teamcity" + } + + if _, ok := os.LookupEnv("GO_PIPELINE_NAME"); ok { + return "gocd" + } + + if _, ok := os.LookupEnv("SEMAPHORE"); ok { + return "semaphore-ci" + } + + if _, ok := os.LookupEnv("BITBUCKET_BUILD_NUMBER"); ok { + return "bitbucket-pipelines" + } + + if _, ok := os.LookupEnv("DRONE"); ok { + return "drone" + } + + return "others|local" +}