zfs-localpv/pkg/version/version.go
Pawan d608dbacd8 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>
2020-03-02 23:00:22 +05:30

119 lines
2.9 KiB
Go

/*
Copyright © 2019 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 version
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/Sirupsen/logrus"
)
var (
// GitCommit that was compiled; filled in by
// the compiler.
GitCommit string
// Version is the version of this repo; filled
// in by the compiler
Version string
// VersionMeta is a pre-release marker for the
// version. If this is "" (empty string) then
// it means that it is a final release. Otherwise,
// this is a pre-release such as "dev" (in
// development), "beta", "rc1", etc.
VersionMeta string
)
const (
versionFile string = "/src/github.com/openebs/zfs-localpv/VERSION"
buildMetaFile string = "/src/github.com/openebs/zfs-localpv/BUILDMETA"
)
// Current returns current version of csi driver
func Current() string {
return Get()
}
// Get returns current version from global
// Version variable. If Version is unset then
// from VERSION file at the root of this repo.
func Get() string {
if Version != "" {
return Version
}
path := filepath.Join(os.Getenv("GOPATH") + versionFile)
vBytes, err := ioutil.ReadFile(path)
if err != nil {
logrus.Errorf("failed to get version: %s", err.Error())
return ""
}
return strings.TrimSpace(string(vBytes))
}
// GetBuildMeta returns build type from
// global VersionMeta variable. If VersionMeta
// is unset then this is fetched from BUILDMETA
// file at the root of this repo.
func GetBuildMeta() string {
if VersionMeta != "" {
return "-" + VersionMeta
}
path := filepath.Join(os.Getenv("GOPATH") + buildMetaFile)
vBytes, err := ioutil.ReadFile(path)
if err != nil {
logrus.Errorf("failed to get build version: %s", err.Error())
return ""
}
return "-" + strings.TrimSpace(string(vBytes))
}
// GetGitCommit returns Git commit SHA-1 from
// global GitCommit variable. If GitCommit is
// unset this calls Git directly.
func GetGitCommit() string {
if GitCommit != "" {
return GitCommit
}
cmd := exec.Command("git", "rev-parse", "--verify", "HEAD")
output, err := cmd.Output()
if err != nil {
logrus.Errorf("failed to get git commit: %s", err.Error())
return ""
}
return strings.TrimSpace(string(output))
}
func GetVersionDetails() string {
return "zfs-" + strings.Join([]string{Get(), GetGitCommit()[0:7]}, "-")
}
// Verbose returns version details with git
// commit info
func Verbose() string {
return strings.Join([]string{Get(), GetGitCommit()[0:7]}, "-")
}