From a3f42f53c09418e19e8e7a03290b295402316fa8 Mon Sep 17 00:00:00 2001 From: Jared Edwards Date: Sat, 21 Oct 2023 21:41:46 -0600 Subject: [PATCH] move metrics and types back to metrics client --- internal/controller/argocd.go | 10 +++++----- internal/controller/cluster.go | 6 +++--- internal/controller/controller.go | 7 +++---- internal/controller/domain.go | 6 +++--- internal/controller/git.go | 6 +++--- internal/controller/kbot.go | 2 +- internal/controller/repository.go | 8 ++++---- internal/controller/state.go | 14 +++++++------- internal/controller/users.go | 6 +++--- internal/controller/vault.go | 12 ++++++------ internal/router/api/v1/cluster.go | 3 +-- internal/router/api/v1/telemetry.go | 5 ++--- internal/telemetry/heartbeat.go | 9 ++++----- pkg/segment/segment.go | 6 +++--- providers/aws/create.go | 2 +- providers/aws/delete.go | 4 ++-- providers/civo/create.go | 2 +- providers/civo/delete.go | 4 ++-- providers/digitalocean/create.go | 2 +- providers/digitalocean/delete.go | 4 ++-- providers/google/create.go | 2 +- providers/google/delete.go | 4 ++-- providers/vultr/create.go | 2 +- providers/vultr/delete.go | 4 ++-- 24 files changed, 63 insertions(+), 67 deletions(-) diff --git a/internal/controller/argocd.go b/internal/controller/argocd.go index e64bbcd1..1a9e3002 100644 --- a/internal/controller/argocd.go +++ b/internal/controller/argocd.go @@ -56,16 +56,16 @@ func (clctrl *ClusterController) InstallArgoCD() error { argoCDInstallPath := fmt.Sprintf("github.com:kubefirst/manifests/argocd/cloud?ref=%s", pkg.KubefirstManifestRepoRef) log.Infof("installing argocd") - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.ArgoCDInstallStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.ArgoCDInstallStarted, err.Error()) err = argocd.ApplyArgoCDKustomize(kcfg.Clientset, argoCDInstallPath) if err != nil { - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.ArgoCDInstallFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.ArgoCDInstallFailed, err.Error()) return err } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.ArgoCDInstallCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.ArgoCDInstallCompleted, err.Error()) // Wait for ArgoCD to be ready _, err = k8s.VerifyArgoCDReadiness(kcfg.Clientset, true, 300) @@ -194,7 +194,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error { } } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CreateRegistryStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.CreateRegistryStarted, err.Error()) argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig) if err != nil { return err @@ -239,7 +239,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error { _, _ = argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{}) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CreateRegistryCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.CreateRegistryCompleted, err.Error()) 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 140bc371..8feedb7c 100644 --- a/internal/controller/cluster.go +++ b/internal/controller/cluster.go @@ -50,7 +50,7 @@ func (clctrl *ClusterController) CreateCluster() error { tfEntrypoint := clctrl.ProviderConfig.GitopsDir + fmt.Sprintf("/terraform/%s", clctrl.CloudProvider) tfEnvs := map[string]string{} - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CloudTerraformApplyStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.CloudTerraformApplyStarted, err.Error()) log.Infof("creating %s cluster", clctrl.CloudProvider) @@ -86,12 +86,12 @@ func (clctrl *ClusterController) CreateCluster() error { if err != nil { return err } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CloudTerraformApplyFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.CloudTerraformApplyFailed, err.Error()) return fmt.Errorf(msg) } log.Infof("created %s cloud resources", clctrl.CloudProvider) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CloudTerraformApplyCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.CloudTerraformApplyCompleted, err.Error()) 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 cf6e4c54..73568ca3 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -20,7 +20,6 @@ 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/metrics-client/pkg/telemetry" "github.com/kubefirst/runtime/pkg" @@ -172,7 +171,7 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition) UserId: machineID, MetricName: telemetry.ClusterInstallStarted, }, - Client: analytics.New(segment.SegmentIOWriteKey), + Client: analytics.New(telemetry.SegmentIOWriteKey), } if err != nil { log.Warn(err) @@ -180,9 +179,9 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition) defer segClient.Client.Close() if clctrl.SegmentClient.UseTelemetry { - telemetry.SendCountMetric(&segClient, telemetry.ClusterInstallStarted, err.Error()) + telemetry.SendEvent(&segClient, telemetry.ClusterInstallStarted, err.Error()) } - clctrl.Telemetry = &segClient + clctrl.SegmentClient = &segClient //Copy Cluster Definiion to Cluster Controller clctrl.AlertsEmail = def.AdminEmail diff --git a/internal/controller/domain.go b/internal/controller/domain.go index 57e0950a..c1fe52fb 100644 --- a/internal/controller/domain.go +++ b/internal/controller/domain.go @@ -27,7 +27,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error { } if !cl.DomainLivenessCheck { - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.DomainLivenessStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.DomainLivenessStarted, err.Error()) switch clctrl.DnsProvider { case "aws": @@ -46,7 +46,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error { // domain id domainId, err := civoConf.GetDNSInfo(clctrl.DomainName, clctrl.CloudRegion) if err != nil { - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.DomainLivenessFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.DomainLivenessFailed, err.Error()) log.Info(err.Error()) } @@ -121,7 +121,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error { return err } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.DomainLivenessCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.DomainLivenessCompleted, err.Error()) log.Infof("domain %s verified", clctrl.DomainName) } diff --git a/internal/controller/git.go b/internal/controller/git.go index 5ddbdbee..f2668ee5 100644 --- a/internal/controller/git.go +++ b/internal/controller/git.go @@ -72,7 +72,7 @@ func (clctrl *ClusterController) RunGitTerraform() error { } // //* create teams and repositories in github - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitTerraformApplyStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.GitTerraformApplyStarted, err.Error()) log.Infof("Creating %s resources with terraform", clctrl.GitProvider) @@ -113,12 +113,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) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitTerraformApplyFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.GitTerraformApplyFailed, err.Error()) return fmt.Errorf(msg) } log.Infof("created git projects and groups for %s.com/%s", clctrl.GitProvider, clctrl.GitAuth.Owner) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitTerraformApplyCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.GitTerraformApplyCompleted, err.Error()) 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 baefbe0f..16c89a64 100644 --- a/internal/controller/kbot.go +++ b/internal/controller/kbot.go @@ -34,7 +34,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) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.KbotSetupFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.KbotSetupFailed, err.Error()) return err } diff --git a/internal/controller/repository.go b/internal/controller/repository.go index 17529b3f..bce252b3 100644 --- a/internal/controller/repository.go +++ b/internal/controller/repository.go @@ -194,7 +194,7 @@ func (clctrl *ClusterController) RepositoryPush() error { gitopsDir := clctrl.ProviderConfig.GitopsDir metaphorDir := clctrl.ProviderConfig.MetaphorDir - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.GitopsRepoPushStarted, err.Error()) gitopsRepo, err := git.PlainOpen(gitopsDir) if err != nil { log.Infof("error opening repo at: %s", gitopsDir) @@ -250,7 +250,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) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.GitopsRepoPushFailed, err.Error()) return fmt.Errorf(msg) } @@ -266,14 +266,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) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.GitopsRepoPushFailed, err.Error()) 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 - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.GitopsRepoPushCompleted, err.Error()) 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 9c181671..371e6ce6 100644 --- a/internal/controller/state.go +++ b/internal/controller/state.go @@ -37,7 +37,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error { } var stateStoreData pkgtypes.StateStoreCredentials - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCredentialsCreateStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.StateStoreCredentialsCreateStarted, err.Error()) if !cl.StateStoreCredsCheck { switch clctrl.CloudProvider { @@ -100,7 +100,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error { if err != nil { msg := fmt.Sprintf("error creating spaces bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err) log.Error(msg) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCredentialsCreateFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.StateStoreCredentialsCreateFailed, err.Error()) return fmt.Errorf(msg) } @@ -126,7 +126,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error { if err != nil { msg := fmt.Sprintf("error creating google bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err) log.Error() - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, msg) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, msg) return fmt.Errorf(msg) } @@ -141,7 +141,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error { objst, err := vultrConf.CreateObjectStorage(clctrl.KubefirstStateStoreBucketName) if err != nil { - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, err.Error()) log.Error(err.Error()) return err } @@ -202,14 +202,14 @@ func (clctrl *ClusterController) StateStoreCreate() error { Context: context.Background(), } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.StateStoreCreateStarted, err.Error()) accessKeyId := cl.StateStoreCredentials.AccessKeyID log.Infof("access key id %s", accessKeyId) bucket, err := civoConf.CreateStorageBucket(accessKeyId, clctrl.KubefirstStateStoreBucketName, clctrl.CloudRegion) if err != nil { - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, err.Error()) log.Error(err.Error()) return err } @@ -229,7 +229,7 @@ func (clctrl *ClusterController) StateStoreCreate() error { return err } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.StateStoreCreateCompleted, err.Error()) log.Infof("%s state store bucket created", clctrl.CloudProvider) } } diff --git a/internal/controller/users.go b/internal/controller/users.go index 1824da99..73179403 100644 --- a/internal/controller/users.go +++ b/internal/controller/users.go @@ -52,7 +52,7 @@ func (clctrl *ClusterController) RunUsersTerraform() error { } } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.UsersTerraformApplyStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.UsersTerraformApplyStarted, err.Error()) log.Info("applying users terraform") tfEnvs := map[string]string{} @@ -80,11 +80,11 @@ func (clctrl *ClusterController) RunUsersTerraform() error { err = terraformext.InitApplyAutoApprove(terraformClient, tfEntrypoint, tfEnvs) if err != nil { log.Errorf("error applying users terraform: %s", err) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.UsersTerraformApplyFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.UsersTerraformApplyFailed, err.Error()) return err } log.Info("executed users terraform successfully") - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.UsersTerraformApplyCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.UsersTerraformApplyCompleted, err.Error()) 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 fab02d22..691cdbee 100644 --- a/internal/controller/vault.go +++ b/internal/controller/vault.go @@ -96,7 +96,7 @@ func (clctrl *ClusterController) InitializeVault() error { } } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.VaultInitializationStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.VaultInitializationStarted, err.Error()) switch clctrl.CloudProvider { case "aws", "google": @@ -150,11 +150,11 @@ 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) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.VaultInitializationFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.VaultInitializationFailed, err.Error()) log.Error(msg) } } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.VaultInitializationCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.VaultInitializationCompleted, err.Error()) err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "vault_initialized_check", true) if err != nil { @@ -196,7 +196,7 @@ func (clctrl *ClusterController) RunVaultTerraform() error { return err } } - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.VaultTerraformApplyStarted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.VaultTerraformApplyStarted, err.Error()) tfEnvs := map[string]string{} @@ -250,12 +250,12 @@ func (clctrl *ClusterController) RunVaultTerraform() error { err = terraformext.InitApplyAutoApprove(terraformClient, tfEntrypoint, tfEnvs) if err != nil { log.Errorf("error applying vault terraform: %s", err) - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.VaultTerraformApplyFailed, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.VaultTerraformApplyFailed, err.Error()) return err } log.Info("vault terraform executed successfully") - telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.VaultTerraformApplyCompleted, err.Error()) + telemetry.SendEvent(clctrl.SegmentClient, telemetry.VaultTerraformApplyCompleted, err.Error()) err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "vault_terraform_apply_check", true) if err != nil { diff --git a/internal/router/api/v1/cluster.go b/internal/router/api/v1/cluster.go index a35d3fb5..2b2eabb0 100644 --- a/internal/router/api/v1/cluster.go +++ b/internal/router/api/v1/cluster.go @@ -20,7 +20,6 @@ import ( "github.com/kubefirst/kubefirst-api/internal/services" "github.com/kubefirst/kubefirst-api/internal/types" "github.com/kubefirst/kubefirst-api/internal/utils" - "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/kubefirst/kubefirst-api/providers/aws" "github.com/kubefirst/kubefirst-api/providers/civo" @@ -82,7 +81,7 @@ func DeleteCluster(c *gin.Context) { UserId: machineID, MetricName: telemetry.ClusterDeleteStarted, }, - Client: analytics.New(segment.SegmentIOWriteKey), + Client: analytics.New(telemetry.SegmentIOWriteKey), } defer segClient.Client.Close() diff --git a/internal/router/api/v1/telemetry.go b/internal/router/api/v1/telemetry.go index e963fe34..d30c0a7a 100644 --- a/internal/router/api/v1/telemetry.go +++ b/internal/router/api/v1/telemetry.go @@ -14,7 +14,6 @@ import ( "github.com/gin-gonic/gin" "github.com/kubefirst/kubefirst-api/internal/db" "github.com/kubefirst/kubefirst-api/internal/types" - "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/metrics-client/pkg/telemetry" "github.com/segmentio/analytics-go" ) @@ -55,7 +54,7 @@ func PostTelemetry(c *gin.Context) { UserId: machineID, MetricName: telemetry.ClusterDeleteStarted, }, - Client: analytics.New(segment.SegmentIOWriteKey), + Client: analytics.New(telemetry.SegmentIOWriteKey), } defer segClient.Client.Close() useTelemetry := true @@ -94,7 +93,7 @@ func PostTelemetry(c *gin.Context) { return } - telemetry.SendCountMetric(&segClient, req.Event, err.Error()) + telemetry.SendEvent(&segClient, req.Event, err.Error()) c.JSON(http.StatusOK, true) } diff --git a/internal/telemetry/heartbeat.go b/internal/telemetry/heartbeat.go index a3a90f70..43c58b5c 100644 --- a/internal/telemetry/heartbeat.go +++ b/internal/telemetry/heartbeat.go @@ -5,17 +5,16 @@ import ( "github.com/kubefirst/kubefirst-api/internal/constants" "github.com/kubefirst/kubefirst-api/internal/db" - "github.com/kubefirst/kubefirst-api/pkg/segment" "github.com/kubefirst/metrics-client/pkg/telemetry" "github.com/segmentio/analytics-go" ) func Heartbeat(segmentClient *telemetry.SegmentClient, dbClient *db.MongoDBClient) { - telemetry.SendCountMetric(segmentClient, telemetry.KubefirstHeartbeat, "") + telemetry.SendEvent(segmentClient, telemetry.KubefirstHeartbeat, "") HeartbeatWorkloadClusters(segmentClient, dbClient) for range time.Tick(time.Second * 30) { - telemetry.SendCountMetric(segmentClient, telemetry.KubefirstHeartbeat, "") + telemetry.SendEvent(segmentClient, telemetry.KubefirstHeartbeat, "") HeartbeatWorkloadClusters(segmentClient, dbClient) } } @@ -46,11 +45,11 @@ func HeartbeatWorkloadClusters(segmentClient *telemetry.SegmentClient, dbClient UserId: segmentClient.TelemetryEvent.MachineID, MetricName: telemetry.KubefirstHeartbeat, }, - Client: analytics.New(segment.SegmentIOWriteKey), + Client: analytics.New(telemetry.SegmentIOWriteKey), } defer workloadClient.Client.Close() - telemetry.SendCountMetric(&workloadClient, telemetry.KubefirstHeartbeat, "") + telemetry.SendEvent(&workloadClient, telemetry.KubefirstHeartbeat, "") } } } diff --git a/pkg/segment/segment.go b/pkg/segment/segment.go index c05d9928..6cd94092 100644 --- a/pkg/segment/segment.go +++ b/pkg/segment/segment.go @@ -4,9 +4,8 @@ import ( "os" "github.com/denisbrodbeck/machineid" - "github.com/kubefirst/runtime/pkg/segment" - "github.com/kubefirst/metrics-client/pkg/telemetry" + "github.com/segmentio/analytics-go" ) @@ -17,6 +16,7 @@ const ( func InitClient() *telemetry.SegmentClient { machineID, _ := machineid.ID() + sc := analytics.New(telemetry.SegmentIOWriteKey) c := telemetry.SegmentClient{ TelemetryEvent: telemetry.TelemetryEvent{ @@ -35,7 +35,7 @@ func InitClient() *telemetry.SegmentClient { UserId: machineID, MetricName: telemetry.KubefirstHeartbeat, }, - Client: analytics.New(segment.SegmentIOWriteKey), + Client: sc, } return &c diff --git a/providers/aws/create.go b/providers/aws/create.go index fea4e3b2..911a2083 100644 --- a/providers/aws/create.go +++ b/providers/aws/create.go @@ -256,7 +256,7 @@ func CreateAWSCluster(definition *pkgtypes.ClusterDefinition) error { log.Info("cluster creation complete") - telemetry.SendCountMetric(ctrl.Telemetry, telemetry.ClusterInstallCompleted, err.Error()) + telemetry.SendEvent(ctrl.SegmentClient, telemetry.ClusterInstallCompleted, err.Error()) // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/aws/delete.go b/providers/aws/delete.go index 2bbc6e60..c7e35fd2 100644 --- a/providers/aws/delete.go +++ b/providers/aws/delete.go @@ -41,7 +41,7 @@ func DeleteAWSCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentClie log.SetReportCaller(false) log.SetOutput(os.Stdout) - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteStarted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteStarted, "") // Instantiate aws config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.APIToken, cl.CloudflareAuth.OriginCaIssuerKey) @@ -253,7 +253,7 @@ func DeleteAWSCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentClie } } - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteCompleted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteCompleted, "") 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 f7a7a2bf..9f41bd2c 100644 --- a/providers/civo/create.go +++ b/providers/civo/create.go @@ -236,7 +236,7 @@ func CreateCivoCluster(definition *pkgtypes.ClusterDefinition) error { log.Info("cluster creation complete") - telemetry.SendCountMetric(ctrl.Telemetry, telemetry.ClusterInstallCompleted, "") + telemetry.SendEvent(ctrl.SegmentClient, telemetry.ClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/civo/delete.go b/providers/civo/delete.go index de2511b3..3db58127 100644 --- a/providers/civo/delete.go +++ b/providers/civo/delete.go @@ -41,7 +41,7 @@ func DeleteCivoCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentCli log.SetReportCaller(false) log.SetOutput(os.Stdout) - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteStarted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteStarted, "") // Instantiate civo config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.APIToken, cl.CloudflareAuth.OriginCaIssuerKey) @@ -249,7 +249,7 @@ func DeleteCivoCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentCli } } - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteCompleted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteCompleted, "") 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 4e5b84f8..8fa915b2 100644 --- a/providers/digitalocean/create.go +++ b/providers/digitalocean/create.go @@ -231,7 +231,7 @@ func CreateDigitaloceanCluster(definition *pkgtypes.ClusterDefinition) error { // Telemetry handler - telemetry.SendCountMetric(ctrl.Telemetry, telemetry.ClusterInstallCompleted, "") + telemetry.SendEvent(ctrl.SegmentClient, telemetry.ClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/digitalocean/delete.go b/providers/digitalocean/delete.go index a0b520a0..3f2863f6 100644 --- a/providers/digitalocean/delete.go +++ b/providers/digitalocean/delete.go @@ -42,7 +42,7 @@ func DeleteDigitaloceanCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.Se log.SetReportCaller(false) log.SetOutput(os.Stdout) - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteStarted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteStarted, "") // Instantiate digitalocean config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.Token, "") @@ -279,7 +279,7 @@ func DeleteDigitaloceanCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.Se } } - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteCompleted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteCompleted, "") 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 fe742377..b6cc545b 100644 --- a/providers/google/create.go +++ b/providers/google/create.go @@ -253,7 +253,7 @@ func CreateGoogleCluster(definition *pkgtypes.ClusterDefinition) error { log.Info("cluster creation complete") - telemetry.SendCountMetric(ctrl.Telemetry, telemetry.ClusterInstallCompleted, "") + telemetry.SendEvent(ctrl.SegmentClient, telemetry.ClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/google/delete.go b/providers/google/delete.go index 5138e1b3..0648a9d1 100644 --- a/providers/google/delete.go +++ b/providers/google/delete.go @@ -42,7 +42,7 @@ func DeleteGoogleCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentC log.SetReportCaller(false) log.SetOutput(os.Stdout) - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteStarted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteStarted, "") // Instantiate google config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.Token, "") @@ -251,7 +251,7 @@ func DeleteGoogleCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentC } } - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteCompleted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteCompleted, "") 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 c51a5efe..0518ff1a 100644 --- a/providers/vultr/create.go +++ b/providers/vultr/create.go @@ -227,7 +227,7 @@ func CreateVultrCluster(definition *pkgtypes.ClusterDefinition) error { log.Info("cluster creation complete") - telemetry.SendCountMetric(ctrl.Telemetry, telemetry.ClusterInstallCompleted, "") + telemetry.SendEvent(ctrl.SegmentClient, telemetry.ClusterInstallCompleted, "") // Create default service entries cl, _ := db.Client.GetCluster(ctrl.ClusterName) diff --git a/providers/vultr/delete.go b/providers/vultr/delete.go index 700b4f54..083a2775 100644 --- a/providers/vultr/delete.go +++ b/providers/vultr/delete.go @@ -42,7 +42,7 @@ func DeleteVultrCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentCl log.SetReportCaller(false) log.SetOutput(os.Stdout) - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteStarted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteStarted, "") // Instantiate vultr config config := providerConfigs.GetConfig(cl.ClusterName, cl.DomainName, cl.GitProvider, cl.GitAuth.Owner, cl.GitProtocol, cl.CloudflareAuth.Token, "") @@ -279,7 +279,7 @@ func DeleteVultrCluster(cl *pkgtypes.Cluster, segmentClient *telemetry.SegmentCl } } - telemetry.SendCountMetric(segmentClient, telemetry.ClusterDeleteCompleted, "") + telemetry.SendEvent(segmentClient, telemetry.ClusterDeleteCompleted, "") err = db.Client.UpdateCluster(cl.ClusterName, "status", constants.ClusterStatusDeleted) if err != nil {