From f15352585d3e600dfa1c53bcc8dd36836dc85796 Mon Sep 17 00:00:00 2001 From: John Dietz Date: Sat, 21 Oct 2023 02:33:31 -0400 Subject: [PATCH] removing dependency on segment in runtime --- go.mod | 5 +++-- internal/controller/argocd.go | 14 +++++++------- internal/controller/cluster.go | 12 ++++++------ internal/controller/controller.go | 4 ++-- internal/controller/domain.go | 8 ++++---- internal/controller/git.go | 8 ++++---- internal/controller/kbot.go | 4 ++-- internal/controller/repository.go | 10 +++++----- internal/controller/state.go | 14 +++++++------- internal/controller/users.go | 8 ++++---- internal/controller/vault.go | 14 +++++++------- internal/router/api/v1/telemetry.go | 2 +- internal/telemetryShim/heartbeat.go | 2 +- pkg/segment/send.go | 17 +++++------------ providers/aws/create.go | 4 ++-- providers/aws/delete.go | 6 +++--- providers/civo/create.go | 4 ++-- providers/civo/delete.go | 6 +++--- providers/digitalocean/create.go | 4 ++-- providers/digitalocean/delete.go | 6 +++--- providers/google/create.go | 4 ++-- providers/google/delete.go | 6 +++--- providers/vultr/create.go | 4 ++-- providers/vultr/delete.go | 6 +++--- 24 files changed, 83 insertions(+), 89 deletions(-) diff --git a/go.mod b/go.mod index 00b785d6..8d3fb138 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/charmbracelet/lipgloss v0.8.0 github.com/civo/civogo v0.3.28 github.com/cloudflare/cloudflare-go v0.73.0 + github.com/denisbrodbeck/machineid v1.0.1 github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.8.2 github.com/go-git/go-git/v5 v5.6.1 @@ -29,6 +30,7 @@ require ( github.com/minio/minio-go/v7 v7.0.49 github.com/otiai10/copy v1.7.0 github.com/rs/zerolog v1.29.0 + github.com/segmentio/analytics-go v3.1.0+incompatible github.com/sirupsen/logrus v1.9.0 github.com/swaggo/files v1.0.0 github.com/swaggo/gin-swagger v1.5.3 @@ -99,7 +101,6 @@ require ( github.com/cloudflare/circl v1.1.0 // indirect github.com/containerd/console v1.0.3 // indirect github.com/davecgh/go-spew v1.1.1 // 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/docker/distribution v2.8.1+incompatible // indirect @@ -211,7 +212,6 @@ require ( github.com/rs/xid v1.4.0 // indirect github.com/russross/blackfriday v1.5.2 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect - github.com/segmentio/analytics-go v3.1.0+incompatible // indirect github.com/segmentio/backo-go v1.0.1 // indirect github.com/sergi/go-diff v1.2.0 // indirect github.com/skeema/knownhosts v1.1.0 // indirect @@ -325,3 +325,4 @@ replace ( k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.2 ) +replace github.com/kubefirst/runtime => /Users/jdietz/git/github/kubefirst/runtime diff --git a/internal/controller/argocd.go b/internal/controller/argocd.go index ff624562..d6002348 100644 --- a/internal/controller/argocd.go +++ b/internal/controller/argocd.go @@ -14,10 +14,10 @@ import ( argocdapi "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned" awsext "github.com/kubefirst/kubefirst-api/extensions/aws" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/runtime/pkg" "github.com/kubefirst/runtime/pkg/argocd" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -66,13 +66,13 @@ func (clctrl *ClusterController) InstallArgoCD() error { err = argocd.ApplyArgoCDKustomize(kcfg.Clientset, argoCDInstallPath) if err != nil { - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallFailed, err.Error()) + telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallFailed, err.Error()) return err } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallCompleted, "") - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallStarted, "") - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallCompleted, "") // Wait for ArgoCD to be ready _, err = k8s.VerifyArgoCDReadiness(kcfg.Clientset, true, 300) @@ -208,7 +208,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error { } } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCreateRegistryStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricCreateRegistryStarted, "") argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig) if err != nil { return err @@ -253,7 +253,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error { _, _ = argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{}) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCreateRegistryCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricCreateRegistryCompleted, "") err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "argocd_create_registry_check", true) if err != nil { diff --git a/internal/controller/cluster.go b/internal/controller/cluster.go index eb6c204b..8fdf341c 100644 --- a/internal/controller/cluster.go +++ b/internal/controller/cluster.go @@ -21,9 +21,9 @@ import ( gitShim "github.com/kubefirst/kubefirst-api/internal/gitShim" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" "github.com/thanhpk/randstr" v1 "k8s.io/api/apps/v1" @@ -54,12 +54,12 @@ func (clctrl *ClusterController) CreateCluster() error { if !cl.CloudTerraformApplyCheck || cl.CloudTerraformApplyFailedCheck { - telemetryShim.Transmit(true, segmentClient, segment.MetricCloudTerraformApplyStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyStarted, "") log.Info("creating aws cloud resources with terraform") tfEntrypoint := clctrl.ProviderConfig.GitopsDir + fmt.Sprintf("/terraform/%s", clctrl.CloudProvider) tfEnvs := map[string]string{} - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyStarted, "") log.Infof("creating %s cluster", clctrl.CloudProvider) @@ -95,17 +95,17 @@ func (clctrl *ClusterController) CreateCluster() error { if err != nil { return err } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyFailed, msg) + telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyFailed, msg) return fmt.Errorf(msg) } log.Infof("created %s cloud resources", clctrl.CloudProvider) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyCompleted, "") log.Infof("successfully created %s cluster", clctrl.CloudProvider) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyCompleted, "") err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "cloud_terraform_apply_failed_check", false) if err != nil { diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 1c33209a..03b1daf9 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -20,6 +20,7 @@ import ( google "github.com/kubefirst/kubefirst-api/pkg/google" "github.com/kubefirst/kubefirst-api/pkg/handlers" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg" runtime "github.com/kubefirst/runtime/pkg" @@ -27,7 +28,6 @@ import ( "github.com/kubefirst/runtime/pkg/github" "github.com/kubefirst/runtime/pkg/gitlab" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/services" log "github.com/sirupsen/logrus" "go.mongodb.org/mongo-driver/bson/primitive" @@ -150,7 +150,7 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition) } defer segmentClient.Client.Close() - telemetryShim.Transmit(rec.UseTelemetry, segmentClient, segment.MetricClusterInstallStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallStarted, "") //Copy Cluster Definiion to Cluster Controller clctrl.AlertsEmail = def.AdminEmail diff --git a/internal/controller/domain.go b/internal/controller/domain.go index b0520cc6..b02481a8 100644 --- a/internal/controller/domain.go +++ b/internal/controller/domain.go @@ -12,10 +12,10 @@ import ( cloudflare_api "github.com/cloudflare/cloudflare-go" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/runtime/pkg/civo" "github.com/kubefirst/runtime/pkg/digitalocean" "github.com/kubefirst/runtime/pkg/dns" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/vultr" log "github.com/sirupsen/logrus" ) @@ -35,7 +35,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error { defer segmentClient.Client.Close() if !cl.DomainLivenessCheck { - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricDomainLivenessStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessStarted, "") switch clctrl.DnsProvider { case "aws": @@ -54,7 +54,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error { // domain id domainId, err := civoConf.GetDNSInfo(clctrl.DomainName, clctrl.CloudRegion) if err != nil { - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricDomainLivenessFailed, "domain liveness test failed") + telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessFailed, "domain liveness test failed") log.Info(err.Error()) } @@ -129,7 +129,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error { return err } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricDomainLivenessCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessCompleted, "") log.Infof("domain %s verified", clctrl.DomainName) } diff --git a/internal/controller/git.go b/internal/controller/git.go index 7c3ea589..552f6785 100644 --- a/internal/controller/git.go +++ b/internal/controller/git.go @@ -18,8 +18,8 @@ import ( vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr" gitShim "github.com/kubefirst/kubefirst-api/internal/gitShim" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/runtime/pkg/gitlab" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -80,7 +80,7 @@ func (clctrl *ClusterController) RunGitTerraform() error { defer segmentClient.Client.Close() // //* create teams and repositories in github - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitTerraformApplyStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricGitTerraformApplyStarted, "") log.Infof("Creating %s resources with terraform", clctrl.GitProvider) @@ -121,12 +121,12 @@ func (clctrl *ClusterController) RunGitTerraform() error { if err != nil { msg := fmt.Sprintf("error creating %s resources with terraform %s: %s", clctrl.GitProvider, tfEntrypoint, err) log.Error(msg) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitTerraformApplyFailed, msg) + telemetryShim.Transmit(segmentClient, segment.MetricGitTerraformApplyFailed, msg) return fmt.Errorf(msg) } log.Infof("created git projects and groups for %s.com/%s", clctrl.GitProvider, clctrl.GitAuth.Owner) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitTerraformApplyCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricGitTerraformApplyCompleted, "") err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "git_terraform_apply_check", true) if err != nil { diff --git a/internal/controller/kbot.go b/internal/controller/kbot.go index 8be08c61..68139b61 100644 --- a/internal/controller/kbot.go +++ b/internal/controller/kbot.go @@ -10,7 +10,7 @@ import ( "os" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" - "github.com/kubefirst/runtime/pkg/segment" + "github.com/kubefirst/kubefirst-api/pkg/segment" internalssh "github.com/kubefirst/runtime/pkg/ssh" log "github.com/sirupsen/logrus" ) @@ -42,7 +42,7 @@ func (clctrl *ClusterController) InitializeBot() error { clctrl.GitAuth.PrivateKey, clctrl.GitAuth.PublicKey, err = internalssh.CreateSshKeyPair() if err != nil { log.Errorf("error generating ssh keys: %s", err) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricKbotSetupFailed, err.Error()) + telemetryShim.Transmit(segmentClient, segment.MetricKbotSetupFailed, err.Error()) return err } diff --git a/internal/controller/repository.go b/internal/controller/repository.go index 8b5593a6..a40a1a1a 100644 --- a/internal/controller/repository.go +++ b/internal/controller/repository.go @@ -16,10 +16,10 @@ import ( "github.com/kubefirst/kubefirst-api/internal/telemetryShim" google "github.com/kubefirst/kubefirst-api/pkg/google" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/runtime/pkg/civo" "github.com/kubefirst/runtime/pkg/digitalocean" "github.com/kubefirst/runtime/pkg/gitlab" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/vultr" log "github.com/sirupsen/logrus" ) @@ -202,7 +202,7 @@ func (clctrl *ClusterController) RepositoryPush() error { gitopsDir := clctrl.ProviderConfig.GitopsDir metaphorDir := clctrl.ProviderConfig.MetaphorDir - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushStarted, "") gitopsRepo, err := git.PlainOpen(gitopsDir) if err != nil { log.Infof("error opening repo at: %s", gitopsDir) @@ -258,7 +258,7 @@ func (clctrl *ClusterController) RepositoryPush() error { ) if err != nil { msg := fmt.Sprintf("error pushing detokenized gitops repository to remote %s: %s", clctrl.ProviderConfig.DestinationGitopsRepoURL, err) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushFailed, msg) + telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushFailed, msg) return fmt.Errorf(msg) } @@ -274,14 +274,14 @@ func (clctrl *ClusterController) RepositoryPush() error { ) if err != nil { msg := fmt.Sprintf("error pushing detokenized metaphor repository to remote %s: %s", clctrl.ProviderConfig.DestinationMetaphorRepoURL, err) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushFailed, msg) + telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushFailed, msg) return fmt.Errorf(msg) } log.Infof("successfully pushed gitops and metaphor repositories to git@%s/%s", clctrl.GitHost, clctrl.GitAuth.Owner) // todo delete the local gitops repo and re-clone it // todo that way we can stop worrying about which origin we're going to push to - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushCompleted, "") err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "gitops_pushed_check", true) if err != nil { diff --git a/internal/controller/state.go b/internal/controller/state.go index 52d44e4f..b5a324e9 100644 --- a/internal/controller/state.go +++ b/internal/controller/state.go @@ -13,10 +13,10 @@ import ( "strings" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg/civo" "github.com/kubefirst/runtime/pkg/digitalocean" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/vultr" log "github.com/sirupsen/logrus" ) @@ -107,7 +107,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error { if err != nil { msg := fmt.Sprintf("error creating spaces bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err) log.Error(msg) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, msg) + telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, msg) return fmt.Errorf(msg) } @@ -133,7 +133,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error { if err != nil { msg := fmt.Sprintf("error creating google bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err) log.Error(msg) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, msg) + telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, msg) return fmt.Errorf(msg) } @@ -148,7 +148,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error { objst, err := vultrConf.CreateObjectStorage(clctrl.KubefirstStateStoreBucketName) if err != nil { - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, err.Error()) + telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, err.Error()) log.Error(err.Error()) return err } @@ -216,14 +216,14 @@ func (clctrl *ClusterController) StateStoreCreate() error { Context: context.Background(), } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateStarted, "") accessKeyId := cl.StateStoreCredentials.AccessKeyID log.Infof("access key id %s", accessKeyId) bucket, err := civoConf.CreateStorageBucket(accessKeyId, clctrl.KubefirstStateStoreBucketName, clctrl.CloudRegion) if err != nil { - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, err.Error()) + telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, err.Error()) log.Error(err.Error()) return err } @@ -243,7 +243,7 @@ func (clctrl *ClusterController) StateStoreCreate() error { return err } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateCompleted, "") log.Infof("%s state store bucket created", clctrl.CloudProvider) } } diff --git a/internal/controller/users.go b/internal/controller/users.go index 4a925c17..7b8b3d93 100644 --- a/internal/controller/users.go +++ b/internal/controller/users.go @@ -16,8 +16,8 @@ import ( terraformext "github.com/kubefirst/kubefirst-api/extensions/terraform" vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -60,7 +60,7 @@ func (clctrl *ClusterController) RunUsersTerraform() error { } } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricUsersTerraformApplyStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricUsersTerraformApplyStarted, "") log.Info("applying users terraform") tfEnvs := map[string]string{} @@ -88,11 +88,11 @@ func (clctrl *ClusterController) RunUsersTerraform() error { err = terraformext.InitApplyAutoApprove(terraformClient, tfEntrypoint, tfEnvs) if err != nil { log.Errorf("error applying users terraform: %s", err) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricUsersTerraformApplyStarted, err.Error()) + telemetryShim.Transmit(segmentClient, segment.MetricUsersTerraformApplyStarted, err.Error()) return err } log.Info("executed users terraform successfully") - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricUsersTerraformApplyCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricUsersTerraformApplyCompleted, "") clctrl.VaultAuth.RootToken = tfEnvs["VAULT_TOKEN"] err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "vault_auth.root_token", clctrl.VaultAuth.RootToken) diff --git a/internal/controller/vault.go b/internal/controller/vault.go index 98065920..61b79c21 100644 --- a/internal/controller/vault.go +++ b/internal/controller/vault.go @@ -23,8 +23,8 @@ import ( terraformext "github.com/kubefirst/kubefirst-api/extensions/terraform" vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" vault "github.com/kubefirst/runtime/pkg/vault" log "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" @@ -104,7 +104,7 @@ func (clctrl *ClusterController) InitializeVault() error { } } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricVaultInitializationStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricVaultInitializationStarted, "") switch clctrl.CloudProvider { case "aws", "google": @@ -158,12 +158,12 @@ func (clctrl *ClusterController) InitializeVault() error { _, err = k8s.WaitForJobComplete(kcfg.Clientset, job, 240) if err != nil { msg := fmt.Sprintf("could not run vault unseal job: %s", err) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricVaultInitializationFailed, msg) + telemetryShim.Transmit(segmentClient, segment.MetricVaultInitializationFailed, msg) log.Error(msg) } } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricVaultInitializationCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricVaultInitializationCompleted, "") err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "vault_initialized_check", true) if err != nil { @@ -213,7 +213,7 @@ func (clctrl *ClusterController) RunVaultTerraform() error { } } - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricVaultTerraformApplyStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricVaultTerraformApplyStarted, "") tfEnvs := map[string]string{} @@ -267,12 +267,12 @@ func (clctrl *ClusterController) RunVaultTerraform() error { err = terraformext.InitApplyAutoApprove(terraformClient, tfEntrypoint, tfEnvs) if err != nil { log.Errorf("error applying vault terraform: %s", err) - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricVaultTerraformApplyFailed, err.Error()) + telemetryShim.Transmit(segmentClient, segment.MetricVaultTerraformApplyFailed, err.Error()) return err } log.Info("vault terraform executed successfully") - telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricVaultTerraformApplyCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricVaultTerraformApplyCompleted, "") err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "vault_terraform_apply_check", true) if err != nil { diff --git a/internal/router/api/v1/telemetry.go b/internal/router/api/v1/telemetry.go index cf71aad0..6122c3ac 100644 --- a/internal/router/api/v1/telemetry.go +++ b/internal/router/api/v1/telemetry.go @@ -72,7 +72,7 @@ func PostTelemetry(c *gin.Context) { } defer segmentClient.Client.Close() - telemetryShim.Transmit(useTelemetry, segmentClient, req.Event, "") + telemetryShim.Transmit(segmentClient, req.Event, "") c.JSON(http.StatusOK, true) } diff --git a/internal/telemetryShim/heartbeat.go b/internal/telemetryShim/heartbeat.go index b4105e90..1df69070 100644 --- a/internal/telemetryShim/heartbeat.go +++ b/internal/telemetryShim/heartbeat.go @@ -11,8 +11,8 @@ import ( "github.com/kubefirst/kubefirst-api/internal/constants" "github.com/kubefirst/kubefirst-api/internal/db" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) diff --git a/pkg/segment/send.go b/pkg/segment/send.go index c7fa9c1f..cccb494d 100644 --- a/pkg/segment/send.go +++ b/pkg/segment/send.go @@ -3,8 +3,6 @@ package segment import ( "fmt" - "github.com/denisbrodbeck/machineid" - "github.com/kubefirst/runtime/pkg" "github.com/segmentio/analytics-go" ) @@ -13,34 +11,29 @@ func (c *SegmentClient) SendCountMetric( metricName string, errorMessage string, ) string { - strippedDomainName, err := pkg.RemoveSubdomainV2(c.DomainName) - if err != nil { - return "error stripping domain name from value" - } - machineID, _ := machineid.ID() if metricName == MetricInitStarted { err := c.Client.Enqueue(analytics.Identify{ - UserId: strippedDomainName, + UserId: c.DomainName, Type: "identify", }) if err != nil { return fmt.Sprintf("error sending identify to segment: %s", err.Error()) } } - err = c.Client.Enqueue(analytics.Track{ - UserId: strippedDomainName, + err := c.Client.Enqueue(analytics.Track{ + UserId: c.DomainName, Event: metricName, Properties: analytics.NewProperties(). Set("cli_version", c.CliVersion). Set("cloud_provider", c.CloudProvider). Set("cluster_id", c.ClusterID). Set("cluster_type", c.ClusterType). - Set("domain", strippedDomainName). + Set("domain", c.DomainName). Set("git_provider", c.GitProvider). Set("client", c.KubefirstClient). Set("kubefirst_team", c.KubefirstTeam). Set("kubefirst_team_info", c.KubefirstTeamInfo). - Set("machine_id", machineID). + Set("machine_id", c.MachineID). Set("error", errorMessage). Set("install_method", c.InstallMethod), }) diff --git a/providers/aws/create.go b/providers/aws/create.go index 4717c4a1..92c32b27 100644 --- a/providers/aws/create.go +++ b/providers/aws/create.go @@ -13,10 +13,10 @@ import ( "github.com/kubefirst/kubefirst-api/internal/db" "github.com/kubefirst/kubefirst-api/internal/services" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" awsinternal "github.com/kubefirst/runtime/pkg/aws" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -264,7 +264,7 @@ func CreateAWSCluster(definition *pkgtypes.ClusterDefinition) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(rec.UseTelemetry, segmentClient, segment.MetricClusterInstallCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/aws/delete.go b/providers/aws/delete.go index aae0fef0..6a77cd31 100644 --- a/providers/aws/delete.go +++ b/providers/aws/delete.go @@ -21,13 +21,13 @@ import ( "github.com/kubefirst/kubefirst-api/internal/errors" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg" "github.com/kubefirst/runtime/pkg/argocd" awsinternal "github.com/kubefirst/runtime/pkg/aws" gitlab "github.com/kubefirst/runtime/pkg/gitlab" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -49,7 +49,7 @@ func DeleteAWSCluster(cl *pkgtypes.Cluster) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteStarted, "") // Instantiate aws config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.APIToken, cl.CloudflareAuth.OriginCaIssuerKey) @@ -261,7 +261,7 @@ func DeleteAWSCluster(cl *pkgtypes.Cluster) error { } } - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteCompleted, "") err = db.Client.UpdateCluster(cl.ClusterName, "status", constants.ClusterStatusDeleted) if err != nil { diff --git a/providers/civo/create.go b/providers/civo/create.go index de8c275d..e95a98fa 100644 --- a/providers/civo/create.go +++ b/providers/civo/create.go @@ -14,9 +14,9 @@ import ( "github.com/kubefirst/kubefirst-api/internal/db" "github.com/kubefirst/kubefirst-api/internal/services" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/ssl" log "github.com/sirupsen/logrus" ) @@ -249,7 +249,7 @@ func CreateCivoCluster(definition *pkgtypes.ClusterDefinition) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(rec.UseTelemetry, segmentClient, segment.MetricClusterInstallCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/civo/delete.go b/providers/civo/delete.go index a64e2cdc..a199f28d 100644 --- a/providers/civo/delete.go +++ b/providers/civo/delete.go @@ -22,12 +22,12 @@ import ( "github.com/kubefirst/kubefirst-api/internal/errors" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg" "github.com/kubefirst/runtime/pkg/argocd" gitlab "github.com/kubefirst/runtime/pkg/gitlab" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -49,7 +49,7 @@ func DeleteCivoCluster(cl *pkgtypes.Cluster) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteStarted, "") // Instantiate civo config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.APIToken, cl.CloudflareAuth.OriginCaIssuerKey) @@ -257,7 +257,7 @@ func DeleteCivoCluster(cl *pkgtypes.Cluster) error { } } - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteCompleted, "") err = db.Client.UpdateCluster(cl.ClusterName, "status", constants.ClusterStatusDeleted) if err != nil { diff --git a/providers/digitalocean/create.go b/providers/digitalocean/create.go index cc61ce68..62c234a4 100644 --- a/providers/digitalocean/create.go +++ b/providers/digitalocean/create.go @@ -14,9 +14,9 @@ import ( "github.com/kubefirst/kubefirst-api/internal/db" "github.com/kubefirst/kubefirst-api/internal/services" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/ssl" log "github.com/sirupsen/logrus" ) @@ -243,7 +243,7 @@ func CreateDigitaloceanCluster(definition *pkgtypes.ClusterDefinition) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(rec.UseTelemetry, segmentClient, segment.MetricClusterInstallCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/digitalocean/delete.go b/providers/digitalocean/delete.go index 60c41605..3f1265c4 100644 --- a/providers/digitalocean/delete.go +++ b/providers/digitalocean/delete.go @@ -22,13 +22,13 @@ import ( "github.com/kubefirst/kubefirst-api/internal/errors" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg" "github.com/kubefirst/runtime/pkg/argocd" "github.com/kubefirst/runtime/pkg/digitalocean" gitlab "github.com/kubefirst/runtime/pkg/gitlab" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -50,7 +50,7 @@ func DeleteDigitaloceanCluster(cl *pkgtypes.Cluster) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteStarted, "") // Instantiate digitalocean config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.Token, "") @@ -287,7 +287,7 @@ func DeleteDigitaloceanCluster(cl *pkgtypes.Cluster) error { } } - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteCompleted, "") err = db.Client.UpdateCluster(cl.ClusterName, "status", constants.ClusterStatusDeleted) if err != nil { diff --git a/providers/google/create.go b/providers/google/create.go index e5fbc4d4..06c128aa 100644 --- a/providers/google/create.go +++ b/providers/google/create.go @@ -16,9 +16,9 @@ import ( "github.com/kubefirst/kubefirst-api/internal/services" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" "github.com/kubefirst/kubefirst-api/pkg/google" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -267,7 +267,7 @@ func CreateGoogleCluster(definition *pkgtypes.ClusterDefinition) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(rec.UseTelemetry, segmentClient, segment.MetricClusterInstallCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/google/delete.go b/providers/google/delete.go index 49439ec5..091a543b 100644 --- a/providers/google/delete.go +++ b/providers/google/delete.go @@ -23,12 +23,12 @@ import ( "github.com/kubefirst/kubefirst-api/internal/telemetryShim" "github.com/kubefirst/kubefirst-api/pkg/google" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg" "github.com/kubefirst/runtime/pkg/argocd" gitlab "github.com/kubefirst/runtime/pkg/gitlab" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" log "github.com/sirupsen/logrus" ) @@ -50,7 +50,7 @@ func DeleteGoogleCluster(cl *pkgtypes.Cluster) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteStarted, "") // Instantiate google config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.Token, "") @@ -259,7 +259,7 @@ func DeleteGoogleCluster(cl *pkgtypes.Cluster) error { } } - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteCompleted, "") err = db.Client.UpdateCluster(cl.ClusterName, "status", constants.ClusterStatusDeleted) if err != nil { diff --git a/providers/vultr/create.go b/providers/vultr/create.go index 3e4053a3..2a268a4b 100644 --- a/providers/vultr/create.go +++ b/providers/vultr/create.go @@ -14,9 +14,9 @@ import ( "github.com/kubefirst/kubefirst-api/internal/db" "github.com/kubefirst/kubefirst-api/internal/services" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/ssl" log "github.com/sirupsen/logrus" ) @@ -241,7 +241,7 @@ func CreateVultrCluster(definition *pkgtypes.ClusterDefinition) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(rec.UseTelemetry, segmentClient, segment.MetricClusterInstallCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/vultr/delete.go b/providers/vultr/delete.go index c9cf933e..9b017b9b 100644 --- a/providers/vultr/delete.go +++ b/providers/vultr/delete.go @@ -22,12 +22,12 @@ import ( "github.com/kubefirst/kubefirst-api/internal/errors" "github.com/kubefirst/kubefirst-api/internal/telemetryShim" "github.com/kubefirst/kubefirst-api/pkg/providerConfigs" + "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" runtime "github.com/kubefirst/runtime/pkg" "github.com/kubefirst/runtime/pkg/argocd" gitlab "github.com/kubefirst/runtime/pkg/gitlab" "github.com/kubefirst/runtime/pkg/k8s" - "github.com/kubefirst/runtime/pkg/segment" "github.com/kubefirst/runtime/pkg/vultr" log "github.com/sirupsen/logrus" ) @@ -50,7 +50,7 @@ func DeleteVultrCluster(cl *pkgtypes.Cluster) error { } defer segmentClient.Client.Close() - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteStarted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteStarted, "") // Instantiate vultr config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.Token, "") @@ -287,7 +287,7 @@ func DeleteVultrCluster(cl *pkgtypes.Cluster) error { } } - telemetryShim.Transmit(cl.UseTelemetry, segmentClient, segment.MetricClusterDeleteCompleted, "") + telemetryShim.Transmit(segmentClient, segment.MetricClusterDeleteCompleted, "") err = db.Client.UpdateCluster(cl.ClusterName, "status", constants.ClusterStatusDeleted) if err != nil {