diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index cb507b604..9cbd2eb4f 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -328,7 +328,6 @@ func runK3d(cmd *cobra.Command, args []string) error { } segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) - telemetry.SendEvent(segClient, telemetry.ClusterInstallStarted, "") // Progress output progressPrinter.AddTracker("preflight-checks", "Running preflight checks", 5) @@ -396,7 +395,6 @@ func runK3d(cmd *cobra.Command, args []string) error { // Check git credentials executionControl := viper.GetBool(fmt.Sprintf("kubefirst-checks.%s-credentials", config.GitProvider)) if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.GitCredentialsCheckStarted, "") if len(cGitToken) == 0 { msg := fmt.Sprintf( @@ -431,13 +429,11 @@ func runK3d(cmd *cobra.Command, args []string) error { var gitopsRepoURL string executionControl = viper.GetBool("kubefirst-checks.kbot-setup") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.KbotSetupStarted, "") log.Info().Msg("creating an ssh key pair for your new cloud infrastructure") sshPrivateKey, sshPublicKey, err = internalssh.CreateSshKeyPair() if err != nil { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.KbotSetupFailed, err.Error()) return err } @@ -586,7 +582,6 @@ func runK3d(cmd *cobra.Command, args []string) error { // //* create teams and repositories in github executionControl = viper.GetBool("kubefirst-checks.terraform-apply-github") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.GitTerraformApplyStarted, "") log.Info().Msg("Creating GitHub resources with Terraform") @@ -608,7 +603,6 @@ func runK3d(cmd *cobra.Command, args []string) error { } err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs) if err != nil { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) msg := fmt.Sprintf("error creating github resources with terraform %s: %s", tfEntrypoint, err) telemetry.SendEvent(segClient, telemetry.GitTerraformApplyFailed, msg) return fmt.Errorf(msg) @@ -627,7 +621,6 @@ func runK3d(cmd *cobra.Command, args []string) error { // //* create teams and repositories in gitlab executionControl = viper.GetBool("kubefirst-checks.terraform-apply-gitlab") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.GitTerraformApplyStarted, "") log.Info().Msg("Creating GitLab resources with Terraform") @@ -650,7 +643,6 @@ func runK3d(cmd *cobra.Command, args []string) error { err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs) if err != nil { msg := fmt.Sprintf("error creating gitlab resources with terraform %s: %s", tfEntrypoint, err) - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.GitTerraformApplyFailed, msg) return fmt.Errorf(msg) } @@ -675,7 +667,6 @@ func runK3d(cmd *cobra.Command, args []string) error { executionControl = viper.GetBool("kubefirst-checks.gitops-repo-pushed") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.GitopsRepoPushStarted, "") gitopsRepo, err := git.PlainOpen(config.GitopsDir) @@ -707,7 +698,6 @@ func runK3d(cmd *cobra.Command, args []string) error { ) if err != nil { msg := fmt.Sprintf("error pushing detokenized gitops repository to remote %s: %s", config.DestinationGitopsRepoGitURL, err) - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.GitopsRepoPushFailed, msg) if !strings.Contains(msg, "already up-to-date") { log.Panic().Msg(msg) @@ -723,7 +713,6 @@ func runK3d(cmd *cobra.Command, args []string) error { ) if err != nil { msg := fmt.Sprintf("error pushing detokenized metaphor repository to remote %s: %s", config.DestinationMetaphorRepoURL, err) - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.GitopsRepoPushFailed, msg) if !strings.Contains(msg, "already up-to-date") { log.Panic().Msg(msg) @@ -748,7 +737,6 @@ func runK3d(cmd *cobra.Command, args []string) error { progressPrinter.SetupProgress(progressPrinter.TotalOfTrackers(), false) if !viper.GetBool("kubefirst-checks.create-k3d-cluster") { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.CloudTerraformApplyStarted, "") log.Info().Msg("Creating k3d cluster") @@ -758,7 +746,6 @@ func runK3d(cmd *cobra.Command, args []string) error { msg := fmt.Sprintf("error creating k3d resources with k3d client %s: %s", config.K3dClient, err) viper.Set("kubefirst-checks.create-k3d-cluster-failed", true) viper.WriteConfig() - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.CloudTerraformApplyFailed, msg) return fmt.Errorf(msg) } @@ -897,7 +884,6 @@ func runK3d(cmd *cobra.Command, args []string) error { //* install argocd executionControl = viper.GetBool("kubefirst-checks.argocd-install") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.ArgoCDInstallStarted, "") log.Info().Msgf("installing argocd") @@ -913,7 +899,6 @@ func runK3d(cmd *cobra.Command, args []string) error { } err = kcfg.ApplyObjects("", output) if err != nil { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.ArgoCDInstallFailed, err.Error()) return err } @@ -1016,7 +1001,6 @@ func runK3d(cmd *cobra.Command, args []string) error { //* argocd sync registry and start sync waves executionControl = viper.GetBool("kubefirst-checks.argocd-create-registry") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.CreateRegistryStarted, "") argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig) if err != nil { @@ -1066,7 +1050,6 @@ func runK3d(cmd *cobra.Command, args []string) error { executionControl = viper.GetBool("kubefirst-checks.vault-initialized") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.VaultInitializationStarted, "") // Initialize and unseal Vault @@ -1094,7 +1077,6 @@ func runK3d(cmd *cobra.Command, args []string) error { _, err = k8s.WaitForJobComplete(kcfg.Clientset, job, 240) if err != nil { msg := fmt.Sprintf("could not run vault unseal job: %s", err) - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.VaultInitializationFailed, msg) log.Fatal().Msg(msg) } @@ -1198,7 +1180,6 @@ func runK3d(cmd *cobra.Command, args []string) error { //* configure vault with terraform executionControl = viper.GetBool("kubefirst-checks.terraform-apply-vault") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.VaultTerraformApplyStarted, "") tfEnvs := map[string]string{} @@ -1240,7 +1221,6 @@ func runK3d(cmd *cobra.Command, args []string) error { tfEntrypoint := config.GitopsDir + "/terraform/vault" err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs) if err != nil { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.VaultTerraformApplyStarted, err.Error()) return err } @@ -1261,7 +1241,6 @@ func runK3d(cmd *cobra.Command, args []string) error { executionControl = viper.GetBool("kubefirst-checks.terraform-apply-users") if !executionControl { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.UsersTerraformApplyStarted, "") log.Info().Msg("applying users terraform") @@ -1279,7 +1258,6 @@ func runK3d(cmd *cobra.Command, args []string) error { tfEntrypoint := config.GitopsDir + "/terraform/users" err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs) if err != nil { - segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) telemetry.SendEvent(segClient, telemetry.UsersTerraformApplyStarted, err.Error()) return err } diff --git a/go.mod b/go.mod index 65714f05c..6090f22ec 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/go-git/go-git/v5 v5.6.1 github.com/hashicorp/vault/api v1.9.0 github.com/kubefirst/kubefirst-api v0.1.8 - github.com/kubefirst/metrics-client v0.2.8 + github.com/kubefirst/metrics-client v0.3.0 github.com/kubefirst/runtime v0.3.35 github.com/rs/zerolog v1.29.1 github.com/segmentio/analytics-go v3.1.0+incompatible diff --git a/go.sum b/go.sum index edf00b8fa..b0f98e3ec 100644 --- a/go.sum +++ b/go.sum @@ -725,6 +725,8 @@ github.com/kubefirst/kubefirst-api v0.1.8 h1:+5AT9pDj4AuH2GCW43Z9U/frEEyemqeZOm3 github.com/kubefirst/kubefirst-api v0.1.8/go.mod h1:Euz7+acib+o9DTkJ3MXRVtPL1rI+vGFZditYG2aXQCY= github.com/kubefirst/metrics-client v0.2.8 h1:JfaeiBifZD/DpyYW2QVHcrhH/KWA98OmM+7c7M12qMc= github.com/kubefirst/metrics-client v0.2.8/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc= +github.com/kubefirst/metrics-client v0.3.0 h1:zCug82pEzeWhHhpeYQvdhytRNDxrLxX18dPQ5PSxY3s= +github.com/kubefirst/metrics-client v0.3.0/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc= github.com/kubefirst/runtime v0.3.35 h1:wn430Irf0E1vc3X0WX3lYBpyhQ5TN6xxMcargILA9uI= github.com/kubefirst/runtime v0.3.35/go.mod h1:0CnYy+8JTG+/0f3QlkTQJqTT654Su6JXk30OufFVY98= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= diff --git a/internal/segment/segment.go b/internal/segment/segment.go index e13bab385..3dad6cab0 100644 --- a/internal/segment/segment.go +++ b/internal/segment/segment.go @@ -30,7 +30,7 @@ func InitClient(clusterId, clusterType, gitProvider string) telemetry.TelemetryE KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"), MachineID: machineID, ErrorMessage: "", - MetricName: telemetry.ClusterInstallStarted, + MetricName: telemetry.ClusterInstallCompleted, UserId: machineID, }