Skip to content

Commit b131dc5

Browse files
committed
Do not add roleMetrics when row is not valid
Signed-off-by: Jocelyn Thode <jocelyn@thode.email>
1 parent 3c1fb00 commit b131dc5

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

collector/pg_roles.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ func (c PGRolesCollector) Update(ctx context.Context, instance *instance, ch cha
7171
return err
7272
}
7373

74-
rolnameLabel := "unknown"
75-
if rolname.Valid {
76-
rolnameLabel = rolname.String
74+
if !rolname.Valid {
75+
continue
7776
}
77+
rolnameLabel := rolname.String
7878

79-
connLimitMetric := 0.0
80-
if connLimit.Valid {
81-
connLimitMetric = float64(connLimit.Int64)
79+
if !connLimit.Valid {
80+
continue
8281
}
82+
connLimitMetric := float64(connLimit.Int64)
8383

8484
ch <- prometheus.MustNewConstMetric(
8585
pgRolesConnectionLimitsDesc,

collector/pg_roles_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ func TestPGRolesCollectorNullMetric(t *testing.T) {
7979
}
8080
}()
8181

82-
expected := []MetricResult{
83-
{labels: labelMap{"rolname": "unknown"}, value: 0, metricType: dto.MetricType_GAUGE},
84-
}
82+
expected := []MetricResult{}
8583
convey.Convey("Metrics comparison", t, func() {
8684
for _, expect := range expected {
8785
m := readMetric(<-ch)

0 commit comments

Comments
 (0)