diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index ba154f4ed..adcbea624 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -27,8 +27,9 @@ import ( "github.com/kubefirst/kubefirst-api/pkg/reports" "github.com/kubefirst/kubefirst-api/pkg/wrappers" "github.com/kubefirst/kubefirst/internal/gitShim" - "github.com/kubefirst/kubefirst/internal/telemetryShim" + "github.com/kubefirst/kubefirst/internal/segment" "github.com/kubefirst/kubefirst/internal/utilities" + "github.com/kubefirst/metrics-client/pkg/telemetry" "github.com/kubefirst/runtime/configs" "github.com/kubefirst/runtime/pkg" "github.com/kubefirst/runtime/pkg/argocd" @@ -40,7 +41,6 @@ import ( "github.com/kubefirst/runtime/pkg/k3d" "github.com/kubefirst/runtime/pkg/k8s" "github.com/kubefirst/runtime/pkg/progressPrinter" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/services" internalssh "github.com/kubefirst/runtime/pkg/ssh" "github.com/kubefirst/runtime/pkg/terraform" @@ -328,26 +328,9 @@ func runK3d(cmd *cobra.Command, args []string) error { viper.WriteConfig() } - // Segment Client - segmentClient := &segment.SegmentClient{ - CliVersion: configs.K1Version, - CloudProvider: k3d.CloudProvider, - ClusterID: clusterId, - ClusterType: clusterTypeFlag, - DomainName: k3d.DomainName, - GitProvider: gitProviderFlag, - KubefirstClient: "cli", - KubefirstTeam: kubefirstTeam, - KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"), - } - segmentClient.SetupClient() - defer func(c segment.SegmentClient) { - err := c.Client.Close() - if err != nil { - log.Info().Msgf("error closing segment client %s", err.Error()) - } - }(*segmentClient) - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricInitStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.InitStarted, "") // Progress output progressPrinter.AddTracker("preflight-checks", "Running preflight checks", 5) @@ -415,13 +398,15 @@ func runK3d(cmd *cobra.Command, args []string) error { // Check git credentials executionControl := viper.GetBool(fmt.Sprintf("kubefirst-checks.%s-credentials", config.GitProvider)) if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitCredentialsCheckStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.GitCredentialsCheckStarted, "") if len(cGitToken) == 0 { msg := fmt.Sprintf( "please set a %s_TOKEN environment variable to continue", strings.ToUpper(config.GitProvider), ) - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitCredentialsCheckFailed, msg) + telemetry.SendEvent(segClient, telemetry.GitCredentialsCheckFailed, msg) return fmt.Errorf(msg) } @@ -439,7 +424,7 @@ func runK3d(cmd *cobra.Command, args []string) error { viper.Set(fmt.Sprintf("kubefirst-checks.%s-credentials", config.GitProvider), true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitCredentialsCheckCompleted, "") + telemetry.SendEvent(segClient, telemetry.GitCredentialsCheckCompleted, "") progressPrinter.IncrementTracker("preflight-checks", 1) } else { log.Info().Msg(fmt.Sprintf("already completed %s checks - continuing", config.GitProvider)) @@ -449,12 +434,16 @@ func runK3d(cmd *cobra.Command, args []string) error { var gitopsRepoURL string executionControl = viper.GetBool("kubefirst-checks.kbot-setup") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricKbotSetupStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + 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 { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricKbotSetupFailed, err.Error()) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.KbotSetupFailed, err.Error()) return err } log.Info().Msg("ssh key pair creation complete") @@ -464,7 +453,7 @@ func runK3d(cmd *cobra.Command, args []string) error { viper.Set("kbot.username", "kbot") viper.Set("kubefirst-checks.kbot-setup", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricKbotSetupCompleted, "") + telemetry.SendEvent(segClient, telemetry.KbotSetupCompleted, err.Error()) log.Info().Msg("kbot-setup complete") progressPrinter.IncrementTracker("preflight-checks", 1) } else { @@ -474,8 +463,8 @@ func runK3d(cmd *cobra.Command, args []string) error { log.Info().Msg("validation and kubefirst cli environment check is complete") - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricInitCompleted, "") - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallStarted, "") + telemetry.SendEvent(segClient, telemetry.InitCompleted, "") + telemetry.SendEvent(segClient, telemetry.InitCompleted, "") // Swap tokens for git protocol switch config.GitProtocol { @@ -602,7 +591,9 @@ func runK3d(cmd *cobra.Command, args []string) error { // //* create teams and repositories in github executionControl = viper.GetBool("kubefirst-checks.terraform-apply-github") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitTerraformApplyStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.GitTerraformApplyStarted, "") log.Info().Msg("Creating GitHub resources with Terraform") @@ -623,15 +614,17 @@ func runK3d(cmd *cobra.Command, args []string) error { } err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs) if err != nil { + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() msg := fmt.Sprintf("error creating github resources with terraform %s: %s", tfEntrypoint, err) - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitTerraformApplyFailed, msg) + telemetry.SendEvent(segClient, telemetry.GitTerraformApplyFailed, msg) return fmt.Errorf(msg) } log.Info().Msgf("created git repositories for github.com/%s", cGitOwner) viper.Set("kubefirst-checks.terraform-apply-github", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitTerraformApplyCompleted, "") + telemetry.SendEvent(segClient, telemetry.GitTerraformApplyCompleted, "") progressPrinter.IncrementTracker("applying-git-terraform", 1) } else { log.Info().Msg("already created GitHub Terraform resources") @@ -641,7 +634,9 @@ func runK3d(cmd *cobra.Command, args []string) error { // //* create teams and repositories in gitlab executionControl = viper.GetBool("kubefirst-checks.terraform-apply-gitlab") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitTerraformApplyStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.GitTerraformApplyStarted, "") log.Info().Msg("Creating GitLab resources with Terraform") @@ -663,14 +658,16 @@ 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) - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitTerraformApplyFailed, msg) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.GitTerraformApplyFailed, msg) return fmt.Errorf(msg) } log.Info().Msgf("created git projects and groups for gitlab.com/%s", gitlabGroupFlag) viper.Set("kubefirst-checks.terraform-apply-gitlab", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitTerraformApplyCompleted, "") + telemetry.SendEvent(segClient, telemetry.GitTerraformApplyCompleted, "") progressPrinter.IncrementTracker("applying-git-terraform", 1) } else { log.Info().Msg("already created GitLab Terraform resources") @@ -687,7 +684,9 @@ func runK3d(cmd *cobra.Command, args []string) error { executionControl = viper.GetBool("kubefirst-checks.gitops-repo-pushed") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitopsRepoPushStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.GitopsRepoPushStarted, "") gitopsRepo, err := git.PlainOpen(config.GitopsDir) if err != nil { @@ -718,7 +717,9 @@ 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) - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitopsRepoPushFailed, msg) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.GitopsRepoPushFailed, msg) if !strings.Contains(msg, "already up-to-date") { log.Panic().Msg(msg) } @@ -733,7 +734,9 @@ 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) - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitopsRepoPushFailed, msg) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.GitopsRepoPushFailed, msg) if !strings.Contains(msg, "already up-to-date") { log.Panic().Msg(msg) } @@ -744,7 +747,7 @@ func runK3d(cmd *cobra.Command, args []string) error { // todo that way we can stop worrying about which origin we're going to push to viper.Set("kubefirst-checks.gitops-repo-pushed", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricGitopsRepoPushCompleted, "") + telemetry.SendEvent(segClient, telemetry.GitopsRepoPushCompleted, "") progressPrinter.IncrementTracker("pushing-gitops-repos-upstream", 1) // todo verify this tracker didnt lose one } else { log.Info().Msg("already pushed detokenized gitops repository content") @@ -757,7 +760,9 @@ func runK3d(cmd *cobra.Command, args []string) error { progressPrinter.SetupProgress(progressPrinter.TotalOfTrackers(), false) if !viper.GetBool("kubefirst-checks.create-k3d-cluster") { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricCloudTerraformApplyStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.CloudTerraformApplyStarted, "") log.Info().Msg("Creating k3d cluster") @@ -766,14 +771,16 @@ 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() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricCloudTerraformApplyFailed, msg) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.CloudTerraformApplyFailed, msg) return fmt.Errorf(msg) } log.Info().Msg("successfully created k3d cluster") viper.Set("kubefirst-checks.create-k3d-cluster", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricCloudTerraformApplyCompleted, "") + telemetry.SendEvent(segClient, telemetry.CloudTerraformApplyCompleted, "") progressPrinter.IncrementTracker("creating-k3d-cluster", 1) } else { log.Info().Msg("already created k3d cluster resources") @@ -904,7 +911,9 @@ func runK3d(cmd *cobra.Command, args []string) error { //* install argocd executionControl = viper.GetBool("kubefirst-checks.argocd-install") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricArgoCDInstallStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.ArgoCDInstallStarted, "") log.Info().Msgf("installing argocd") @@ -919,13 +928,15 @@ func runK3d(cmd *cobra.Command, args []string) error { } err = kcfg.ApplyObjects("", output) if err != nil { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricArgoCDInstallFailed, err.Error()) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.ArgoCDInstallFailed, err.Error()) return err } viper.Set("kubefirst-checks.argocd-install", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricArgoCDInstallCompleted, "") + telemetry.SendEvent(segClient, telemetry.ArgoCDInstallCompleted, "") progressPrinter.IncrementTracker("installing-argo-cd", 1) } else { log.Info().Msg("argo cd already installed, continuing") @@ -1021,7 +1032,9 @@ 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 { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricCreateRegistryStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.CreateRegistryStarted, "") argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig) if err != nil { return err @@ -1033,7 +1046,7 @@ func runK3d(cmd *cobra.Command, args []string) error { _, _ = argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{}) viper.Set("kubefirst-checks.argocd-create-registry", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricCreateRegistryCompleted, "") + telemetry.SendEvent(segClient, telemetry.CreateRegistryCompleted, "") progressPrinter.IncrementTracker("installing-argo-cd", 1) } else { log.Info().Msg("argocd registry create already done, continuing") @@ -1070,7 +1083,9 @@ func runK3d(cmd *cobra.Command, args []string) error { executionControl = viper.GetBool("kubefirst-checks.vault-initialized") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricVaultInitializationStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.VaultInitializationStarted, "") // Initialize and unseal Vault vaultHandlerPath := "github.com:kubefirst/manifests.git/vault-handler/replicas-1" @@ -1097,13 +1112,15 @@ 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) - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricVaultInitializationFailed, msg) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.VaultInitializationFailed, msg) log.Fatal().Msg(msg) } viper.Set("kubefirst-checks.vault-initialized", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricVaultInitializationCompleted, "") + telemetry.SendEvent(segClient, telemetry.VaultInitializationCompleted, "") progressPrinter.IncrementTracker("configuring-vault", 1) } else { log.Info().Msg("vault is already initialized - skipping") @@ -1200,7 +1217,9 @@ func runK3d(cmd *cobra.Command, args []string) error { //* configure vault with terraform executionControl = viper.GetBool("kubefirst-checks.terraform-apply-vault") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricVaultTerraformApplyStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.VaultTerraformApplyStarted, "") tfEnvs := map[string]string{} var usernamePasswordString, base64DockerAuth string @@ -1241,14 +1260,16 @@ func runK3d(cmd *cobra.Command, args []string) error { tfEntrypoint := config.GitopsDir + "/terraform/vault" err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs) if err != nil { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricVaultTerraformApplyFailed, err.Error()) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.VaultTerraformApplyStarted, err.Error()) return err } log.Info().Msg("vault terraform executed successfully") viper.Set("kubefirst-checks.terraform-apply-vault", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricVaultTerraformApplyCompleted, "") + telemetry.SendEvent(segClient, telemetry.VaultTerraformApplyCompleted, "") progressPrinter.IncrementTracker("configuring-vault", 1) } else { log.Info().Msg("already executed vault terraform") @@ -1261,7 +1282,9 @@ func runK3d(cmd *cobra.Command, args []string) error { executionControl = viper.GetBool("kubefirst-checks.terraform-apply-users") if !executionControl { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricUsersTerraformApplyStarted, "") + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.UsersTerraformApplyStarted, "") log.Info().Msg("applying users terraform") @@ -1278,14 +1301,16 @@ func runK3d(cmd *cobra.Command, args []string) error { tfEntrypoint := config.GitopsDir + "/terraform/users" err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs) if err != nil { - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricUsersTerraformApplyStarted, err.Error()) + segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + defer segClient.Client.Close() + telemetry.SendEvent(segClient, telemetry.UsersTerraformApplyStarted, err.Error()) return err } log.Info().Msg("executed users terraform successfully") // progressPrinter.IncrementTracker("step-users", 1) viper.Set("kubefirst-checks.terraform-apply-users", true) viper.WriteConfig() - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricUsersTerraformApplyCompleted, "") + telemetry.SendEvent(segClient, telemetry.UsersTerraformApplyCompleted, "") progressPrinter.IncrementTracker("creating-users", 1) } else { log.Info().Msg("already created users with terraform") @@ -1352,7 +1377,7 @@ func runK3d(cmd *cobra.Command, args []string) error { } // Mark cluster install as complete - telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallCompleted, "") + telemetry.SendEvent(segClient, telemetry.ClusterInstallCompleted, "") viper.Set("kubefirst-checks.cluster-install-complete", true) viper.WriteConfig() @@ -1401,12 +1426,5 @@ func runK3d(cmd *cobra.Command, args []string) error { } } - defer func(c segment.SegmentClient) { - err := c.Client.Close() - if err != nil { - log.Info().Msgf("error closing segment client %s", err.Error()) - } - }(*segmentClient) - return nil } diff --git a/go.mod b/go.mod index 271e8c184..3ddeeec8f 100644 --- a/go.mod +++ b/go.mod @@ -8,15 +8,18 @@ require ( github.com/aws/aws-sdk-go v1.44.230 github.com/charmbracelet/bubbles v0.16.1 github.com/charmbracelet/bubbletea v0.24.2 - github.com/charmbracelet/lipgloss v0.7.1 + github.com/charmbracelet/lipgloss v0.8.0 github.com/chromedp/chromedp v0.8.7 github.com/civo/civogo v0.3.28 + github.com/denisbrodbeck/machineid v1.0.1 github.com/dustin/go-humanize v1.0.1 github.com/go-git/go-git/v5 v5.6.1 github.com/hashicorp/vault/api v1.9.0 - github.com/kubefirst/kubefirst-api v0.0.2 + github.com/kubefirst/kubefirst-api v0.0.4 + github.com/kubefirst/metrics-client v0.2.1 github.com/kubefirst/runtime v0.3.28 - github.com/rs/zerolog v1.29.0 + github.com/rs/zerolog v1.29.1 + github.com/segmentio/analytics-go v3.1.0+incompatible github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.15.0 @@ -80,7 +83,6 @@ require ( github.com/chromedp/cdproto v0.0.0-20230109101555-6b041c6303cc // indirect github.com/chromedp/sysutil v1.0.0 // indirect github.com/cloudflare/circl v1.1.0 // indirect - github.com/denisbrodbeck/machineid v1.0.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/digitalocean/godo v1.98.0 // indirect github.com/dlclark/regexp2 v1.4.0 // indirect @@ -159,7 +161,6 @@ require ( github.com/rs/xid v1.4.0 // indirect github.com/russross/blackfriday v1.6.0 // indirect github.com/sahilm/fuzzy v0.1.0 // indirect - github.com/segmentio/analytics-go v3.1.0+incompatible // indirect github.com/segmentio/backo-go v1.0.1 // indirect github.com/skeema/knownhosts v1.1.0 // indirect github.com/vmihailenco/go-tinylfu v0.2.1 // indirect @@ -261,7 +262,7 @@ require ( github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/reflow v0.3.0 // indirect - github.com/muesli/termenv v0.15.1 // indirect + github.com/muesli/termenv v0.15.2 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/rivo/uniseg v0.4.2 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect diff --git a/go.sum b/go.sum index bdb030ec4..a34b2a1a4 100644 --- a/go.sum +++ b/go.sum @@ -248,8 +248,8 @@ github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06 github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc= github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc= -github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E= -github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c= +github.com/charmbracelet/lipgloss v0.8.0 h1:IS00fk4XAHcf8uZKc3eHeMUTCxUH6NkaTrdyCQk84RU= +github.com/charmbracelet/lipgloss v0.8.0/go.mod h1:p4eYUZZJ/0oXTuCQKFF8mqyKCz0ja6y+7DniDDw5KKU= github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E= github.com/chromedp/cdproto v0.0.0-20230109101555-6b041c6303cc h1:pgBIUnhrsNh0Xi+8qUdHIP/nljIVz3laeRv23eqr45M= github.com/chromedp/cdproto v0.0.0-20230109101555-6b041c6303cc/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= @@ -308,7 +308,7 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -731,8 +731,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubefirst/kubefirst-api v0.0.2 h1:ezvCOiafSJ9arapBAnewDU8a/r3VO6GAJywQrQs9QDU= -github.com/kubefirst/kubefirst-api v0.0.2/go.mod h1:SFnfUf9aY0sLmju1UvDGxLHL3mxGV94RzHwHrf27vsI= +github.com/kubefirst/kubefirst-api v0.0.4 h1:YhPR9L14s7ZlLbKM3ODHaXIq+r5LO7qesBW0e4/2w58= +github.com/kubefirst/kubefirst-api v0.0.4/go.mod h1:RCxLtyupPlpkOYYGFKnbbPCpacEHvlHzEW3Rn77r7XU= +github.com/kubefirst/metrics-client v0.2.1 h1:KCzeeKQCq13ksj+l8cTrtHWKtraYTTnwWks2X4+xdFI= +github.com/kubefirst/metrics-client v0.2.1/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc= github.com/kubefirst/runtime v0.3.28 h1:Ac9NzqX+H0fa4tUauOMrjbtpSFnNluLYmSk6v5u++G4= github.com/kubefirst/runtime v0.3.28/go.mod h1:9egAgF5cF594mIzra5nTB1kfE57Hr/Nvl79tjLsAWCQ= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= @@ -847,8 +849,8 @@ github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIf github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= -github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs= -github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ= +github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= +github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= @@ -1005,8 +1007,8 @@ github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.21.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM= -github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= -github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= +github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc= +github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU= github.com/rubiojr/go-vhd v0.0.0-20200706105327-02e210299021/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= diff --git a/internal/segment/segment.go b/internal/segment/segment.go new file mode 100644 index 000000000..d4b1808e3 --- /dev/null +++ b/internal/segment/segment.go @@ -0,0 +1,44 @@ +package segment + +import ( + "os" + + "github.com/denisbrodbeck/machineid" + "github.com/kubefirst/kubefirst/configs" + "github.com/kubefirst/metrics-client/pkg/telemetry" + "github.com/kubefirst/runtime/pkg/k3d" + + "github.com/segmentio/analytics-go" +) + +const ( + kubefirstClient string = "api" +) + +func InitClient(clusterId, clusterType, gitProvider string) *telemetry.SegmentClient { + + machineID, _ := machineid.ID() + sc := analytics.New(telemetry.SegmentIOWriteKey) + + c := telemetry.SegmentClient{ + TelemetryEvent: telemetry.TelemetryEvent{ + CliVersion: configs.K1Version, + CloudProvider: k3d.CloudProvider, + ClusterID: clusterId, + ClusterType: clusterType, + DomainName: k3d.DomainName, + GitProvider: gitProvider, + InstallMethod: "kubefirst-launch", + KubefirstClient: kubefirstClient, + KubefirstTeam: os.Getenv("KUBEFIRST_TEAM"), + KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"), + MachineID: machineID, + ErrorMessage: "", + UserId: machineID, + MetricName: telemetry.ClusterInstallStarted, + }, + Client: sc, + } + + return &c +} diff --git a/internal/telemetryShim/metrics.go b/internal/telemetryShim/metrics.go deleted file mode 100644 index 4437e1179..000000000 --- a/internal/telemetryShim/metrics.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright (C) 2021-2023, Kubefirst - -This program is licensed under MIT. -See the LICENSE file for more details. -*/ -package telemetryShim - -import ( - "github.com/kubefirst/runtime/pkg/segment" - "github.com/rs/zerolog/log" -) - -// Transmit sends a metric via Segment -func Transmit(useTelemetry bool, segmentClient *segment.SegmentClient, metricName string, errorMessage string) { - segmentMsg := segmentClient.SendCountMetric(metricName, errorMessage) - if segmentMsg != "" { - log.Info().Msg(segmentMsg) - } -}