diff --git a/cmd/inventory.go b/cmd/inventory.go index 21867cf..f007d09 100644 --- a/cmd/inventory.go +++ b/cmd/inventory.go @@ -6,14 +6,16 @@ import ( "github.com/equinix-labs/otel-init-go/otelinit" "github.com/metal-toolbox/fleet-scheduler/internal/app" "github.com/metal-toolbox/fleet-scheduler/internal/client" + "github.com/metal-toolbox/fleet-scheduler/internal/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/net/context" ) var cmdInventory = &cobra.Command{ - Use: "inventory", - Short: "gather all servers and create invetory for them", + Use: "inventory", + Short: "gather all servers and create invetory for them", + Version: version.Current().String(), Run: func(cmd *cobra.Command, args []string) { err := inventory(cmd.Context()) if err != nil { @@ -44,6 +46,14 @@ func inventory(ctx context.Context) error { return err } + v := version.Current() + logger.WithFields(logrus.Fields{ + "GitCommit": v.GitCommit, + "AppVersion": v.AppVersion, + "ServerServiceVersion:": v.ServerserviceVersion, // TODO; Swap out with fleetdb once migrated to fleetdb + "ConditionOrcVersion:": v.ConditionorcVersion, + }).Info("running task: inventory") + newClient, err := client.New(otelCtxWithCancel, cfg, logger) if err != nil { return err diff --git a/cmd/root.go b/cmd/root.go index 908eb33..5fbac07 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,16 +4,16 @@ import ( "fmt" "os" + "github.com/metal-toolbox/fleet-scheduler/internal/version" "github.com/spf13/cobra" ) var cfgFile string var rootCmd = &cobra.Command{ - Use: "fleet-scheduler", - Short: "execute commands to manage the fleet", - - DisableAutoGenTag: true, + Use: "fleet-scheduler", + Short: "execute commands to manage the fleet", + Version: version.Current().String(), } func Execute() { diff --git a/cmd/test.go b/cmd/test.go index 4c12391..cef711d 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -8,14 +8,16 @@ import ( "github.com/equinix-labs/otel-init-go/otelinit" "github.com/metal-toolbox/fleet-scheduler/internal/app" "github.com/metal-toolbox/fleet-scheduler/internal/client" + "github.com/metal-toolbox/fleet-scheduler/internal/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/net/context" ) var cmdTest = &cobra.Command{ - Use: "test", - Short: "test", + Use: "test", + Short: "test", + Version: version.Current().String(), Run: func(cmd *cobra.Command, args []string) { err := test(cmd.Context()) if err != nil { @@ -47,6 +49,12 @@ func test(ctx context.Context) error { return err } + v := version.Current() + logger.WithFields(logrus.Fields{ + "GitCommit": v.GitCommit, + "AppVersion": v.AppVersion, + }).Info("running task: test") + // Just used to verify fleet-scheduler can authenticate _, err = client.New(otelCtxWithCancel, cfg, logger) if err != nil { diff --git a/internal/version/version.go b/internal/version/version.go index 7169549..93d1d0a 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -1,12 +1,10 @@ package version import ( + "fmt" "runtime" rdebug "runtime/debug" "strings" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" ) var ( @@ -31,8 +29,8 @@ type Version struct { ConditionorcVersion string `json:"conditionorc_version"` } -func Current() Version { - return Version{ +func Current() *Version { + return &Version{ GitBranch: GitBranch, GitCommit: GitCommit, GitSummary: GitSummary, @@ -44,16 +42,8 @@ func Current() Version { } } -func ExportBuildInfoMetric() { - buildInfo := promauto.NewGaugeVec( - prometheus.GaugeOpts{ - Name: "fleet-scheduler_build_info", - Help: "A metric with a constant '1' value, labeled by branch, commit, summary, builddate, version, goversion from which Fleet Scheduler was built.", - }, - []string{"branch", "commit", "summary", "builddate", "version", "goversion", "conditionorcVersion", "serverserviceVersion"}, - ) - - buildInfo.WithLabelValues(GitBranch, GitCommit, GitSummary, BuildDate, AppVersion, GoVersion, ConditionorcVersion, ServerserviceVersion).Set(1) +func (v *Version) String() string { + return fmt.Sprintf("version=%s ref=%s branch=%s built=%s", v.AppVersion, v.GitCommit, v.GitBranch, v.BuildDate) } func serverserviceVersion() string {