From e582e5f88ce25c2fdb42c8e0b4d7c07271bb7fbd Mon Sep 17 00:00:00 2001 From: Alexey Lesovsky Date: Thu, 5 Aug 2021 10:27:53 +0500 Subject: [PATCH] Add version string label to patroni_version metric. --- internal/collector/patroni_common.go | 6 ++++-- internal/collector/patroni_common_test.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/collector/patroni_common.go b/internal/collector/patroni_common.go index e837287..9808789 100644 --- a/internal/collector/patroni_common.go +++ b/internal/collector/patroni_common.go @@ -48,7 +48,7 @@ func NewPatroniCommonCollector(constLabels labels, settings model.CollectorSetti version: newBuiltinTypedDesc( descOpts{"patroni", "", "version", "Numeric representation of Patroni version.", 0}, prometheus.GaugeValue, - varLabels, constLabels, + []string{"scope", "version"}, constLabels, settings.Filters, ), pgup: newBuiltinTypedDesc( @@ -175,7 +175,7 @@ func (c *patroniCommonCollector) Update(config Config, ch chan<- prometheus.Metr return err } - ch <- c.version.newConstMetric(info.version, info.scope) + ch <- c.version.newConstMetric(info.version, info.scope, info.versionStr) ch <- c.pgup.newConstMetric(info.running, info.scope) ch <- c.pgstart.newConstMetric(info.startTime, info.scope) @@ -239,6 +239,7 @@ type apiPatroniResponse struct { type patroniInfo struct { scope string version float64 + versionStr string running float64 startTime float64 master float64 @@ -331,6 +332,7 @@ func parsePatroniResponse(resp *apiPatroniResponse) (*patroniInfo, error) { return &patroniInfo{ scope: resp.Patroni.Scope, version: float64(version), + versionStr: resp.Patroni.Version, running: running, startTime: float64(t1.UnixNano()) / 1000000000, master: master, diff --git a/internal/collector/patroni_common_test.go b/internal/collector/patroni_common_test.go index 1d44748..27d00d9 100644 --- a/internal/collector/patroni_common_test.go +++ b/internal/collector/patroni_common_test.go @@ -98,7 +98,7 @@ func Test_parsePatroniResponse(t *testing.T) { Xlog: patroniXlogInfo{Location: 67111576, ReceivedLocation: 0, ReplayedLocation: 0, ReplayedTimestamp: "", Paused: false}, }, want: &patroniInfo{ - scope: "demo", version: 20002, running: 1, startTime: 1624864724.5653172, + scope: "demo", version: 20002, versionStr: "2.0.2", running: 1, startTime: 1624864724.5653172, master: 1, standbyLeader: 0, replica: 0, xlogLoc: 67111576, xlogRecvLoc: 0, xlogReplLoc: 0, xlogReplTs: 0, xlogPaused: 0, pgversion: 100016, unlocked: 0, timeline: 1, @@ -117,7 +117,7 @@ func Test_parsePatroniResponse(t *testing.T) { Xlog: patroniXlogInfo{Location: 0, ReceivedLocation: 67211944, ReplayedLocation: 67211944, ReplayedTimestamp: "2021-07-09 05:30:41.207477+00:00", Paused: true}, }, want: &patroniInfo{ - scope: "demo", version: 20100, running: 1, startTime: 1625585463.056298, + scope: "demo", version: 20100, versionStr: "2.1.0", running: 1, startTime: 1625585463.056298, master: 0, standbyLeader: 0, replica: 1, xlogLoc: 0, xlogRecvLoc: 67211944, xlogReplLoc: 67211944, xlogReplTs: 1625808641.207477, xlogPaused: 1, pgversion: 100016, unlocked: 1, timeline: 1,