From 866d094d70355a2060974f18c2ed7aac8ee6bd29 Mon Sep 17 00:00:00 2001 From: Pranay Valson Date: Fri, 16 Sep 2022 17:31:24 -0700 Subject: [PATCH] adds bsp-agent to binary run info Signed-off-by: Pranay Valson --- cmd/bspagent/main.go | 1 + internal/utils/utils.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/cmd/bspagent/main.go b/cmd/bspagent/main.go index 8f8f701c..9c50e82b 100644 --- a/cmd/bspagent/main.go +++ b/cmd/bspagent/main.go @@ -56,6 +56,7 @@ func init() { outWriter = &bspLogger } + utils.Version() log.SetOutput(outWriter) log.SetLevel(log.InfoLevel) log.WithFields(log.Fields{"file": "main.go"}).Info("bsp-agent is running...") diff --git a/internal/utils/utils.go b/internal/utils/utils.go index b4209e3b..22426248 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -12,6 +12,7 @@ import ( "os" "os/user" "path" + "runtime" "strconv" "strings" @@ -26,6 +27,24 @@ import ( "google.golang.org/api/option" ) +const ( + clientIdentifier = "bspagent" // Client identifier to advertise over the network +) + +const ( + // BspAgentVersionMajor is Major version component of the current release + BspAgentVersionMajor = 1 + // BspAgentVersionMinor is Minor version component of the current release + BspAgentVersionMinor = 3 + // BspAgentVersionPatch is Patch version component of the current release + BspAgentVersionPatch = 1 +) + +// BspAgentVersion holds the textual version string. +var BspAgentVersion = func() string { + return fmt.Sprintf("%d.%d.%d", BspAgentVersionMajor, BspAgentVersionMinor, BspAgentVersionPatch) +}() + // NewRedisClient provides a new redis client using a redis config func NewRedisClient(rconfig *config.RedisConfig) (*redis.Client, string, string, error) { var pwd string @@ -319,3 +338,14 @@ func MapToAvroUnion(data map[string]interface{}) map[string]interface{} { return vs } + +// Version Provides version info on bsp agent binary +func Version() { + fmt.Println(clientIdentifier) + fmt.Println("Bsp Agent Version:", BspAgentVersion) + fmt.Println("Architecture:", runtime.GOARCH) + fmt.Println("Go Version:", runtime.Version()) + fmt.Println("Operating System:", runtime.GOOS) + fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH")) + fmt.Printf("GOROOT=%s\n", runtime.GOROOT()) +}