diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-07-09 14:49:03 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-07-09 14:53:24 +0300 |
commit | ddf73390db3e907f0c0614a7b8031f7cbc10601b (patch) | |
tree | 2dddf2f128fbbd093135775b2a493551db7e718d | |
parent | 46856e1fd24d25f22289beefa472736aadc38652 (diff) |
Export the Praefect version running
Praefect didn't expose the version running, which makes debugging
harder. This change follows conventions set by Gitaly.
A few ways of exposing the version are implemented:
1. Through the `-version` flag
2. Logging the version at boot of the server
3. A prometheus metric, the metric is stale, but the labels are not
Closes https://gitlab.com/gitlab-org/gitaly/issues/1499
-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() +} |