Skip to content

Commit

Permalink
adding missing methods and machineid to type
Browse files Browse the repository at this point in the history
  • Loading branch information
johndietz committed Oct 21, 2023
1 parent 47f6dbe commit 3d6df67
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 0 additions & 1 deletion internal/telemetryShim/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func SetupTelemetry(cl pkgtypes.Cluster) (*segment.SegmentClient, error) {
KubefirstTeamInfo: os.Getenv("KUBEFIRST_TEAM_INFO"),
MachineID: machineID,
}
segmentClient.SetupClient()

return segmentClient, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/segment/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ type SegmentClient struct {
KubefirstClient string
KubefirstTeam string
KubefirstTeamInfo string
MachineID string
}
52 changes: 52 additions & 0 deletions pkg/segment/send.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package segment

import (
"fmt"

"github.com/denisbrodbeck/machineid"
"github.com/kubefirst/runtime/pkg"
"github.com/segmentio/analytics-go"
)

// SendCountMetric
func (c *SegmentClient) SendCountMetric(
metricName string,
errorMessage string,
) string {
strippedDomainName, err := pkg.RemoveSubdomainV2(c.DomainName)
if err != nil {
return "error stripping domain name from value"
}
machineID, _ := machineid.ID()
if metricName == MetricInitStarted {
err := c.Client.Enqueue(analytics.Identify{
UserId: strippedDomainName,
Type: "identify",
})
if err != nil {
return fmt.Sprintf("error sending identify to segment: %s", err.Error())
}
}
err = c.Client.Enqueue(analytics.Track{
UserId: strippedDomainName,
Event: metricName,
Properties: analytics.NewProperties().
Set("cli_version", c.CliVersion).
Set("cloud_provider", c.CloudProvider).
Set("cluster_id", c.ClusterID).
Set("cluster_type", c.ClusterType).
Set("domain", strippedDomainName).
Set("git_provider", c.GitProvider).
Set("client", c.KubefirstClient).
Set("kubefirst_team", c.KubefirstTeam).
Set("kubefirst_team_info", c.KubefirstTeamInfo).
Set("machine_id", machineID).
Set("error", errorMessage).
Set("install_method", c.InstallMethod),
})
if err != nil {
return fmt.Sprintf("error sending track to segment: %s", err.Error())
}

return ""
}

0 comments on commit 3d6df67

Please sign in to comment.