Skip to content

Commit

Permalink
feat(usage): include pvc name in volume events
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Jun 8, 2020
1 parent e558bb5 commit 2bc0ad2
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions deploy/operators/centos7/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deploy/operators/centos8/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deploy/yamls/centos7/zfs-driver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deploy/yamls/centos8/zfs-driver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deploy/yamls/ubuntu/zfs-driver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deploy/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -204,6 +205,7 @@ func (cs *controller) CreateVolume(
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
size := req.GetCapacityRange().RequiredBytes
contentSource := req.GetVolumeContentSource()
pvcName := helpers.GetInsensitiveParameter(&parameters, "csi.storage.k8s.io/pvc/name")

if err = cs.validateVolumeCreateReq(req); err != nil {
return nil, err
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/usage/googleanalytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
9 changes: 9 additions & 0 deletions pkg/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2bc0ad2

Please sign in to comment.