Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Add version string label to patroni_version metric.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Aug 5, 2021
1 parent 5ad122c commit e582e5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/collector/patroni_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -239,6 +239,7 @@ type apiPatroniResponse struct {
type patroniInfo struct {
scope string
version float64
versionStr string
running float64
startTime float64
master float64
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions internal/collector/patroni_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit e582e5f

Please sign in to comment.