From 6db2f6f2ff98e39aef9a340794b0a838fc6a5e69 Mon Sep 17 00:00:00 2001 From: Pawan Date: Sun, 7 Jun 2020 16:58:44 +0530 Subject: [PATCH] feat(usage): include pvc name in volume events Signed-off-by: Pawan --- changelogs/unreleased/150-pawanpraka1 | 1 + deploy/operators/centos7/zfs-operator.yaml | 1 + deploy/operators/centos8/zfs-operator.yaml | 1 + deploy/yamls/centos7/zfs-driver.yaml | 1 + deploy/yamls/centos8/zfs-driver.yaml | 1 + deploy/yamls/ubuntu/zfs-driver.yaml | 1 + deploy/zfs-operator.yaml | 1 + pkg/driver/controller.go | 8 +++++--- pkg/usage/googleanalytics.go | 1 + pkg/usage/usage.go | 9 +++++++++ 10 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/150-pawanpraka1 diff --git a/changelogs/unreleased/150-pawanpraka1 b/changelogs/unreleased/150-pawanpraka1 new file mode 100644 index 000000000..0f543477d --- /dev/null +++ b/changelogs/unreleased/150-pawanpraka1 @@ -0,0 +1 @@ +include pvc name in volume events diff --git a/deploy/operators/centos7/zfs-operator.yaml b/deploy/operators/centos7/zfs-operator.yaml index 0479a0461..e1b4f1db6 100644 --- a/deploy/operators/centos7/zfs-operator.yaml +++ b/deploy/operators/centos7/zfs-operator.yaml @@ -1038,6 +1038,7 @@ spec: - "--strict-topology" - "--enable-leader-election" - "--leader-election-type=leases" + - "--extra-create-metadata=true" env: - name: ADDRESS value: /var/lib/csi/sockets/pluginproxy/csi.sock diff --git a/deploy/operators/centos8/zfs-operator.yaml b/deploy/operators/centos8/zfs-operator.yaml index c80cb8852..0f0942273 100644 --- a/deploy/operators/centos8/zfs-operator.yaml +++ b/deploy/operators/centos8/zfs-operator.yaml @@ -1038,6 +1038,7 @@ spec: - "--strict-topology" - "--enable-leader-election" - "--leader-election-type=leases" + - "--extra-create-metadata=true" env: - name: ADDRESS value: /var/lib/csi/sockets/pluginproxy/csi.sock diff --git a/deploy/yamls/centos7/zfs-driver.yaml b/deploy/yamls/centos7/zfs-driver.yaml index 9cff1ddc4..29244d724 100644 --- a/deploy/yamls/centos7/zfs-driver.yaml +++ b/deploy/yamls/centos7/zfs-driver.yaml @@ -570,6 +570,7 @@ spec: - "--strict-topology" - "--enable-leader-election" - "--leader-election-type=leases" + - "--extra-create-metadata=true" env: - name: ADDRESS value: /var/lib/csi/sockets/pluginproxy/csi.sock diff --git a/deploy/yamls/centos8/zfs-driver.yaml b/deploy/yamls/centos8/zfs-driver.yaml index 549996aaa..fa2409c30 100644 --- a/deploy/yamls/centos8/zfs-driver.yaml +++ b/deploy/yamls/centos8/zfs-driver.yaml @@ -570,6 +570,7 @@ spec: - "--strict-topology" - "--enable-leader-election" - "--leader-election-type=leases" + - "--extra-create-metadata=true" env: - name: ADDRESS value: /var/lib/csi/sockets/pluginproxy/csi.sock diff --git a/deploy/yamls/ubuntu/zfs-driver.yaml b/deploy/yamls/ubuntu/zfs-driver.yaml index 3fecc4e8d..d99cefa43 100644 --- a/deploy/yamls/ubuntu/zfs-driver.yaml +++ b/deploy/yamls/ubuntu/zfs-driver.yaml @@ -570,6 +570,7 @@ spec: - "--strict-topology" - "--enable-leader-election" - "--leader-election-type=leases" + - "--extra-create-metadata=true" env: - name: ADDRESS value: /var/lib/csi/sockets/pluginproxy/csi.sock diff --git a/deploy/zfs-operator.yaml b/deploy/zfs-operator.yaml index e9a5731f1..297e079a8 100644 --- a/deploy/zfs-operator.yaml +++ b/deploy/zfs-operator.yaml @@ -1038,6 +1038,7 @@ spec: - "--strict-topology" - "--enable-leader-election" - "--leader-election-type=leases" + - "--extra-create-metadata=true" env: - name: ADDRESS value: /var/lib/csi/sockets/pluginproxy/csi.sock diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index a2892b4d8..1855c73cf 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -61,11 +61,12 @@ var SupportedVolumeCapabilityAccessModes = []*csi.VolumeCapability_AccessMode{ } // sendEventOrIgnore sends anonymous local-pv provision/delete events -func sendEventOrIgnore(pvName, capacity, stgType, method string) { +func sendEventOrIgnore(pvcName, pvName, capacity, stgType, method string) { if zfs.GoogleAnalyticsEnabled == "true" { analytics.New().Build().ApplicationBuilder(). SetVolumeType(stgType, method). SetDocumentTitle(pvName). + SetCampaignName(pvcName). SetLabel(analytics.EventLabelCapacity). SetReplicaCount(analytics.LocalPVReplicaCount, method). SetCategory(method). @@ -204,6 +205,7 @@ func (cs *controller) CreateVolume( pool := helpers.GetInsensitiveParameter(¶meters, "poolname") size := req.GetCapacityRange().RequiredBytes contentSource := req.GetVolumeContentSource() + pvcName := helpers.GetInsensitiveParameter(¶meters, "csi.storage.k8s.io/pvc/name") if err = cs.validateVolumeCreateReq(req); err != nil { return nil, err @@ -221,7 +223,7 @@ func (cs *controller) CreateVolume( return nil, status.Error(codes.Internal, err.Error()) } - sendEventOrIgnore(volName, strconv.FormatInt(int64(size), 10), "zfs-localpv", analytics.VolumeProvision) + sendEventOrIgnore(pvcName, volName, strconv.FormatInt(int64(size), 10), "zfs-localpv", analytics.VolumeProvision) topology := map[string]string{zfs.ZFSTopologyKey: selected} cntx := map[string]string{zfs.PoolNameKey: pool} @@ -268,7 +270,7 @@ func (cs *controller) DeleteVolume( ) } - sendEventOrIgnore(volumeID, vol.Spec.Capacity, "zfs-localpv", analytics.VolumeDeprovision) + sendEventOrIgnore("", volumeID, vol.Spec.Capacity, "zfs-localpv", analytics.VolumeDeprovision) deleteResponse: return csipayload.NewDeleteVolumeResponseBuilder().Build(), nil diff --git a/pkg/usage/googleanalytics.go b/pkg/usage/googleanalytics.go index 7fa5d90cb..beb7aaeb5 100644 --- a/pkg/usage/googleanalytics.go +++ b/pkg/usage/googleanalytics.go @@ -34,6 +34,7 @@ func (u *Usage) Send() { gaClient.ClientID(u.clientID). CampaignSource(u.campaignSource). CampaignContent(u.clientID). + CampaignName(u.campaignName). ApplicationID(u.appID). ApplicationVersion(u.appVersion). DataSource(u.dataSource). diff --git a/pkg/usage/usage.go b/pkg/usage/usage.go index 3e407f446..b4cc8a2e2 100644 --- a/pkg/usage/usage.go +++ b/pkg/usage/usage.go @@ -86,6 +86,9 @@ type Gclient struct { // anonymous campaign source campaignSource string + // anonymous campaign name + campaignName string + // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ds // (usecase) node-detail dataSource string @@ -133,6 +136,12 @@ func (u *Usage) SetApplicationName(appName string) *Usage { return u } +// SetCampaignName : set the name of the PVC or will be empty. +func (u *Usage) SetCampaignName(campaignName string) *Usage { + u.campaignName = campaignName + return u +} + // SetApplicationID : usecase(OpenEBS/NDM) func (u *Usage) SetApplicationID(appID string) *Usage { u.appID = appID