Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adopt latest metrics-client #1955

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func runK3d(cmd *cobra.Command, args []string) error {
}

segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.ClusterInstallStarted, "")
telemetry.SendEvent(segClient, telemetry.ArgoCDInstallCompleted, "")
johndietz marked this conversation as resolved.
Show resolved Hide resolved

// Progress output
progressPrinter.AddTracker("preflight-checks", "Running preflight checks", 5)
Expand Down Expand Up @@ -396,7 +396,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
// Check git credentials
executionControl := viper.GetBool(fmt.Sprintf("kubefirst-checks.%s-credentials", config.GitProvider))
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.GitCredentialsCheckStarted, "")
if len(cGitToken) == 0 {
msg := fmt.Sprintf(
Expand Down Expand Up @@ -431,13 +430,11 @@ func runK3d(cmd *cobra.Command, args []string) error {
var gitopsRepoURL string
executionControl = viper.GetBool("kubefirst-checks.kbot-setup")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.KbotSetupStarted, "")

log.Info().Msg("creating an ssh key pair for your new cloud infrastructure")
sshPrivateKey, sshPublicKey, err = internalssh.CreateSshKeyPair()
if err != nil {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.KbotSetupFailed, err.Error())
return err
}
Expand Down Expand Up @@ -586,7 +583,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
// //* create teams and repositories in github
executionControl = viper.GetBool("kubefirst-checks.terraform-apply-github")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.GitTerraformApplyStarted, "")

log.Info().Msg("Creating GitHub resources with Terraform")
Expand All @@ -608,7 +604,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
}
err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs)
if err != nil {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
msg := fmt.Sprintf("error creating github resources with terraform %s: %s", tfEntrypoint, err)
telemetry.SendEvent(segClient, telemetry.GitTerraformApplyFailed, msg)
return fmt.Errorf(msg)
Expand All @@ -627,7 +622,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
// //* create teams and repositories in gitlab
executionControl = viper.GetBool("kubefirst-checks.terraform-apply-gitlab")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.GitTerraformApplyStarted, "")

log.Info().Msg("Creating GitLab resources with Terraform")
Expand All @@ -650,7 +644,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs)
if err != nil {
msg := fmt.Sprintf("error creating gitlab resources with terraform %s: %s", tfEntrypoint, err)
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.GitTerraformApplyFailed, msg)
return fmt.Errorf(msg)
}
Expand All @@ -675,7 +668,6 @@ func runK3d(cmd *cobra.Command, args []string) error {

executionControl = viper.GetBool("kubefirst-checks.gitops-repo-pushed")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.GitopsRepoPushStarted, "")

gitopsRepo, err := git.PlainOpen(config.GitopsDir)
Expand Down Expand Up @@ -707,7 +699,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
)
if err != nil {
msg := fmt.Sprintf("error pushing detokenized gitops repository to remote %s: %s", config.DestinationGitopsRepoGitURL, err)
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.GitopsRepoPushFailed, msg)
if !strings.Contains(msg, "already up-to-date") {
log.Panic().Msg(msg)
Expand All @@ -723,7 +714,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
)
if err != nil {
msg := fmt.Sprintf("error pushing detokenized metaphor repository to remote %s: %s", config.DestinationMetaphorRepoURL, err)
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.GitopsRepoPushFailed, msg)
if !strings.Contains(msg, "already up-to-date") {
log.Panic().Msg(msg)
Expand All @@ -748,7 +738,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
progressPrinter.SetupProgress(progressPrinter.TotalOfTrackers(), false)

if !viper.GetBool("kubefirst-checks.create-k3d-cluster") {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.CloudTerraformApplyStarted, "")

log.Info().Msg("Creating k3d cluster")
Expand All @@ -758,7 +747,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
msg := fmt.Sprintf("error creating k3d resources with k3d client %s: %s", config.K3dClient, err)
viper.Set("kubefirst-checks.create-k3d-cluster-failed", true)
viper.WriteConfig()
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.CloudTerraformApplyFailed, msg)
return fmt.Errorf(msg)
}
Expand Down Expand Up @@ -897,7 +885,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
//* install argocd
executionControl = viper.GetBool("kubefirst-checks.argocd-install")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.ArgoCDInstallStarted, "")

log.Info().Msgf("installing argocd")
Expand All @@ -913,7 +900,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
}
err = kcfg.ApplyObjects("", output)
if err != nil {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.ArgoCDInstallFailed, err.Error())
return err
}
Expand Down Expand Up @@ -1016,7 +1002,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
//* argocd sync registry and start sync waves
executionControl = viper.GetBool("kubefirst-checks.argocd-create-registry")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.CreateRegistryStarted, "")
argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig)
if err != nil {
Expand Down Expand Up @@ -1066,7 +1051,6 @@ func runK3d(cmd *cobra.Command, args []string) error {

executionControl = viper.GetBool("kubefirst-checks.vault-initialized")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.VaultInitializationStarted, "")

// Initialize and unseal Vault
Expand Down Expand Up @@ -1094,7 +1078,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
_, err = k8s.WaitForJobComplete(kcfg.Clientset, job, 240)
if err != nil {
msg := fmt.Sprintf("could not run vault unseal job: %s", err)
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.VaultInitializationFailed, msg)
log.Fatal().Msg(msg)
}
Expand Down Expand Up @@ -1198,7 +1181,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
//* configure vault with terraform
executionControl = viper.GetBool("kubefirst-checks.terraform-apply-vault")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.VaultTerraformApplyStarted, "")

tfEnvs := map[string]string{}
Expand Down Expand Up @@ -1240,7 +1222,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
tfEntrypoint := config.GitopsDir + "/terraform/vault"
err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs)
if err != nil {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.VaultTerraformApplyStarted, err.Error())
return err
}
Expand All @@ -1261,7 +1242,6 @@ func runK3d(cmd *cobra.Command, args []string) error {

executionControl = viper.GetBool("kubefirst-checks.terraform-apply-users")
if !executionControl {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.UsersTerraformApplyStarted, "")

log.Info().Msg("applying users terraform")
Expand All @@ -1279,7 +1259,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
tfEntrypoint := config.GitopsDir + "/terraform/users"
err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs)
if err != nil {
segClient := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag)
telemetry.SendEvent(segClient, telemetry.UsersTerraformApplyStarted, err.Error())
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/go-git/go-git/v5 v5.6.1
github.com/hashicorp/vault/api v1.9.0
github.com/kubefirst/kubefirst-api v0.1.8
github.com/kubefirst/metrics-client v0.2.8
github.com/kubefirst/metrics-client v0.3.0
github.com/kubefirst/runtime v0.3.35
github.com/rs/zerolog v1.29.1
github.com/segmentio/analytics-go v3.1.0+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ github.com/kubefirst/kubefirst-api v0.1.8 h1:+5AT9pDj4AuH2GCW43Z9U/frEEyemqeZOm3
github.com/kubefirst/kubefirst-api v0.1.8/go.mod h1:Euz7+acib+o9DTkJ3MXRVtPL1rI+vGFZditYG2aXQCY=
github.com/kubefirst/metrics-client v0.2.8 h1:JfaeiBifZD/DpyYW2QVHcrhH/KWA98OmM+7c7M12qMc=
github.com/kubefirst/metrics-client v0.2.8/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc=
github.com/kubefirst/metrics-client v0.3.0 h1:zCug82pEzeWhHhpeYQvdhytRNDxrLxX18dPQ5PSxY3s=
github.com/kubefirst/metrics-client v0.3.0/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc=
github.com/kubefirst/runtime v0.3.35 h1:wn430Irf0E1vc3X0WX3lYBpyhQ5TN6xxMcargILA9uI=
github.com/kubefirst/runtime v0.3.35/go.mod h1:0CnYy+8JTG+/0f3QlkTQJqTT654Su6JXk30OufFVY98=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down
2 changes: 1 addition & 1 deletion internal/segment/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func InitClient(clusterId, clusterType, gitProvider string) telemetry.TelemetryE
KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"),
MachineID: machineID,
ErrorMessage: "",
MetricName: telemetry.ClusterInstallStarted,
MetricName: telemetry.ClusterInstallCompleted,
UserId: machineID,
}

Expand Down