Skip to content

Commit

Permalink
Merge pull request #79 from rebuy-de/add-toolstack
Browse files Browse the repository at this point in the history
CLOUD-2822 add toolstack label
  • Loading branch information
svenwltr authored Jul 14, 2021
2 parents 20eb579 + 2213a9b commit c500b69
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/buildutil/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ func (i SystemInfo) Name() string {
}

type BuildInfo struct {
BuildDate string
System SystemInfo
Version Version
BuildDate string
System SystemInfo
Version Version
SDKVersion Version

Go struct {
Name string
Expand Down Expand Up @@ -231,6 +232,11 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo,
info.Commit.Hash = e.OutputString("git", "rev-parse", "HEAD")
info.Commit.Branch = e.OutputString("git", "rev-parse", "--abbrev-ref", "HEAD")

info.SDKVersion, err = ParseVersion(e.OutputString("go", "list", "-mod=readonly", "-m", "-f", "{{.Version}}", "github.com/rebuy-de/rebuy-go-sdk/..."))
if err != nil {
logrus.WithError(err).Error("Failed to parse sdk-version")
}

info.Version, err = ParseVersion(e.OutputString("git", "describe", "--always", "--dirty", "--tags"))
if err != nil {
logrus.WithError(err).Error("Failed to parse version")
Expand Down
1 change: 1 addition & 0 deletions cmd/buildutil/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (r *Runner) RunBuild(ctx context.Context, cmd *cobra.Command, args []string
{name: "GoModule", value: r.Info.Go.Module},
{name: "GoPackage", value: target.Package},
{name: "GoVersion", value: r.Info.Go.Version},
{name: "SDKVersion", value: r.Info.SDKVersion.String()},
{name: "BuildDate", value: r.Info.BuildDate},
{name: "CommitDate", value: r.Info.Commit.Date},
{name: "CommitHash", value: r.Info.Commit.Hash},
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmdutil/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
GoModule = "unknown"
GoPackage = "unknown"
GoVersion = "unknown"
SDKVersion = "unknown"
BuildDate = "unknown"
CommitDate = "unknown"
CommitHash = "unknown"
Expand All @@ -34,6 +35,7 @@ func NewVersionCommand() *cobra.Command {
fmt.Printf("GoModule: %s\n", GoModule)
fmt.Printf("GoPackage: %s\n", GoPackage)
fmt.Printf("GoVersion: %s\n", GoVersion)
fmt.Printf("SDKVersion: %s\n", SDKVersion)
fmt.Printf("BuildDate: %s\n", BuildDate)
fmt.Printf("CommitDate: %s\n", CommitDate)
fmt.Printf("CommitHash: %s\n", CommitHash)
Expand Down
33 changes: 33 additions & 0 deletions pkg/instutil/toolstack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package instutil

import (
"fmt"
"strings"

"github.com/prometheus/client_golang/prometheus"
"github.com/rebuy-de/rebuy-go-sdk/v3/pkg/cmdutil"
)

func init() {
gauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "rebuy",
Name: "toolstack",
}, []string{
"toolstack",
"language",
"language_version",
"sdk",
"sdk_version",
})
prometheus.MustRegister(gauge)

major := strings.SplitN(cmdutil.SDKVersion, ".", 2)[0]

gauge.WithLabelValues(
fmt.Sprintf("golang.rebuy-go-sdk.%s", major),
"golang",
cmdutil.GoVersion,
"rebuy-go-sdk",
cmdutil.SDKVersion,
).Set(1)
}

0 comments on commit c500b69

Please sign in to comment.