diff --git a/go.mod b/go.mod index 3ad2015b..d604c60f 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 70c9817f..b4670c42 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/main b/main new file mode 100755 index 00000000..0bc4279c Binary files /dev/null and b/main differ diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 0ce1c8b0..3890aebd 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -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). @@ -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() } @@ -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} @@ -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 } diff --git a/pkg/usage/googleanalytics.go b/pkg/usage/googleanalytics.go index ad058dbb..1e33efc7 100644 --- a/pkg/usage/googleanalytics.go +++ b/pkg/usage/googleanalytics.go @@ -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 @@ -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 +// } diff --git a/pkg/usage/ping.go b/pkg/usage/ping.go index ed73f99f..2026e2e7 100644 --- a/pkg/usage/ping.go +++ b/pkg/usage/ping.go @@ -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() diff --git a/pkg/usage/usage.go b/pkg/usage/usage.go index fcafd352..bfc26963 100644 --- a/pkg/usage/usage.go +++ b/pkg/usage/usage.go @@ -17,191 +17,75 @@ limitations under the License. package usage import ( + "strconv" + + ga4Client "github.com/openebs/go-ogle-analytics/client" + ga4Event "github.com/openebs/go-ogle-analytics/event" k8sapi "github.com/openebs/lib-csi/pkg/client/k8s" ) // Usage struct represents all information about a usage metric sent to // Google Analytics with respect to the application type Usage struct { - // Embedded Event struct as we are currently only sending hits of type - // 'event' - Event - - // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an - // use-case: cstor or jiva volume, or m-apiserver application - // Embedded field for application - Application - - // Embedded Gclient struct - Gclient -} - -// Event is a represents usage of OpenEBS -// Event contains all the query param fields when hits is of type='event' -// Ref: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ec -type Event struct { - // (Required) Event Category, ec - category string - // (Required) Event Action, ea - action string - // (Optional) Event Label, el - label string - // (Optional) Event vallue, ev - // Non negative - value int64 -} - -// NewEvent returns an Event struct with eventCategory, eventAction, -// eventLabel, eventValue fields -func (u *Usage) NewEvent(c, a, l string, v int64) *Usage { - u.category = c - u.action = a - u.label = l - u.value = v - return u -} - -// Application struct holds details about the Application -type Application struct { - // eg. project version - appVersion string - - // eg. kubernetes version - appInstallerID string - - // Name of the application, usage(OpenEBS/NDM) - appID string - - // eg. usage(os-type/architecture) of system or volume's CASType - appName string -} - -// Gclient struct represents a Google Analytics hit -type Gclient struct { - // constant tracking-id used to send a hit - trackID string - - // anonymous client-id - clientID string + // + OpenebsEventBuilder *ga4Event.OpenebsEventBuilder - // 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 - - // Document-title property in Google Analytics - // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dt - // use-case: uuid of the volume objects or a uuid to anonymously tell objects apart - documentTitle string + // + AnalyticsClient *ga4Client.MeasurementClient } // New returns an instance of Usage func New() *Usage { - return &Usage{} -} - -// SetDataSource : usage(os-type, kernel) -func (u *Usage) SetDataSource(dataSource string) *Usage { - u.dataSource = dataSource - return u -} - -// SetTrackingID Sets the GA-code for the project -func (u *Usage) SetTrackingID(track string) *Usage { - u.trackID = track - return u -} - -// SetCampaignSource : source of openebs installater like: -// helm or operator etc. This will have to be configured -// via ENV variable OPENEBS_IO_INSTALLER_TYPE -func (u *Usage) SetCampaignSource(campaignSrc string) *Usage { - u.campaignSource = campaignSrc - return u + client, err := ga4Client.NewMeasurementClient( + ga4Client.WithApiSecret("NguBiGh6QeOdeG3zJswggQ"), + ga4Client.WithMeasurementId("G-TZGP46618W"), + ) + if err != nil { + return nil + } + openebsEventBuilder := ga4Event.NewOpenebsEventBuilder() + return &Usage{AnalyticsClient: client, OpenebsEventBuilder: openebsEventBuilder} } // SetDocumentTitle : usecase(anonymous-id) -func (u *Usage) SetDocumentTitle(documentTitle string) *Usage { - u.documentTitle = documentTitle - return u -} - -// SetApplicationName : usecase(os-type/arch, volume CASType) -func (u *Usage) SetApplicationName(appName string) *Usage { - u.appName = appName - 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 - return u -} - -// SetApplicationVersion : usecase(project-version) -func (u *Usage) SetApplicationVersion(appVersion string) *Usage { - u.appVersion = appVersion - return u -} - -// SetApplicationInstallerID : usecase(k8s-version) -func (u *Usage) SetApplicationInstallerID(appInstallerID string) *Usage { - u.appInstallerID = appInstallerID - return u -} - -// SetClientID sets the anonymous user id -func (u *Usage) SetClientID(userID string) *Usage { - u.clientID = userID +func (u *Usage) SetResourceId(res_id string) *Usage { + u.OpenebsEventBuilder.ResourceId(res_id) return u } // SetCategory sets the category of an event func (u *Usage) SetCategory(c string) *Usage { - u.category = c + u.OpenebsEventBuilder.Category(c) return u } // SetAction sets the action of an event func (u *Usage) SetAction(a string) *Usage { - u.action = a + u.OpenebsEventBuilder.Action(a) return u } // SetLabel sets the label for an event func (u *Usage) SetLabel(l string) *Usage { - u.label = l + u.OpenebsEventBuilder.Label(l) return u } // SetValue sets the value for an event's label -func (u *Usage) SetValue(v int64) *Usage { - u.value = v +func (u *Usage) SetValue(v string) *Usage { + u.OpenebsEventBuilder.Value(v) return u } // Build is a builder method for Usage struct -func (u *Usage) Build() *Usage { - // Default ApplicationID for openebs project is OpenEBS +func (u *Usage) CommonBuild() *Usage { v := NewVersion() _ = v.getVersion(false) - u.SetApplicationID(AppName). - SetTrackingID(GAclientID). - SetClientID(v.id). - SetCampaignSource(v.installerType) - // TODO: Add condition for version over-ride - // Case: CAS/Jiva version, etc + + u.OpenebsEventBuilder. + Project(AppName). + EngineInstaller(v.installerType) + return u } @@ -210,28 +94,18 @@ func (u *Usage) Build() *Usage { func (u *Usage) ApplicationBuilder() *Usage { v := NewVersion() _ = v.getVersion(false) - u.SetApplicationVersion(v.openebsVersion). - SetApplicationName(v.k8sArch). - SetApplicationInstallerID(v.k8sVersion). - SetDataSource(v.nodeType) + + u.AnalyticsClient.SetClientId(v.id) + + u.OpenebsEventBuilder.EngineVersion(v.openebsVersion).EngineName(DefaultCASType).EngineInstaller(v.installerType).NodeArch(v.nodeArch).NodeOs(v.nodeOs).NodeKernelVersion(v.nodeKernelVersion) + return u } // SetVolumeCapacity sets the storage capacity of the volume for a volume event func (u *Usage) SetVolumeCapacity(volCapG string) *Usage { s, _ := toGigaUnits(volCapG) - u.SetValue(s) - return u -} - -// SetVolumeType Wrapper for setting the default storage-engine for volume-provision event -func (u *Usage) SetVolumeType(volType, method string) *Usage { - if method == VolumeProvision && volType == "" { - // Set the default storage engine, if not specified in the request - u.SetApplicationName(DefaultCASType) - } else { - u.SetApplicationName(volType) - } + u.SetValue(strconv.FormatInt(s, 10)) return u } @@ -242,11 +116,11 @@ func (u *Usage) SetReplicaCount(count, method string) *Usage { if method == VolumeProvision && count == "" { // Case: When volume-provision the replica count isn't specified // it is set to three by default by the m-apiserver - u.SetAction(DefaultReplicaCount) + u.OpenebsEventBuilder.Action(DefaultReplicaCount) } else { // Catch all case for volume-deprovision event and // volume-provision event with an overridden replica-count - u.SetAction(Replica + count) + u.OpenebsEventBuilder.Action(Replica + count) } return u } @@ -256,12 +130,153 @@ func (u *Usage) InstallBuilder(override bool) *Usage { v := NewVersion() clusterSize, _ := k8sapi.NumberOfNodes() _ = v.getVersion(override) - u.SetApplicationVersion(v.openebsVersion). - SetApplicationName(v.k8sArch). - SetApplicationInstallerID(v.k8sVersion). - SetDataSource(v.nodeType). - SetDocumentTitle(v.id). - SetApplicationID(AppName). - NewEvent(InstallEvent, RunningStatus, EventLabelNode, int64(clusterSize)) + + u.AnalyticsClient.SetClientId(v.id) + + u.OpenebsEventBuilder. + EngineVersion(v.openebsVersion). + EngineInstaller(v.installerType). + EngineName(DefaultCASType). + NodeArch(v.nodeArch). + NodeOs(v.nodeOs). + NodeKernelVersion(v.nodeKernelVersion). + ResourceId(v.id). + Project(AppName). + Category(InstallEvent). + Action(RunningStatus). + Label(EventLabelNode). + Value(strconv.Itoa(clusterSize)) + return u } + + +// // NewEvent returns an Event struct with eventCategory, eventAction, +// // eventLabel, eventValue fields +// func (u *Usage) NewEvent(c, a, l string, v int64) *Usage { +// u.category = c +// u.action = a +// u.label = l +// u.value = v +// return u +// } + +// // Application struct holds details about the Application +// type Application struct { +// // eg. project version +// appVersion string + +// // eg. kubernetes version +// appInstallerID string + +// // Name of the application, usage(OpenEBS/NDM) +// appID string + +// // eg. usage(os-type/architecture) of system or volume's CASType +// appName string +// } + +// // Gclient struct represents a Google Analytics hit +// type Gclient struct { +// // constant tracking-id used to send a hit +// trackID string + +// // anonymous client-id +// clientID string + +// // 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 + +// // Document-title property in Google Analytics +// // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dt +// // use-case: uuid of the volume objects or a uuid to anonymously tell objects apart +// documentTitle string +// } + + +// // SetDataSource : usage(os-type, kernel) +// func (u *Usage) SetDataSource(dataSource string) *Usage { +// u.dataSource = dataSource +// return u +// } + +// // SetTrackingID Sets the GA-code for the project +// func (u *Usage) SetTrackingID(track string) *Usage { +// u.trackID = track +// return u +// } + +// // SetCampaignSource : source of openebs installater like: +// // helm or operator etc. This will have to be configured +// // via ENV variable OPENEBS_IO_INSTALLER_TYPE +// func (u *Usage) SetCampaignSource(campaignSrc string) *Usage { +// u.campaignSource = campaignSrc +// return u +// } + +// // SetApplicationName : usecase(os-type/arch, volume CASType) +// func (u *Usage) SetApplicationName(appName string) *Usage { +// u.appName = appName +// 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 +// return u +// } + +// // SetApplicationVersion : usecase(project-version) +// func (u *Usage) SetApplicationVersion(appVersion string) *Usage { +// u.appVersion = appVersion +// return u +// } + +// // SetApplicationInstallerID : usecase(k8s-version) +// func (u *Usage) SetApplicationInstallerID(appInstallerID string) *Usage { +// u.appInstallerID = appInstallerID +// return u +// } + +// // SetClientID sets the anonymous user id +// func (u *Usage) SetClientID(userID string) *Usage { +// u.clientID = userID +// return u +// } + +// u.SetApplicationVersion(v.openebsVersion). +// SetApplicationName(v.k8sArch). +// SetApplicationInstallerID(v.k8sVersion). +// SetDataSource(v.nodeType) + +// u.SetApplicationVersion(v.openebsVersion). +// SetApplicationName(v.k8sArch). +// SetApplicationInstallerID(v.k8sVersion). +// SetDataSource(v.nodeType). +// SetDocumentTitle(v.id). +// SetApplicationID(AppName). +// NewEvent(InstallEvent, RunningStatus, EventLabelNode, int64(clusterSize)) + +// // SetVolumeType Wrapper for setting the default storage-engine for volume-provision event +// func (u *Usage) SetVolumeType(volType, method string) *Usage { +// if method == VolumeProvision && volType == "" { +// // Set the default storage engine, if not specified in the request +// u.SetApplicationName(DefaultCASType) +// } else { +// u.SetApplicationName(volType) +// } +// return u +// } \ No newline at end of file diff --git a/pkg/usage/versionset.go b/pkg/usage/versionset.go index 0d775878..329125dd 100644 --- a/pkg/usage/versionset.go +++ b/pkg/usage/versionset.go @@ -17,6 +17,8 @@ limitations under the License. package usage import ( + "strings" + k8sapi "github.com/openebs/lib-csi/pkg/client/k8s" "github.com/openebs/lib-csi/pkg/common/env" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,23 +28,25 @@ import ( ) var ( - clusterUUID = "OPENEBS_IO_USAGE_UUID" - clusterVersion = "OPENEBS_IO_K8S_VERSION" - clusterArch = "OPENEBS_IO_K8S_ARCH" - openEBSversion = "OPENEBS_IO_VERSION_TAG" - nodeType = "OPENEBS_IO_NODE_TYPE" - installerType = "OPENEBS_IO_INSTALLER_TYPE" + clusterUUID = "OPENEBS_IO_USAGE_UUID" + k8sVersion = "OPENEBS_IO_K8S_VERSION" + nodeArch = "OPENEBS_IO_K8S_ARCH" + openEBSversion = "OPENEBS_IO_VERSION_TAG" + nodeOs = "OPENEBS_IO_NODE_OS" + nodeKernelVersion = "OPENEBS_IO_NODE_KERNEL_VERSION" + installerType = "OPENEBS_IO_INSTALLER_TYPE" ) // VersionSet is a struct which stores (sort of) fixed information about a // k8s environment type VersionSet struct { - id string // OPENEBS_IO_USAGE_UUID - k8sVersion string // OPENEBS_IO_K8S_VERSION - k8sArch string // OPENEBS_IO_K8S_ARCH - openebsVersion string // OPENEBS_IO_VERSION_TAG - nodeType string // OPENEBS_IO_NODE_TYPE - installerType string // OPENEBS_IO_INSTALLER_TYPE + id string // OPENEBS_IO_USAGE_UUID + k8sVersion string // OPENEBS_IO_K8S_VERSION + nodeArch string // OPENEBS_IO_K8S_ARCH + openebsVersion string // OPENEBS_IO_VERSION_TAG + nodeOs string // OPENEBS_IO_NODE_OS + nodeKernelVersion string // OPENEBS_IO_NODE_KERNEL_VERSION + installerType string // OPENEBS_IO_INSTALLER_TYPE } // NewVersion returns a new versionSet struct @@ -65,13 +69,16 @@ func (v *VersionSet) fetchAndSetVersion() error { return err } // eg. linux/amd64 - v.k8sArch = k8s.Platform + v.nodeArch = k8s.Platform v.k8sVersion = k8s.GitVersion // Explicitly informing linters that we intended to avoid errors(errcheck) - _ = env.Set(clusterArch, v.k8sArch) - _ = env.Set(clusterVersion, v.k8sVersion) - v.nodeType, err = k8sapi.GetOSAndKernelVersion() - _ = env.Set(nodeType, v.nodeType) + _ = env.Set(nodeArch, v.nodeArch) + _ = env.Set(k8sVersion, v.k8sVersion) + info, err := k8sapi.GetOSAndKernelVersion() + v.nodeOs = strings.Split(info, " ")[0] + v.nodeKernelVersion = strings.Split(info, " ")[1] + _ = env.Set(nodeOs, v.nodeOs) + _ = env.Set(nodeKernelVersion, v.nodeKernelVersion) if err != nil { return err } @@ -92,9 +99,10 @@ func (v *VersionSet) getVersion(override bool) error { } // Fetch data from ENV v.id = env.Get(clusterUUID) - v.k8sArch = env.Get(clusterArch) - v.k8sVersion = env.Get(clusterVersion) - v.nodeType = env.Get(nodeType) + v.nodeArch = env.Get(nodeArch) + v.k8sVersion = env.Get(k8sVersion) + v.nodeOs = env.Get(nodeOs) + v.nodeKernelVersion = env.Get(nodeKernelVersion) v.openebsVersion = env.Get(openEBSversion) v.installerType = env.Get(installerType) return nil