mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 06:20:11 +01:00
feat(analytics): adding google analytics for ZFSPV
Whenever a volume is provisioned and de-provisioned we will send a google event with mainly following details : 1. pvName (will shown as app title in google analytics) 2. size of the volume 3. event type : volume-provision, volume-deprovision 4. storage type zfs-localpv 5. replicacount as 1 6. ClientId as default namespace uuid Apart from this, we send the event once in 24 hr, which will have some info like number of nodes, node type, kubernetes version etc. This metric is cotrolled by OPENEBS_IO_ENABLE_ANALYTICS env. We can set it to false if we don't want to send the metrics. Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
parent
0fc86d843b
commit
d608dbacd8
28 changed files with 1731 additions and 18 deletions
111
pkg/usage/versionset.go
Normal file
111
pkg/usage/versionset.go
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
Copyright 2020 The OpenEBS Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package usage
|
||||
|
||||
import (
|
||||
k8sapi "github.com/openebs/zfs-localpv/pkg/client/k8s/v1alpha1"
|
||||
env "github.com/openebs/zfs-localpv/pkg/common/env"
|
||||
openebsversion "github.com/openebs/zfs-localpv/pkg/version"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// NewVersion returns a new versionSet struct
|
||||
func NewVersion() *versionSet {
|
||||
return &versionSet{}
|
||||
}
|
||||
|
||||
// fetchAndSetVersion consumes the Kubernetes API to get environment constants
|
||||
// and returns a versionSet struct
|
||||
func (v *versionSet) fetchAndSetVersion() error {
|
||||
var err error
|
||||
v.id, err = getUUIDbyNS("default")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
env.Set(clusterUUID, v.id)
|
||||
|
||||
k8s, err := k8sapi.GetServerVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// eg. linux/amd64
|
||||
v.k8sArch = k8s.Platform
|
||||
v.k8sVersion = k8s.GitVersion
|
||||
env.Set(clusterArch, v.k8sArch)
|
||||
env.Set(clusterVersion, v.k8sVersion)
|
||||
v.nodeType, err = k8sapi.GetOSAndKernelVersion()
|
||||
env.Set(nodeType, v.nodeType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.openebsVersion = openebsversion.GetVersionDetails()
|
||||
env.Set(openEBSversion, v.openebsVersion)
|
||||
return nil
|
||||
}
|
||||
|
||||
// getVersion is a wrapper over fetchAndSetVersion
|
||||
func (v *versionSet) getVersion(override bool) error {
|
||||
// If ENVs aren't set or the override is true, fetch the required
|
||||
// values from the K8s APIserver
|
||||
if _, present := env.Lookup(openEBSversion); !present || override {
|
||||
if err := v.fetchAndSetVersion(); err != nil {
|
||||
klog.Error(err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 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.openebsVersion = env.Get(openEBSversion)
|
||||
v.installerType = env.Get(installerType)
|
||||
return nil
|
||||
}
|
||||
|
||||
// getUUIDbyNS returns the metadata.object.uid of a namespace in Kubernetes
|
||||
func getUUIDbyNS(namespace string) (string, error) {
|
||||
ns := k8sapi.Namespace()
|
||||
NSstruct, err := ns.Get(namespace, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if NSstruct != nil {
|
||||
return string(NSstruct.GetObjectMeta().GetUID()), nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue