Skip to content

Commit

Permalink
adjusting api to leverage new telemetry (#247)
Browse files Browse the repository at this point in the history
* adjusting api to leverage new telemetry

* adopt metrics-client v0.3.0 and implement parent_cluster_id

* setting parent cluster id
  • Loading branch information
johndietz authored Dec 12, 2023
1 parent 008f14c commit b5caee0
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 19 deletions.
6 changes: 4 additions & 2 deletions charts/kubefirst-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ spec:
value: {{ .Values.global.kubefirstTeamInfo | default "" | quote }}
- name: KUBEFIRST_VERSION
value: {{ .Values.global.kubefirstVersion | default "unset" }}
- name: PARENT_CLUSTER_ID
value: {{ .Values.global.clusterId | default $clusterId }}
- name: USE_TELEMETRY
value: {{ .Values.global.useTelemetry | default "true" | quote }}
- name: IS_CLUSTER_ZERO
Expand Down Expand Up @@ -170,8 +172,6 @@ spec:
imagePullPolicy: {{ .Values.image.hook.pullPolicy }}
args: [
"transmit",
"--type",
"cluster-zero",
]
env:
- name: CLOUD_PROVIDER
Expand All @@ -194,5 +194,7 @@ spec:
value: {{ .Values.global.kubefirstTeamInfo | default "" | quote }}
- name: KUBEFIRST_VERSION
value: {{ .Values.global.kubefirstVersion | default "unset" }}
- name: PARENT_CLUSTER_ID
value: {{ .Values.global.clusterId | default $clusterId }}
- name: USE_TELEMETRY
value: {{ .Values.global.useTelemetry | default "true" | quote }}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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.8
github.com/kubefirst/metrics-client v0.3.0
github.com/kubefirst/runtime v0.3.35
github.com/minio/minio-go/v7 v7.0.49
github.com/otiai10/copy v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubefirst/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/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
KubefirstTeam: env.KubefirstTeam,
KubefirstTeamInfo: env.KubefirstTeamInfo,
MachineID: env.ClusterId,
MetricName: telemetry.ClusterInstallStarted,
ParentClusterId: env.ParentClusterId,
MetricName: telemetry.ClusterInstallCompleted,
UserId: env.ClusterId,
}
clctrl.TelemetryEvent = telemetryEvent

telemetry.SendEvent(clctrl.TelemetryEvent, telemetry.ClusterInstallStarted, "")

//Copy Cluster Definiion to Cluster Controller
clctrl.AlertsEmail = def.AdminEmail
clctrl.CloudProvider = def.CloudProvider
Expand Down
3 changes: 2 additions & 1 deletion internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type Env struct {
KubefirstTeamInfo string `env:"KUBEFIRST_TEAM_INFO"`
AWSRegion string `env:"AWS_REGION"`
AWSProfile string `env:"AWS_PROFILE"`
IsClusterZero string `env:"IS_CLUSTER_ZERO" envDefault:"false"`
IsClusterZero string `env:"IS_CLUSTER_ZERO"`
ParentClusterId string `env:"PARENT_CLUSTER_ID"`
InCluster string `env:"IN_CLUSTER" envDefault:"false"`
EnterpriseApiUrl string `env:"ENTERPRISE_API_URL"`
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func main() {
KubefirstTeam: env.KubefirstTeam,
KubefirstTeamInfo: env.KubefirstTeamInfo,
MachineID: env.ClusterId,
MetricName: telemetry.ClusterInstallStarted,
MetricName: telemetry.ClusterInstallCompleted,
ParentClusterId: env.ParentClusterId,
UserId: env.ClusterId,
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/segment/segment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package segment

import (
"os"

"github.com/denisbrodbeck/machineid"
"github.com/kubefirst/metrics-client/pkg/telemetry"

"github.com/segmentio/analytics-go"
log "github.com/sirupsen/logrus"
)

const (
kubefirstClient string = "api"
)

func InitClient() *telemetry.SegmentClient {

machineID, err := machineid.ID()
if err != nil {
log.Info("machine id FAILED")
}
sc := analytics.New(telemetry.SegmentIOWriteKey)

kubefirstVersion := os.Getenv("KUBEFIRST_VERSION")
if kubefirstVersion == "" {
kubefirstVersion = "development"
}

c := telemetry.SegmentClient{
TelemetryEvent: telemetry.TelemetryEvent{
CliVersion: kubefirstVersion,
CloudProvider: os.Getenv("CLOUD_PROVIDER"),
ClusterID: os.Getenv("CLUSTER_ID"),
ClusterType: os.Getenv("CLUSTER_TYPE"),
DomainName: os.Getenv("DOMAIN_NAME"),
GitProvider: os.Getenv("GIT_PROVIDER"),
InstallMethod: os.Getenv("INSTALL_METHOD"),
KubefirstClient: kubefirstClient,
KubefirstTeam: os.Getenv("KUBEFIRST_TEAM"),
KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"),
MachineID: machineID,
ParentClusterId: os.Getenv("PARENT_CLUSTER_ID"),
ErrorMessage: "",
UserId: machineID,
MetricName: telemetry.ClusterInstallCompleted,
},
Client: sc,
}

return &c
}
3 changes: 1 addition & 2 deletions providers/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/kubefirst/kubefirst-api/internal/db"
"github.com/kubefirst/kubefirst-api/internal/services"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
awsinternal "github.com/kubefirst/runtime/pkg/aws"
"github.com/kubefirst/runtime/pkg/k8s"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -253,7 +252,7 @@ func CreateAWSCluster(definition *pkgtypes.ClusterDefinition) error {
return err
}

telemetry.SendEvent(ctrl.TelemetryEvent, telemetry.ClusterInstallCompleted, "")
log.Info("cluster creation complete")

// Create default service entries
cl, _ := db.Client.GetCluster(ctrl.ClusterName)
Expand Down
3 changes: 1 addition & 2 deletions providers/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/kubefirst/kubefirst-api/internal/db"
"github.com/kubefirst/kubefirst-api/internal/services"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/ssl"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -233,7 +232,7 @@ func CreateCivoCluster(definition *pkgtypes.ClusterDefinition) error {
return err
}

telemetry.SendEvent(ctrl.TelemetryEvent, telemetry.ClusterInstallCompleted, "")
log.Info("cluster creation complete")

// Create default service entries
cl, _ := db.Client.GetCluster(ctrl.ClusterName)
Expand Down
4 changes: 1 addition & 3 deletions providers/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/kubefirst/kubefirst-api/internal/db"
"github.com/kubefirst/kubefirst-api/internal/services"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/ssl"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -229,8 +228,7 @@ func CreateDigitaloceanCluster(definition *pkgtypes.ClusterDefinition) error {
return err
}

// Telemetry handler
telemetry.SendEvent(ctrl.TelemetryEvent, telemetry.ClusterInstallCompleted, "")
log.Info("cluster creation complete")

// Create default service entries
cl, _ := db.Client.GetCluster(ctrl.ClusterName)
Expand Down
3 changes: 1 addition & 2 deletions providers/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/kubefirst/kubefirst-api/internal/services"
"github.com/kubefirst/kubefirst-api/pkg/google"
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"
)
Expand Down Expand Up @@ -252,7 +251,7 @@ func CreateGoogleCluster(definition *pkgtypes.ClusterDefinition) error {
return err
}

telemetry.SendEvent(ctrl.TelemetryEvent, telemetry.ClusterInstallCompleted, "")
log.Info("cluster creation complete")

// Create default service entries
cl, _ := db.Client.GetCluster(ctrl.ClusterName)
Expand Down
3 changes: 1 addition & 2 deletions providers/vultr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/kubefirst/kubefirst-api/internal/db"
"github.com/kubefirst/kubefirst-api/internal/services"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/ssl"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -224,7 +223,7 @@ func CreateVultrCluster(definition *pkgtypes.ClusterDefinition) error {
return err
}

telemetry.SendEvent(ctrl.TelemetryEvent, telemetry.ClusterInstallCompleted, "")
log.Info("cluster creation complete")

// Create default service entries
cl, _ := db.Client.GetCluster(ctrl.ClusterName)
Expand Down

0 comments on commit b5caee0

Please sign in to comment.