diff options
author | Ahmad Sherif <ahmad.m.sherif@gmail.com> | 2017-10-10 17:51:22 +0300 |
---|---|---|
committer | Ahmad Sherif <ahmad.m.sherif@gmail.com> | 2017-10-10 17:51:22 +0300 |
commit | 7df1c3b321f02055faf8451de5fca1f232d6008f (patch) | |
tree | b9872e0d8b0fbba87977238b7a33ac90b17e0930 | |
parent | e909b8267e543f6b1a12ede56f44512d00c93b7e (diff) | |
parent | 7e5606eacc5d0a0c1b42268c356e0baff94e824f (diff) |
Merge branch '260-git-version-prometheus' into 'master'
Include git-version in gitaly_build_info metrics
Closes #260
See merge request gitlab-org/gitaly!400
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | cmd/gitaly/main.go | 11 | ||||
-rw-r--r-- | internal/git/helper.go | 25 |
3 files changed, 36 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b498e63cc..98ca11a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ UNRELEASED +- Add `git version` to `gitaly_build_info` metrics + https://gitlab.com/gitlab-org/gitaly/merge_requests/400 - Use relative paths for git object dir attributes https://gitlab.com/gitlab-org/gitaly/merge_requests/393 diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go index 1ba31c693..749a53253 100644 --- a/cmd/gitaly/main.go +++ b/cmd/gitaly/main.go @@ -13,6 +13,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/connectioncounter" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/linguist" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/server" @@ -47,12 +48,18 @@ func loadConfig(configPath string) error { // registerServerVersionPromGauge registers a label with the current server version // making it easy to see what versions of Gitaly are running across a cluster func registerServerVersionPromGauge() { + gitVersion, err := git.Version() + if err != nil { + fmt.Printf("git version: %v\n", err) + os.Exit(1) + } gitlabBuildInfoGauge := prometheus.NewGauge(prometheus.GaugeOpts{ Name: "gitlab_build_info", Help: "Current build info for this GitLab Service", ConstLabels: prometheus.Labels{ - "version": version.GetVersion(), - "built": version.GetBuildTime(), + "version": version.GetVersion(), + "built": version.GetBuildTime(), + "git_version": gitVersion, }, }) diff --git a/internal/git/helper.go b/internal/git/helper.go index dc755f437..00966d4d0 100644 --- a/internal/git/helper.go +++ b/internal/git/helper.go @@ -2,11 +2,15 @@ package git import ( "bytes" + "context" "fmt" + "os/exec" + "strings" "time" "github.com/golang/protobuf/ptypes/timestamp" pb "gitlab.com/gitlab-org/gitaly-proto/go" + "gitlab.com/gitlab-org/gitaly/internal/command" ) // FallbackTimeValue is the value returned by `SafeTimeParse` in case it @@ -64,3 +68,24 @@ func NewCommit(id, subject, body, authorName, authorEmail, authorDate, ParentIds: parentIds, }, nil } + +// Version returns the used git version. +func Version() (string, error) { + var buf bytes.Buffer + cmd, err := command.New(context.Background(), exec.Command(command.GitPath(), "version"), nil, &buf, nil) + if err != nil { + return "", err + } + + if err = cmd.Wait(); err != nil { + return "", err + } + + out := strings.Trim(buf.String(), " \n") + ver := strings.SplitN(out, " ", 3) + if len(ver) != 3 { + return "", fmt.Errorf("invalid version format: %q", buf.String()) + } + + return ver[2], nil +} |