diff --git a/monitoring/serve_options.go b/monitoring/serve_options.go index 0ce2bac8019c93dea237e7e3411c095263d04f73..8206807ad021c7eb0885a533752203a1d0ffe8b1 100644 --- a/monitoring/serve_options.go +++ b/monitoring/serve_options.go @@ -52,6 +52,13 @@ func WithListenerAddress(addr string) Option { } } +// WithVersion will configure the `gitlab_build_info` metric with the version information +func WithVersion(version string) Option { + return func(config *optionsConfig) { + config.buildInfoGaugeLabels[buildInfoVersionLabel] = version + } +} + // WithBuildInformation will configure the `gitlab_build_info` metric with appropriate labels func WithBuildInformation(version string, buildTime string) Option { return func(config *optionsConfig) { diff --git a/monitoring/serve_options_test.go b/monitoring/serve_options_test.go index a6a9064cf8aac9259fa7f919362ec3df62c3a96f..82841df67a58bb536f795dbe6219696de2a4de63 100644 --- a/monitoring/serve_options_test.go +++ b/monitoring/serve_options_test.go @@ -51,6 +51,12 @@ func Test_applyOptions(t *testing.T) { opts: []Option{WithListenerAddress(":0")}, wantListenerCheck: isTCPListener, }, + { + name: "with_version", + opts: []Option{WithVersion("1.0.0")}, + wantListenerCheck: checkDefaultListener, + wantbuildInfoGaugeLabels: prometheus.Labels{"version": "1.0.0"}, + }, { name: "with_build_information", opts: []Option{WithBuildInformation("1.0.0", "2018-01-02T00:00:00Z")},