diff options
author | John Cai <jcai@gitlab.com> | 2019-07-10 19:30:10 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-07-10 19:30:10 +0300 |
commit | e6b278d5b08aae16d83dc252d58452ea11173188 (patch) | |
tree | 4962da76714c300d7b752c3f13b3982ceee50ffe | |
parent | ac59f1a3e386d7a6d867136c2f5282ee5cb86e61 (diff) | |
parent | ddf73390db3e907f0c0614a7b8031f7cbc10601b (diff) |
Merge branch 'zj-praefect-version' into 'master'
Export the Praefect version running
Closes #1499
See merge request gitlab-org/gitaly!1358
-rw-r--r-- | changelogs/unreleased/zj-praefect-version.yml | 5 | ||||
-rw-r--r-- | cmd/praefect/main.go | 32 | ||||
-rw-r--r-- | internal/praefect/version.go | 22 |
3 files changed, 57 insertions, 2 deletions
diff --git a/changelogs/unreleased/zj-praefect-version.yml b/changelogs/unreleased/zj-praefect-version.yml new file mode 100644 index 000000000..c5c5259c9 --- /dev/null +++ b/changelogs/unreleased/zj-praefect-version.yml @@ -0,0 +1,5 @@ +--- +title: Expose the Praefect server version +merge_request: 1358 +author: +type: added diff --git a/cmd/praefect/main.go b/cmd/praefect/main.go index b4efeeae9..37fdddb22 100644 --- a/cmd/praefect/main.go +++ b/cmd/praefect/main.go @@ -13,16 +13,19 @@ import ( "syscall" "time" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/praefect" "gitlab.com/gitlab-org/gitaly/internal/praefect/config" + "gitlab.com/gitlab-org/gitaly/internal/version" "gitlab.com/gitlab-org/labkit/tracing" ) var ( - flagConfig = flag.String("config", "", "Location for the config.toml") - logger = logrus.New() + flagConfig = flag.String("config", "", "Location for the config.toml") + flagVersion = flag.Bool("version", false, "Print version and exit") + logger = logrus.New() errNoConfigFile = errors.New("the config flag must be passed") ) @@ -30,6 +33,12 @@ var ( func main() { flag.Parse() + // If invoked with -version + if *flagVersion { + fmt.Println(version.GetVersionString()) + os.Exit(0) + } + conf, err := configure() if err != nil { logger.Fatal(err) @@ -74,6 +83,9 @@ func configure() (config.Config, error) { }() } + registerServerVersionPromGauge() + logger.WithField("version", praefect.GetVersionString()).Info("Starting Praefect") + return conf, nil } @@ -161,3 +173,19 @@ func getListeners(socketPath, listenAddr string) ([]net.Listener, error) { return listeners, nil } + +// 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() { + gitlabBuildInfoGauge := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "gitlab_build_info", + Help: "Current build info for this GitLab Service", + ConstLabels: prometheus.Labels{ + "version": praefect.GetVersion(), + "built": praefect.GetBuildTime(), + }, + }) + + prometheus.MustRegister(gitlabBuildInfoGauge) + gitlabBuildInfoGauge.Set(1) +} diff --git a/internal/praefect/version.go b/internal/praefect/version.go new file mode 100644 index 000000000..25758f35a --- /dev/null +++ b/internal/praefect/version.go @@ -0,0 +1,22 @@ +package praefect + +import ( + "fmt" + + "gitlab.com/gitlab-org/gitaly/internal/version" +) + +// GetVersionString returns a standard version header +func GetVersionString() string { + return fmt.Sprintf("Praefect, version %v", version.GetVersion()) +} + +// GetVersion returns the semver compatible version number +func GetVersion() string { + return version.GetVersion() +} + +// GetBuildTime returns the time at which the build took place +func GetBuildTime() string { + return version.GetBuildTime() +} |