Skip to content

Commit

Permalink
feat(event): update ua to ga4 analytics
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
Abhinandan-Purkait committed Nov 9, 2023
1 parent e927123 commit 333fc0a
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 225 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.19
require (
github.com/container-storage-interface/spec v1.8.0
github.com/docker/go-units v0.4.0
github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef
github.com/kubernetes-csi/csi-lib-utils v0.9.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.27.4
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109140127-1a72a3a59377
github.com/openebs/lib-csi v0.8.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.15.1
Expand All @@ -22,6 +22,7 @@ require (
k8s.io/apimachinery v0.27.2
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/code-generator v0.27.2
k8s.io/klog v0.3.0
k8s.io/klog/v2 v2.100.1
k8s.io/utils v0.0.0-20230505201702-9f6742963106
sigs.k8s.io/controller-runtime v0.2.0
Expand Down
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -223,8 +224,7 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef h1:jLpa0vamfyIGeIJ/CfUJEWoKriw4ODeOgF1XxDvgMZ4=
github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef/go.mod h1:PlwhC7q1VSK73InDzdDatVetQrTsQHIbOvcJAZzitY0=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -233,6 +233,7 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down Expand Up @@ -272,6 +273,7 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
Expand Down Expand Up @@ -312,6 +314,14 @@ github.com/onsi/gomega v1.27.1/go.mod h1:aHX5xOykVYzWOV4WqQy0sy8BQptgukenXpCXfad
github.com/onsi/gomega v1.27.3/go.mod h1:5vG284IBtfDAmDyrK+eGyZmUgUlmi+Wngqo557cZ6Gw=
github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E=
github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109100518-070125e17d7f h1:ImMid0eNsL8y9fEalA23PDupow7EiKSHRqKdzB1iybU=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109100518-070125e17d7f/go.mod h1:4xapXO4MRDVgGyUZdCD/5GQkPSwMgoen0f0qayOdW94=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109131215-db9b2be43a06 h1:1jmQeue/1lmssTlCorwCabSE+9YKsG/1g2m4+52Szk0=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109131215-db9b2be43a06/go.mod h1:4xapXO4MRDVgGyUZdCD/5GQkPSwMgoen0f0qayOdW94=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109135453-c3705f381d31 h1:BBKJDEGQwJ7q1ryyrRcncFTAbEjiz97a8GGqdt94SQ0=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109135453-c3705f381d31/go.mod h1:4xapXO4MRDVgGyUZdCD/5GQkPSwMgoen0f0qayOdW94=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109140127-1a72a3a59377 h1:6DxG/WeR651CPwqJR4ZFLVhlV0L8qGUBKFNeSCeDufY=
github.com/openebs/go-ogle-analytics v0.1.1-0.20231109140127-1a72a3a59377/go.mod h1:4xapXO4MRDVgGyUZdCD/5GQkPSwMgoen0f0qayOdW94=
github.com/openebs/lib-csi v0.8.0 h1:lxhv/SRjS7DBz7vTLkaDPd/FJnUftofxSFTU4fdZzW0=
github.com/openebs/lib-csi v0.8.0/go.mod h1:4yc0Q1thH+oU80z73zGELfrOw2yeLdLNIRmcrxBxsBc=
github.com/pborman/uuid v0.0.0-20170612153648-e790cca94e6c/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34=
Expand Down Expand Up @@ -814,6 +824,7 @@ k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo v0.0.0-20230306165830-ab3349d207d4 h1:aClvVG6GbX10ISHcc24J+tqbr0S7fEe1MWkFJ7cWWCI=
k8s.io/gengo v0.0.0-20230306165830-ab3349d207d4/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog v0.3.0 h1:0VPpR+sizsiivjIfIAQH/rl8tan6jvWkS7lU+0di3lE=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
Expand Down
Binary file added main
Binary file not shown.
16 changes: 8 additions & 8 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ var SupportedVolumeCapabilityAccessModes = []*csi.VolumeCapability_AccessMode{
}

// sendEventOrIgnore sends anonymous local-pv provision/delete events
func sendEventOrIgnore(pvcName, pvName, capacity, stgType, method string) {
func sendEventOrIgnore(pvcName, pvName, capacity, method string) {
if lvm.GoogleAnalyticsEnabled == "true" {
analytics.New().Build().ApplicationBuilder().
SetVolumeType(stgType, method).
SetDocumentTitle(pvName).
SetCampaignName(pvcName).
fmt.Println("--------> SENDING ONE METRIC")
analytics.New().CommonBuild().ApplicationBuilder().
SetResourceId(pvName).
// SetCampaignName(pvcName). ??? NEW FIELD NEEDED
SetLabel(analytics.EventLabelCapacity).
SetReplicaCount(analytics.LocalPVReplicaCount, method).
SetCategory(method).
Expand Down Expand Up @@ -232,7 +232,7 @@ func (cs *controller) init() error {
go pvcInformer.Informer().Run(stopCh)

if lvm.GoogleAnalyticsEnabled == "true" {
analytics.New().Build().InstallBuilder(true).Send()
analytics.New().CommonBuild().InstallBuilder(true).Send()
go analytics.PingCheck()
}

Expand Down Expand Up @@ -367,7 +367,7 @@ func (cs *controller) CreateVolume(
}
sendEventOrIgnore(params.PVCName, volName,
strconv.FormatInt(int64(size), 10),
"lvm-localpv", analytics.VolumeProvision)
analytics.VolumeProvision)

topology := map[string]string{lvm.LVMTopologyKey: vol.Spec.OwnerNodeID}
cntx := map[string]string{lvm.VolGroupKey: vol.Spec.VolGroup, lvm.OpenEBSCasTypeKey: lvm.LVMCasTypeName}
Expand Down Expand Up @@ -419,7 +419,7 @@ func (cs *controller) deleteVolume(ctx context.Context, volumeID string) error {
if err = lvm.WaitForLVMVolumeDestroy(ctx, volumeID); err != nil {
return err
}
sendEventOrIgnore("", volumeID, vol.Spec.Capacity, "lvm-localpv", analytics.VolumeDeprovision)
sendEventOrIgnore("", volumeID, vol.Spec.Capacity, analytics.VolumeDeprovision)
return nil
}

Expand Down
58 changes: 36 additions & 22 deletions pkg/usage/googleanalytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package usage

import (
analytics "github.com/jpillora/go-ogle-analytics"
"k8s.io/klog/v2"
"fmt"

"k8s.io/klog"
)

// Send sends a single usage metric to Google Analytics with some
Expand All @@ -27,28 +28,41 @@ import (
func (u *Usage) Send() {
// Instantiate a Gclient with the tracking ID
go func() {
// Un-wrap the gaClient struct back here
gaClient, err := analytics.NewClient(u.Gclient.trackID)
if err != nil {
return
}
gaClient.ClientID(u.clientID).
CampaignSource(u.campaignSource).
CampaignContent(u.clientID).
CampaignName(u.campaignName).
ApplicationID(u.appID).
ApplicationVersion(u.appVersion).
DataSource(u.dataSource).
ApplicationName(u.appName).
ApplicationInstallerID(u.appInstallerID).
DocumentTitle(u.documentTitle)
// Un-wrap the Event struct back here
event := analytics.NewEvent(u.category, u.action)
event.Label(u.label)
event.Value(u.value)
if err := gaClient.Send(event); err != nil {
client := u.AnalyticsClient

fmt.Println("----->", client)

event := u.OpenebsEventBuilder.Build()

fmt.Println("------>", event)

if err := client.Send(event); err != nil {
klog.Errorf(err.Error())
return
}
}()
}

// // Un-wrap the gaClient struct back here
// gaClient, err := analytics.NewClient(u.Gclient.trackID)
// if err != nil {
// return
// }
// gaClient.ClientID(u.clientID).
// CampaignSource(u.campaignSource).
// CampaignContent(u.clientID).
// CampaignName(u.campaignName).
// ApplicationID(u.appID).
// ApplicationVersion(u.appVersion).
// DataSource(u.dataSource).
// ApplicationName(u.appName).
// ApplicationInstallerID(u.appInstallerID).
// DocumentTitle(u.documentTitle)
// // Un-wrap the Event struct back here
// event := analytics.NewEvent(u.category, u.action)
// event.Label(u.label)
// event.Value(u.value)
// if err := gaClient.Send(event); err != nil {
// klog.Errorf(err.Error())
// return
// }
2 changes: 1 addition & 1 deletion pkg/usage/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func PingCheck() {
duration := getPingPeriod()
ticker := time.NewTicker(duration)
for range ticker.C {
u.Build().
u.CommonBuild().
InstallBuilder(true).
SetCategory(Ping).
Send()
Expand Down
Loading

0 comments on commit 333fc0a

Please sign in to comment.