func SendAnalytics()

in cli/pkg/analytics/client.go [59:114]


func SendAnalytics(conf *config.Config, version string, gitCommit string) {
	// Generate timestamp. Format: 2006-01-02T15:04:05.000Z
	now := time.Now()
	timestamp := now.Format("2006-01-02T15:04:05.000Z")

	// Generate CreateId used by all clusters

	// Assign UUIDs to create run and cluster
	createId, err := uuid.NewV4()
	if err != nil {
		log.Warn(err)
		return
	}

	for i, cluster := range conf.ClustersConfig {
		// Cluster Id
		clusterId, err := uuid.NewV4()
		if err != nil {
			log.Warn(err)
			return
		}

		// Create Cluster Object, omitting any user-identified data (Project IDs)
		// NOTE - ClusterId and CreateId are generated server-side before DB insert to avoid HTTP POST anti-patterns
		sendObject := Cluster{
			ClusterId:          clusterId.String(),
			CreateId:           createId.String(),
			Version:            version,
			GitCommit:          gitCommit,
			Timestamp:          timestamp,
			OS:                 runtime.GOOS,
			TerraformState:     conf.TerraformState,
			DefaultNodepoolOS:  conf.DefaultNodepoolOS,
			PrivateEndpoint:    conf.PrivateEndpoint,
			VPCType:            conf.VpcConfig.VpcType,
			ClusterIndex:       i,
			ClusterType:        cluster.ClusterType,
			ClusterMachineType: cluster.MachineType,
			ClusterRegion:      cluster.Region,
			ClusterZones:       cluster.Zones,
		}
		// Encode as JSON
		json, err := json.Marshal(sendObject)
		if err != nil {
			log.Warn(err)
			return
		}
		err = PostToAnalyticsServer(json)
		if err != nil {
			log.Warn(err)
			return
		}
	}
	log.Info("✅ Sent cluster info to analytics server")
	return
}