Skip to content

Commit 576b744

Browse files
authored
Add version, gitcommit, MCG, and ASM to analytics (#128)
1 parent 4d1c335 commit 576b744

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

analytics/server.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ type Cluster struct {
2929
ClusterId string `json:"clusterId"`
3030
CreateId string `json:"createId"`
3131

32+
// What version is the user running?
33+
Version string `json:"version"`
34+
GitCommit string `json:"gitCommit"`
35+
3236
// The rest of these fields must be populated by the client on POST.
3337
//String Format: 2006-01-02T15:04:05.000Z Test string: 2021-11-12T11:45:26.371Z
3438
Timestamp string `json:"timestamp"`
@@ -42,6 +46,8 @@ type Cluster struct {
4246
DefaultNodepoolOS string `json:"defaultNodepoolOS"`
4347
PrivateEndpoint bool `json:"privateEndpoint"`
4448
EnableConfigSync bool `json:"enableConfigSync"`
49+
AnthosServiceMesh bool `json:"anthosServiceMesh"`
50+
MultiClusterGateway bool `json:"multiClusterGateway"`
4551
EnablePolicyController bool `json:"enablePolicyController"`
4652
VPCType string `json:"vpcType"`
4753

@@ -175,9 +181,11 @@ func initCloudSQL() (*app, error) {
175181
}
176182

177183
tableCreate := `
178-
CREATE TABLE IF NOT EXISTS CLUSTERS(
184+
CREATE TABLE IF NOT EXISTS CLUSTERS3(
179185
ClusterId TEXT,
180186
CreateId TEXT,
187+
Version TEXT,
188+
GitCommit TEXT,
181189
Timestamp TIMESTAMP,
182190
OS TEXT,
183191
TerraformState TEXT,
@@ -188,6 +196,8 @@ func initCloudSQL() (*app, error) {
188196
PrivateEndpoint BOOL,
189197
EnableConfigSync BOOL,
190198
EnablePolicyController BOOL,
199+
AnthosServiceMesh BOOL,
200+
MultiClusterGateway BOOL,
191201
VPCType TEXT,
192202
ClusterIndex INTEGER,
193203
ClusterNumNodes INTEGER,
@@ -206,9 +216,9 @@ func initCloudSQL() (*app, error) {
206216

207217
// Helper - writes Cluster object to Cloud SQL on localhost (via proxy)
208218
func writeToCloudSQL(app *app, c Cluster) error {
209-
sqlInsert := "INSERT INTO CLUSTERS(ClusterId, CreateId, Timestamp, OS, TerraformState, Region, EnableWorkloadIdentity, EnablePreemptibleNodepool, DefaultNodepoolOS, PrivateEndpoint, EnableConfigSync, EnablePolicyController, VPCType, ClusterIndex, ClusterNumNodes, ClusterMachineType, ClusterRegion, ClusterZone) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)"
219+
sqlInsert := "INSERT INTO CLUSTERS3(ClusterId, CreateId, Version, GitCommit, Timestamp, OS, TerraformState, Region, EnableWorkloadIdentity, EnablePreemptibleNodepool, DefaultNodepoolOS, PrivateEndpoint, EnableConfigSync, EnablePolicyController, AnthosServiceMesh, MultiClusterGateway, VPCType, ClusterIndex, ClusterNumNodes, ClusterMachineType, ClusterRegion, ClusterZone) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)"
210220

211-
_, err := app.db.Exec(sqlInsert, c.ClusterId, c.CreateId, c.Timestamp, c.OS, c.TerraformState, c.Region, c.EnableWorkloadIdentity, c.EnablePreemptibleNodepool, c.DefaultNodepoolOS, c.PrivateEndpoint, c.EnableConfigSync, c.EnablePolicyController, c.VPCType, c.ClusterIndex, c.ClusterNumNodes, c.ClusterMachineType, c.ClusterRegion, c.ClusterZone)
221+
_, err := app.db.Exec(sqlInsert, c.ClusterId, c.CreateId, c.Version, c.GitCommit, c.Timestamp, c.OS, c.TerraformState, c.Region, c.EnableWorkloadIdentity, c.EnablePreemptibleNodepool, c.DefaultNodepoolOS, c.PrivateEndpoint, c.EnableConfigSync, c.EnablePolicyController, c.AnthosServiceMesh, c.MultiClusterGateway, c.VPCType, c.ClusterIndex, c.ClusterNumNodes, c.ClusterMachineType, c.ClusterRegion, c.ClusterZone)
212222

213223
if err != nil {
214224
return fmt.Errorf("Error on Cloud SQL Insert: %v", err)

cli/cmd/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var createCmd = &cobra.Command{
3737

3838
// Send user analytics - async
3939
if conf.SendAnalytics {
40-
go analytics.SendAnalytics(conf)
40+
go analytics.SendAnalytics(conf, Version, GitCommit)
4141
}
4242

4343
config.GenerateTfvars(conf)

cli/pkg/analytics/client.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"gkekitctl/pkg/config"
7+
78
"net/http"
89
"runtime"
910
"time"
@@ -18,6 +19,8 @@ import (
1819
type Cluster struct {
1920
ClusterId string `json:"clusterId"`
2021
CreateId string `json:"createId"`
22+
Version string `json:"version"`
23+
GitCommit string `json:"gitCommit"`
2124
Timestamp string `json:"timestamp"`
2225
OS string `json:"os"`
2326
TerraformState string `json:"terraformState"`
@@ -28,6 +31,8 @@ type Cluster struct {
2831
PrivateEndpoint bool `json:"privateEndpoint"`
2932
EnableConfigSync bool `json:"enableConfigSync"`
3033
EnablePolicyController bool `json:"enablePolicyController"`
34+
AnthosServiceMesh bool `json:"anthosServiceMesh"`
35+
MultiClusterGateway bool `json:"multiClusterGateway"`
3136
VPCType string `json:"vpcType"`
3237
ClusterIndex int `json:"clusterIndex"`
3338
ClusterNumNodes int `json:"clusterNumNodes"`
@@ -37,7 +42,7 @@ type Cluster struct {
3742
ClusterZone string `json:"clusterZone"`
3843
}
3944

40-
func SendAnalytics(conf *config.Config) {
45+
func SendAnalytics(conf *config.Config, version string, gitCommit string) {
4146
// Generate timestamp. Format: 2006-01-02T15:04:05.000Z
4247
now := time.Now()
4348
timestamp := now.Format("2006-01-02T15:04:05.000Z")
@@ -64,6 +69,8 @@ func SendAnalytics(conf *config.Config) {
6469
sendObject := Cluster{
6570
ClusterId: clusterId.String(),
6671
CreateId: createId.String(),
72+
Version: version,
73+
GitCommit: gitCommit,
6774
Timestamp: timestamp,
6875
OS: runtime.GOOS,
6976
TerraformState: conf.TerraformState,
@@ -74,6 +81,8 @@ func SendAnalytics(conf *config.Config) {
7481
PrivateEndpoint: conf.PrivateEndpoint,
7582
EnableConfigSync: conf.ConfigSync,
7683
EnablePolicyController: conf.PolicyController,
84+
AnthosServiceMesh: conf.AnthosServiceMesh,
85+
MultiClusterGateway: conf.MultiClusterGateway,
7786
VPCType: conf.VpcConfig.VpcType,
7887
ClusterIndex: i,
7988
ClusterNumNodes: cluster.NumNodes,

cli/pkg/config/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type Config struct {
4747
ClustersProjectID string `yaml:"clustersProjectId"`
4848
GovernanceProjectID string `yaml:"governanceProjectId"`
4949
ConfigSync bool `yaml:"configSync"`
50+
AnthosServiceMesh bool `yaml:"anthosServiceMesh"`
51+
MultiClusterGateway bool `yaml:"multiClusterGateway"`
5052
PolicyController bool `yaml:"policyController"`
5153
PrivateEndpoint bool `yaml:"privateEndpoint"`
5254
EnableWorkloadIdentity bool `yaml:"enableWorkloadIdentity"`

0 commit comments

Comments
 (0)