Skip to content

Commit

Permalink
Merge pull request #14 from kubefirst/telemetry
Browse files Browse the repository at this point in the history
adjustments to add parentclusterid and remove transmittype
  • Loading branch information
johndietz authored Dec 11, 2023
2 parents 28da1b1 + dcde194 commit f241c62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
27 changes: 6 additions & 21 deletions cmd/transmit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
installMethod string
kubefirstTeam string
kubefirstTeamInfo string
transmitType string
)

// transmitCmd represents the transmit command
Expand Down Expand Up @@ -56,35 +55,21 @@ var transmitCmd = &cobra.Command{
KubefirstTeam: os.Getenv("KUBEFIRST_TEAM"),
KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"),
MachineID: os.Getenv("CLUSTER_ID"),
MetricName: telemetry.ClusterInstallStarted,
ParentClusterId: os.Getenv("PARENT_CLUSTER_ID"),
MetricName: telemetry.ClusterInstallCompleted,
UserId: os.Getenv("CLUSTER_ID"),
}

switch transmitType {
case "cluster-zero":
//started event
err := telemetry.SendEvent(event, telemetry.ClusterInstallStarted, "")
if err != nil {
log.Error(err)
}
log.Infof("metrics transmitted: %s", event.MetricName)

//completed event
event.MetricName = telemetry.ClusterInstallCompleted
err = telemetry.SendEvent(event, telemetry.ClusterInstallCompleted, "")
if err != nil {
log.Error(err)
}
log.Infof("metrics transmitted: %s", event.MetricName)
default:
log.Errorf("%s is not an allowed option", transmitType)
err = telemetry.SendEvent(event, telemetry.ClusterInstallCompleted, "")
if err != nil {
log.Error(err)
}
log.Infof("metrics transmitted: %s", event.MetricName)
},
}

func init() {
rootCmd.AddCommand(transmitCmd)

transmitCmd.Flags().StringVar(&transmitType, "type", "", "the type of metric to transmit [cluster-zero] (required)")
transmitCmd.MarkFlagRequired("type")
}
6 changes: 4 additions & 2 deletions pkg/telemetry/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ const (
KbotSetupFailed = "kubefirst.init.kbot_setup.failed"

// Create
ClusterInstallStarted = "kubefirst.cluster_install.started"
// note: as of kubefirst 2.3.6, there will no longer a kubefirst.cluster_install.started event
// as all installs are conducted through helm
// ClusterInstallStarted = "kubefirst.cluster_install.started" # permanently removed
ClusterInstallCompleted = "kubefirst.cluster_install.completed"
ClusterInstallFailed = "kubefirst.cluster_install.failed"
ClusterInstallFailed = "kubefirst.cluster_install.failed"

GitTerraformApplyStarted = "kubefirst.git_terraform_apply.started"
GitTerraformApplyCompleted = "kubefirst.git_terraform_apply.completed"
Expand Down
3 changes: 2 additions & 1 deletion pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func SendEvent(event TelemetryEvent, metricName string, errMsg string) error {
return err
}

if event.MetricName == ClusterInstallStarted {
if event.MetricName == ClusterInstallCompleted {
err := client.Enqueue(analytics.Identify{
UserId: event.UserId,
})
Expand All @@ -60,6 +60,7 @@ func SendEvent(event TelemetryEvent, metricName string, errMsg string) error {
Set("kubefirst_team", event.KubefirstTeam).
Set("kubefirst_team_info", event.KubefirstTeamInfo).
Set("machine_id", event.MachineID).
Set("parent_cluster_id", event.ParentClusterId).
Set("error", errMsg),
})
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/telemetry/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type TelemetryEvent struct {
ClusterID string
ClusterType string
DomainName string
ErrorMessage string
GitProvider string
InstallMethod string
KubefirstClient string
KubefirstTeam string
KubefirstTeamInfo string
MachineID string
////////////////////////
ErrorMessage string
MetricName string
UserId string
MetricName string
ParentClusterId string
UserId string
}

0 comments on commit f241c62

Please sign in to comment.