Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2017-10-09 23:00:36 +0300
committerAhmad Sherif <me@ahmadsherif.com>2017-10-10 17:45:35 +0300
commit7e5606eacc5d0a0c1b42268c356e0baff94e824f (patch)
treeb9872e0d8b0fbba87977238b7a33ac90b17e0930
parente909b8267e543f6b1a12ede56f44512d00c93b7e (diff)
Include git-version in gitaly_build_info metrics
-rw-r--r--CHANGELOG.md2
-rw-r--r--cmd/gitaly/main.go11
-rw-r--r--internal/git/helper.go25
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
+}