Skip to content

Commit

Permalink
feat: add orgid and envid to telemetry (#4065) (#4066)
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv authored Jun 20, 2023
1 parent 48c12a2 commit 332b09f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/telemetry/payload.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package telemetry

import (
"os"
"runtime"
"strings"

"github.com/kubeshop/testkube/pkg/utils/text"
)

const runContextAgent = "agent"

type Params struct {
EventCount int64 `json:"event_count,omitempty"`
EventCategory string `json:"event_category,omitempty"`
Expand Down Expand Up @@ -108,6 +111,7 @@ func NewAPIPayload(clusterId, name, version, host, clusterType string) Payload {
MachineID: GetMachineID(),
ClusterID: clusterId,
ClusterType: clusterType,
Context: getAgentContext(),
},
}},
}
Expand Down Expand Up @@ -136,6 +140,7 @@ func NewCreatePayload(name, clusterType string, params CreateParams) Payload {
TestSource: params.TestSource,
TestSuiteSteps: params.TestSuiteSteps,
ClusterType: clusterType,
Context: getAgentContext(),
},
}},
}
Expand Down Expand Up @@ -164,6 +169,7 @@ func NewRunPayload(name, clusterType string, params RunParams) Payload {
DurationMs: params.DurationMs,
Status: params.Status,
ClusterType: clusterType,
Context: getAgentContext(),
},
}},
}
Expand All @@ -184,3 +190,17 @@ func AnonymizeHost(host string) string {

return APIHostExternal
}

func getAgentContext() RunContext {
orgID := os.Getenv("TESTKUBE_CLOUD_ORG_ID")
envID := os.Getenv("TESTKUBE_CLOUD_ENV_ID")

if orgID == "" || envID == "" {
return RunContext{}
}
return RunContext{
Type: runContextAgent,
EnvironmentId: envID,
OrganizationId: orgID,
}
}

0 comments on commit 332b09f

Please sign in to comment.