Skip to content

Commit

Permalink
Merge pull request #216 from kubefirst/telemetry-shift
Browse files Browse the repository at this point in the history
telemetry adjustments
  • Loading branch information
johndietz authored Oct 22, 2023
2 parents 826799f + 77dde17 commit d98ce20
Show file tree
Hide file tree
Showing 33 changed files with 336 additions and 633 deletions.
28 changes: 18 additions & 10 deletions charts/kubefirst-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,25 @@ spec:
"transmit",
"--type",
"cluster-zero",
"--cluster-id",
{{ .Values.clusterId | default $clusterId }},
"--cluster-type",
{{ .Values.clusterType | default "bootstrap" | quote }},
"--install-method",
{{ .Values.installMethod | default "helm" | quote }},
"--kubefirst-team",
{{ .Values.kubefirstTeam | default "undefined" | quote }},
"--kubefirst-team-info",
{{ .Values.kubefirstTeamInfo | default "undefined" }}
]
env:
- name: KUBEFIRST_VERSION
value: {{ .Values.global.kubefirstVersion | default "unset" }}
- name: CLOUD_PROVIDER
value: {{ .Values.cloudProvider | default "unset" }}
- name: CLUSTER_ID
value: {{ $clusterId | default "unset" }}
- name: CLUSTER_TYPE
value: {{ .Values.clusterType | default "bootstrap" }}
- name: DOMAIN_NAME
value: {{ .Values.domainName | default "unset" }}
- name: GIT_PROVIDER
value: {{ .Values.gitProvider | default "unset" }}
- name: INSTALL_METHOD
value: {{ .Values.installMethod | default "helm" }}
- name: KUBEFIRST_CLIENT
value: {{ .Values.kubefirstClient | default "api" }} # deprecated
- name: KUBEFIRST_TEAM
value: {{ .Values.kubefirstTeam | default "" }}
- name: KUBEFIRST_TEAM_INFO
value: {{ .Values.kubefirstTeamInfo | default "" }}
11 changes: 11 additions & 0 deletions charts/kubefirst-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,16 @@ mongodbUsername: ''
initContainer:
enabled: false

cloudProvider: ''
clusterId: ''
clusterType: ''
domainName: ''
gitProvider: ''
installMethod: ''
kubefirstClient: ''
kubefirstTeam: ''
kubefirstTeamInfo: ''


global:
kubefirstVersion: ''
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ require (
github.com/google/go-github/v52 v52.0.0
github.com/hashicorp/vault/api v1.9.0
github.com/joho/godotenv v1.5.1
github.com/kubefirst/metrics-client v0.2.1
github.com/kubefirst/runtime v0.3.27
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/rs/zerolog v1.29.1
github.com/segmentio/analytics-go v3.1.0+incompatible
github.com/sirupsen/logrus v1.9.0
github.com/swaggo/files v1.0.0
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,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=
Expand Down Expand Up @@ -1004,8 +1004,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 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
Expand Down
30 changes: 8 additions & 22 deletions internal/controller/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ 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/pkg/segment"
"github.com/kubefirst/kubefirst-api/pkg/telemetryShim"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg"
"github.com/kubefirst/runtime/pkg/argocd"
"github.com/kubefirst/runtime/pkg/k8s"
Expand All @@ -38,13 +37,6 @@ func (clctrl *ClusterController) InstallArgoCD() error {
return err
}

// Telemetry handler
segmentClient, err := telemetryShim.SetupTelemetry(cl)
if err != nil {
return err
}
defer segmentClient.Client.Close()

if !cl.ArgoCDInstallCheck {
var kcfg *k8s.KubernetesClient

Expand All @@ -64,15 +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.SendEvent(clctrl.SegmentClient, telemetry.ArgoCDInstallStarted, err.Error())
err = argocd.ApplyArgoCDKustomize(kcfg.Clientset, argoCDInstallPath)
if err != nil {
telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallFailed, err.Error())

telemetry.SendEvent(clctrl.SegmentClient, telemetry.ArgoCDInstallFailed, err.Error())

return err
}
telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallCompleted, "")

telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallCompleted, "")
telemetry.SendEvent(clctrl.SegmentClient, telemetry.ArgoCDInstallCompleted, err.Error())

// Wait for ArgoCD to be ready
_, err = k8s.VerifyArgoCDReadiness(kcfg.Clientset, true, 300)
Expand Down Expand Up @@ -185,13 +178,6 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
return err
}

// Telemetry handler
segmentClient, err := telemetryShim.SetupTelemetry(cl)
if err != nil {
return err
}
defer segmentClient.Client.Close()

if !cl.ArgoCDCreateRegistryCheck {
var kcfg *k8s.KubernetesClient

Expand All @@ -208,7 +194,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
}
}

telemetryShim.Transmit(segmentClient, segment.MetricCreateRegistryStarted, "")
telemetry.SendEvent(clctrl.SegmentClient, telemetry.CreateRegistryStarted, err.Error())
argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig)
if err != nil {
return err
Expand Down Expand Up @@ -253,7 +239,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {

_, _ = argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{})

telemetryShim.Transmit(segmentClient, segment.MetricCreateRegistryCompleted, "")
telemetry.SendEvent(clctrl.SegmentClient, telemetry.CreateRegistryCompleted, err.Error())

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "argocd_create_registry_check", true)
if err != nil {
Expand Down
24 changes: 5 additions & 19 deletions internal/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr"
gitShim "github.com/kubefirst/kubefirst-api/internal/gitShim"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
"github.com/kubefirst/kubefirst-api/pkg/segment"
"github.com/kubefirst/kubefirst-api/pkg/telemetryShim"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/k8s"
log "github.com/sirupsen/logrus"
"github.com/thanhpk/randstr"
Expand All @@ -45,21 +44,13 @@ func (clctrl *ClusterController) CreateCluster() error {
return err
}

// Telemetry handler
segmentClient, err := telemetryShim.SetupTelemetry(cl)
if err != nil {
return err
}
defer segmentClient.Client.Close()

if !cl.CloudTerraformApplyCheck || cl.CloudTerraformApplyFailedCheck {

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(segmentClient, segment.MetricCloudTerraformApplyStarted, "")

telemetry.SendEvent(clctrl.SegmentClient, telemetry.CloudTerraformApplyStarted, err.Error())

log.Infof("creating %s cluster", clctrl.CloudProvider)

Expand Down Expand Up @@ -95,17 +86,12 @@ func (clctrl *ClusterController) CreateCluster() error {
if err != nil {
return err
}
telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyFailed, msg)
telemetry.SendEvent(clctrl.SegmentClient, telemetry.CloudTerraformApplyFailed, err.Error())
return fmt.Errorf(msg)
}

log.Infof("created %s cloud resources", clctrl.CloudProvider)

telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyCompleted, "")

log.Infof("successfully created %s cluster", clctrl.CloudProvider)

telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyCompleted, "")
telemetry.SendEvent(clctrl.SegmentClient, telemetry.CloudTerraformApplyCompleted, err.Error())

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "cloud_terraform_apply_failed_check", false)
if err != nil {
Expand Down
57 changes: 44 additions & 13 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ import (
"os"
"time"

"github.com/denisbrodbeck/machineid"
"github.com/kubefirst/kubefirst-api/internal/constants"
"github.com/kubefirst/kubefirst-api/internal/db"
"github.com/kubefirst/kubefirst-api/internal/utils"
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"
"github.com/kubefirst/kubefirst-api/pkg/telemetryShim"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg"
runtime "github.com/kubefirst/runtime/pkg"
awsinternal "github.com/kubefirst/runtime/pkg/aws"
"github.com/kubefirst/runtime/pkg/github"
"github.com/kubefirst/runtime/pkg/gitlab"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/services"
"github.com/segmentio/analytics-go"

log "github.com/sirupsen/logrus"
"go.mongodb.org/mongo-driver/bson/primitive"
)
Expand Down Expand Up @@ -99,12 +101,12 @@ type ClusterController struct {
KubefirstStateStoreBucketName string
KubefirstArtifactsBucketName string

// Telemetry
UseTelemetry bool

// Database Controller
MdbCl *db.MongoDBClient

// Telemetry
SegmentClient *telemetry.SegmentClient

// Provider clients
AwsClient *awsinternal.AWSConfiguration
GoogleClient google.GoogleConfiguration
Expand Down Expand Up @@ -143,14 +145,43 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
clusterID = runtime.GenerateClusterID()
}

// Telemetry handler
segmentClient, err := telemetryShim.SetupTelemetry(rec)
if os.Getenv("USE_TELEMETRY") == "false" {
clctrl.SegmentClient.UseTelemetry = false
} else {
clctrl.SegmentClient.UseTelemetry = true
}

// Telemetry handle
machineID, _ := machineid.ID()

segClient := telemetry.SegmentClient{
TelemetryEvent: telemetry.TelemetryEvent{
CliVersion: os.Getenv("KUBEFIRST_VERSION"),
CloudProvider: clctrl.CloudProvider,
ClusterID: clusterID,
ClusterType: def.Type,
DomainName: def.DomainName,
GitProvider: def.GitProvider,
InstallMethod: os.Getenv("INSTALL_METHOD"),
KubefirstClient: "api",
KubefirstTeam: os.Getenv("KUBEFIRST_TEAM"),
KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"),
MachineID: machineID,
ErrorMessage: "",
UserId: machineID,
MetricName: telemetry.ClusterInstallStarted,
},
Client: analytics.New(telemetry.SegmentIOWriteKey),
}
if err != nil {
return err
log.Warn(err)
}
defer segmentClient.Client.Close()
defer segClient.Client.Close()

telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallStarted, "")
if clctrl.SegmentClient.UseTelemetry {
telemetry.SendEvent(&segClient, telemetry.ClusterInstallStarted, err.Error())
}
clctrl.SegmentClient = &segClient

//Copy Cluster Definiion to Cluster Controller
clctrl.AlertsEmail = def.AdminEmail
Expand Down Expand Up @@ -259,16 +290,16 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
}

if os.Getenv("USE_TELEMETRY") == "false" {
clctrl.UseTelemetry = false
clctrl.SegmentClient.UseTelemetry = false
} else {
clctrl.UseTelemetry = true
clctrl.SegmentClient.UseTelemetry = true
}

// Write cluster record if it doesn't exist
cl := pkgtypes.Cluster{
ID: primitive.NewObjectID(),
CreationTimestamp: fmt.Sprintf("%v", primitive.NewDateTimeFromTime(time.Now().UTC())),
UseTelemetry: clctrl.UseTelemetry,
UseTelemetry: clctrl.SegmentClient.UseTelemetry,
Status: constants.ClusterStatusProvisioning,
AlertsEmail: clctrl.AlertsEmail,
ClusterName: clctrl.ClusterName,
Expand Down
16 changes: 4 additions & 12 deletions internal/controller/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"fmt"

cloudflare_api "github.com/cloudflare/cloudflare-go"
"github.com/kubefirst/kubefirst-api/pkg/segment"
"github.com/kubefirst/kubefirst-api/pkg/telemetryShim"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/civo"
"github.com/kubefirst/runtime/pkg/digitalocean"
"github.com/kubefirst/runtime/pkg/dns"
Expand All @@ -27,15 +26,8 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
return err
}

// Telemetry handler
segmentClient, err := telemetryShim.SetupTelemetry(cl)
if err != nil {
return err
}
defer segmentClient.Client.Close()

if !cl.DomainLivenessCheck {
telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessStarted, "")
telemetry.SendEvent(clctrl.SegmentClient, telemetry.DomainLivenessStarted, err.Error())

switch clctrl.DnsProvider {
case "aws":
Expand All @@ -54,7 +46,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
// domain id
domainId, err := civoConf.GetDNSInfo(clctrl.DomainName, clctrl.CloudRegion)
if err != nil {
telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessFailed, "domain liveness test failed")
telemetry.SendEvent(clctrl.SegmentClient, telemetry.DomainLivenessFailed, err.Error())
log.Info(err.Error())
}

Expand Down Expand Up @@ -129,7 +121,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
return err
}

telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessCompleted, "")
telemetry.SendEvent(clctrl.SegmentClient, telemetry.DomainLivenessCompleted, err.Error())

log.Infof("domain %s verified", clctrl.DomainName)
}
Expand Down
Loading

0 comments on commit d98ce20

Please sign in to comment.