Skip to content

Commit

Permalink
Do not add roleMetrics when row is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
jocelynthode committed Jan 24, 2024
1 parent 3c1fb00 commit 0687481
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 6 additions & 6 deletions collector/pg_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func (c PGRolesCollector) Update(ctx context.Context, instance *instance, ch cha
return err
}

rolnameLabel := "unknown"
if rolname.Valid {
rolnameLabel = rolname.String
if !rolname.Valid {
continue
}
rolnameLabel := rolname.String

connLimitMetric := 0.0
if connLimit.Valid {
connLimitMetric = float64(connLimit.Int64)
if !connLimit.Valid {
continue
}
connLimitMetric := float64(connLimit.Int64)

ch <- prometheus.MustNewConstMetric(
pgRolesConnectionLimitsDesc,
Expand Down
4 changes: 1 addition & 3 deletions collector/pg_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ func TestPGRolesCollectorNullMetric(t *testing.T) {
}
}()

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

0 comments on commit 0687481

Please sign in to comment.