Skip to content

Commit

Permalink
feat(event): update ua to ga4 analytics (#183)
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
Abhinandan-Purkait authored Nov 22, 2023
1 parent 1cc3661 commit bd967bd
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 710 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ go 1.19

require (
github.com/container-storage-interface/spec v1.8.0
github.com/docker/go-units v0.5.0
github.com/google/uuid v1.3.1
github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef
github.com/kubernetes-csi/csi-lib-iscsi v0.0.0-20200118015005-959f12c91ca8
github.com/kubernetes-csi/csi-lib-utils v0.14.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.27.7
github.com/openebs/api/v3 v3.0.2
github.com/openebs/google-analytics-4 v0.1.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.7.0
Expand All @@ -24,14 +23,15 @@ require (
k8s.io/client-go v0.27.2
k8s.io/code-generator v0.27.2
k8s.io/kubernetes v0.0.0-00010101000000-000000000000
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
k8s.io/utils v0.0.0-20230505201702-9f6742963106
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
Expand All @@ -45,7 +45,7 @@ require (
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -57,6 +57,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/selinux v1.10.0 // indirect
github.com/openebs/lib-csi v0.8.2 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,12 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/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/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
Expand Down Expand Up @@ -891,6 +889,10 @@ github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK9
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
github.com/openebs/api/v3 v3.0.2 h1:pHSMJATl9ETdw0AZ75e5UcgeN/ERmGZbdU9gdzWfMu0=
github.com/openebs/api/v3 v3.0.2/go.mod h1:cED/PzY/8Jr9pWVl90qHnuQk2hSG9NLCawrNsqEDWkA=
github.com/openebs/google-analytics-4 v0.1.0 h1:6aUDbQoh1ezb+NU/MkapFKffogW4QK3WYt8g2UmENe8=
github.com/openebs/google-analytics-4 v0.1.0/go.mod h1:3DkQfGCo79pZhL76Xtg0/R7LNLMttW6Bm/uP0yiZQHU=
github.com/openebs/lib-csi v0.8.2 h1:HmoiZX3VXFPglwqnRPnRus7K58ixDWBa19OpPZGk2Ws=
github.com/openebs/lib-csi v0.8.2/go.mod h1:4yc0Q1thH+oU80z73zGELfrOw2yeLdLNIRmcrxBxsBc=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
Expand Down Expand Up @@ -1665,8 +1667,8 @@ k8s.io/kubernetes v1.27.2 h1:g4v9oY6u7vBUDEuq4FvC50Bbw2K7GZuvM00IIESWVf4=
k8s.io/kubernetes v1.27.2/go.mod h1:U8ZXeKBAPxeb4J4/HOaxjw1A9K6WfSH+fY2SS7CR6IM=
k8s.io/mount-utils v0.27.2 h1:fEqtBdAv88xpoPr3nR0MgYs6P+2PjXyUTwd4NmqSBjY=
k8s.io/mount-utils v0.27.2/go.mod h1:vmcjYdi2Vg1VTWY7KkhvwJVY6WDHxb/QQhiQKkR8iNs=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.36.0/go.mod h1:NFUHyPn4ekoC/JHeZFfZurN6ixxawE1BnVonP/oahEI=
Expand Down
45 changes: 39 additions & 6 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/openebs/cstor-csi/pkg/env"
k8snode "github.com/openebs/cstor-csi/pkg/kubernetes/node"
csipayload "github.com/openebs/cstor-csi/pkg/payload"
analytics "github.com/openebs/cstor-csi/pkg/usage"
utils "github.com/openebs/cstor-csi/pkg/utils"
analytics "github.com/openebs/google-analytics-4/usage"
errors "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
Expand All @@ -37,6 +37,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// Ping event is sent periodically
Ping string = "ping"
// DefaultCASType Event application name constant for volume event
DefaultCASType string = "cstor"
// Replica Event replication
Replica string = "replica:"
// DefaultReplicaCount holds the replica count string
DefaultReplicaCount string = "replica:3"
)

// controller is the server implementation
// for CSI Controller
type controller struct {
Expand Down Expand Up @@ -354,12 +365,11 @@ func getAccessibilityRequirements(requirement *csi.TopologyRequirement) (string,
// sendEventOrIgnore sends anonymous cstor provision/delete events
func sendEventOrIgnore(pvcName, pvName, capacity, replicaCount, stgType, method string) {
if env.Truthy(env.OpenEBSEnableAnalytics) {
analytics.New().Build().ApplicationBuilder().
SetVolumeType(stgType, method).
SetDocumentTitle(pvName).
SetCampaignName(pvcName).
analytics.New().CommonBuild(GetVolumeType(stgType, method)).ApplicationBuilder().
SetVolumeName(pvName).
SetVolumeClaimName(pvcName).
SetLabel(analytics.EventLabelCapacity).
SetReplicaCount(replicaCount, method).
SetAction(GetReplicaCount(stgType, method)).
SetCategory(method).
SetVolumeCapacity(capacity).Send()
}
Expand Down Expand Up @@ -408,3 +418,26 @@ func (cs *controller) ControllerGetVolume(ctx context.Context, req *csi.Controll
},
}, nil
}

// SetVolumeType Wrapper for setting the default storage-engine for volume-provision event
func GetVolumeType(volType, method string) string {
if method == analytics.VolumeProvision && volType == "" {
// Set the default storage engine, if not specified in the request
return DefaultCASType
} else {
return volType
}
}

// GetReplicaCount Wrapper for setting replica count for volume events
func GetReplicaCount(count, method string) string {
if method == analytics.VolumeProvision && count == "" {
// Case: When volume-provision the replica count isn't specified
// it is set to three by default by the cstor-operators
return DefaultReplicaCount
} else {
// Catch all case for volume-deprovision event and
// volume-provision event with an overridden replica-count
return Replica + count
}
}
8 changes: 5 additions & 3 deletions pkg/driver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi"
config "github.com/openebs/cstor-csi/pkg/config"
"github.com/openebs/cstor-csi/pkg/env"
analytics "github.com/openebs/cstor-csi/pkg/usage"
utils "github.com/openebs/cstor-csi/pkg/utils"
"github.com/openebs/cstor-csi/pkg/version"
analytics "github.com/openebs/google-analytics-4/usage"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -124,8 +125,9 @@ func (d *CSIDriver) Run() error {
// Send Event only after starting controller.
// ControllerServer(cs) will be non-empty only if driver is running as controller service
if d.cs != nil && env.Truthy(env.OpenEBSEnableAnalytics) {
analytics.New().Build().InstallBuilder(true).Send()
go analytics.PingCheck()
analytics.RegisterVersionGetter(version.GetVersionDetails)
analytics.New().CommonBuild(DefaultCASType).InstallBuilder(true).Send()
go analytics.PingCheck(DefaultCASType, Ping)
}

s.Wait()
Expand Down
50 changes: 0 additions & 50 deletions pkg/usage/const.go

This file was deleted.

54 changes: 0 additions & 54 deletions pkg/usage/googleanalytics.go

This file was deleted.

63 changes: 0 additions & 63 deletions pkg/usage/ping.go

This file was deleted.

Loading

0 comments on commit bd967bd

Please sign in to comment.