Skip to content

Commit

Permalink
FS-1101; Fixing version
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Feb 9, 2024
1 parent 0a0e1b0 commit 36b87a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
14 changes: 12 additions & 2 deletions cmd/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 10 additions & 2 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 5 additions & 15 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 36b87a9

Please sign in to comment.