Skip to content

Commit

Permalink
Be more go-like
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Yuan <felix.yuan@reddit.com>
  • Loading branch information
Sticksman committed Jun 25, 2023
1 parent cec3fb5 commit 19cf776
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions collector/pg_process_idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch cha
applicationNameLabel = applicationName.String
}

var secondsCountMetric uint64
var secondsCountMetric uint64 = 0
if secondsCount.Valid {
secondsCountMetric = uint64(secondsCount.Int64)
}
var secondsSumMetric float64
secondsSumMetric := 0.0
if secondsSum.Valid {
secondsSumMetric = float64(secondsSum.Int64)
}
Expand Down
6 changes: 3 additions & 3 deletions collector/pg_replication_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance
return err
}

isActiveValue := 0
isActiveValue := 0.0
if isActive.Valid && isActive.Bool {
isActiveValue = 1
isActiveValue = 1.0
}
slotNameLabel := "unknown"
if slotName.Valid {
Expand All @@ -120,7 +120,7 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance
}
ch <- prometheus.MustNewConstMetric(
pgReplicationSlotIsActiveDesc,
prometheus.GaugeValue, float64(isActiveValue), slotNameLabel,
prometheus.GaugeValue, isActiveValue, slotNameLabel,
)
}
if err := rows.Err(); err != nil {
Expand Down
22 changes: 11 additions & 11 deletions collector/pg_stat_bgwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
return err
}

var cptMetric float64
cptMetric := 0.0
if cpt.Valid {
cptMetric = float64(cpt.Int64)
}
Expand All @@ -139,7 +139,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
cptMetric,
)
var cprMetric float64
cprMetric := 0.0
if cpr.Valid {
cprMetric = float64(cpr.Int64)
}
Expand All @@ -148,7 +148,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
cprMetric,
)
var cpwtMetric float64
cpwtMetric := 0.0
if cpwt.Valid {
cpwtMetric = float64(cpwt.Float64)
}
Expand All @@ -157,7 +157,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
cpwtMetric,
)
var cpstMetric float64
cpstMetric := 0.0
if cpst.Valid {
cpstMetric = float64(cpst.Float64)
}
Expand All @@ -166,7 +166,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
cpstMetric,
)
var bcpMetric float64
bcpMetric := 0.0
if bcp.Valid {
bcpMetric = float64(bcp.Int64)
}
Expand All @@ -175,7 +175,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
bcpMetric,
)
var bcMetric float64
bcMetric := 0.0
if bc.Valid {
bcMetric = float64(bc.Int64)
}
Expand All @@ -184,7 +184,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
bcMetric,
)
var mwcMetric float64
mwcMetric := 0.0
if mwc.Valid {
mwcMetric = float64(mwc.Int64)
}
Expand All @@ -193,7 +193,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
mwcMetric,
)
var bbMetric float64
bbMetric := 0.0
if bb.Valid {
bbMetric = float64(bb.Int64)
}
Expand All @@ -202,7 +202,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
bbMetric,
)
var bbfMetric float64
bbfMetric := 0.0
if bbf.Valid {
bbfMetric = float64(bbf.Int64)
}
Expand All @@ -211,7 +211,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
bbfMetric,
)
var baMetric float64
baMetric := 0.0
if ba.Valid {
baMetric = float64(ba.Int64)
}
Expand All @@ -220,7 +220,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
prometheus.CounterValue,
baMetric,
)
var srMetric float64
srMetric := 0.0
if sr.Valid {
srMetric = float64(sr.Time.Unix())
}
Expand Down
34 changes: 17 additions & 17 deletions collector/pg_stat_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel = datname.String
}

var numBackendsMetric float64
numBackendsMetric := 0.0
if numBackends.Valid {
numBackendsMetric = numBackends.Float64
}
Expand All @@ -288,7 +288,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var xactCommitMetric float64
xactCommitMetric := 0.0
if xactCommit.Valid {
xactCommitMetric = xactCommit.Float64
}
Expand All @@ -300,7 +300,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var xactRollbackMetric float64
xactRollbackMetric := 0.0
if xactRollback.Valid {
xactRollbackMetric = xactRollback.Float64
}
Expand All @@ -312,7 +312,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var blksReadMetric float64
blksReadMetric := 0.0
if blksRead.Valid {
blksReadMetric = blksRead.Float64
}
Expand All @@ -324,7 +324,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var blksHitMetric float64
blksHitMetric := 0.0
if blksHit.Valid {
blksHitMetric = blksHit.Float64
}
Expand All @@ -336,7 +336,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var tupReturnedMetric float64
tupReturnedMetric := 0.0
if tupReturned.Valid {
tupReturnedMetric = tupReturned.Float64
}
Expand All @@ -348,7 +348,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var tupFetchedMetric float64
tupFetchedMetric := 0.0
if tupFetched.Valid {
tupFetchedMetric = tupFetched.Float64
}
Expand All @@ -360,7 +360,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var tupInsertedMetric float64
tupInsertedMetric := 0.0
if tupInserted.Valid {
tupInsertedMetric = tupInserted.Float64
}
Expand All @@ -372,7 +372,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var tupUpdatedMetric float64
tupUpdatedMetric := 0.0
if tupUpdated.Valid {
tupUpdatedMetric = tupUpdated.Float64
}
Expand All @@ -384,7 +384,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var tupDeletedMetric float64
tupDeletedMetric := 0.0
if tupDeleted.Valid {
tupDeletedMetric = tupDeleted.Float64
}
Expand All @@ -396,7 +396,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var conflictsMetric float64
conflictsMetric := 0.0
if conflicts.Valid {
conflictsMetric = conflicts.Float64
}
Expand All @@ -408,7 +408,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var tempFilesMetric float64
tempFilesMetric := 0.0
if tempFiles.Valid {
tempFilesMetric = tempFiles.Float64
}
Expand All @@ -420,7 +420,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var tempBytesMetric float64
tempBytesMetric := 0.0
if tempBytes.Valid {
tempBytesMetric = tempBytes.Float64
}
Expand All @@ -432,7 +432,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var deadlocksMetric float64
deadlocksMetric := 0.0
if deadlocks.Valid {
deadlocksMetric = deadlocks.Float64
}
Expand All @@ -444,7 +444,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var blkReadTimeMetric float64
blkReadTimeMetric := 0.0
if blkReadTime.Valid {
blkReadTimeMetric = blkReadTime.Float64
}
Expand All @@ -456,7 +456,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var blkWriteTimeMetric float64
blkWriteTimeMetric := 0.0
if blkWriteTime.Valid {
blkWriteTimeMetric = blkWriteTime.Float64
}
Expand All @@ -468,7 +468,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
datnameLabel,
)

var statsResetMetric float64
statsResetMetric := 0.0
if statsReset.Valid {
statsResetMetric = float64(statsReset.Time.Unix())
}
Expand Down
10 changes: 5 additions & 5 deletions collector/pg_stat_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
queryidLabel = queryid.String
}

var callsTotalMetric float64
callsTotalMetric := 0.0
if callsTotal.Valid {
callsTotalMetric = float64(callsTotal.Int64)
}
Expand All @@ -134,7 +134,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
userLabel, datnameLabel, queryidLabel,
)

var secondsTotalMetric float64
secondsTotalMetric := 0.0
if secondsTotal.Valid {
secondsTotalMetric = secondsTotal.Float64
}
Expand All @@ -145,7 +145,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
userLabel, datnameLabel, queryidLabel,
)

var rowsTotalMetric float64
rowsTotalMetric := 0.0
if rowsTotal.Valid {
rowsTotalMetric = float64(rowsTotal.Int64)
}
Expand All @@ -156,7 +156,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
userLabel, datnameLabel, queryidLabel,
)

var blockReadSecondsTotalMetric float64
blockReadSecondsTotalMetric := 0.0
if blockReadSecondsTotal.Valid {
blockReadSecondsTotalMetric = blockReadSecondsTotal.Float64
}
Expand All @@ -167,7 +167,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
userLabel, datnameLabel, queryidLabel,
)

var blockWriteSecondsTotalMetric float64
blockWriteSecondsTotalMetric := 0.0
if blockWriteSecondsTotal.Valid {
blockWriteSecondsTotalMetric = blockWriteSecondsTotal.Float64
}
Expand Down
Loading

0 comments on commit 19cf776

Please sign in to comment.