Skip to content

Commit 40691cd

Browse files
committed
Be more go-like
1 parent 910c7da commit 40691cd

File tree

7 files changed

+65
-65
lines changed

7 files changed

+65
-65
lines changed

collector/pg_process_idle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch cha
105105
applicationNameLabel = applicationName.String
106106
}
107107

108-
var secondsCountMetric uint64
108+
var secondsCountMetric uint64 = 0
109109
if secondsCount.Valid {
110110
secondsCountMetric = uint64(secondsCount.Int64)
111111
}
112-
var secondsSumMetric float64
112+
secondsSumMetric := 0.0
113113
if secondsSum.Valid {
114114
secondsSumMetric = float64(secondsSum.Int64)
115115
}

collector/pg_replication_slot.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance
9191
return err
9292
}
9393

94-
isActiveValue := 0
94+
isActiveValue := 0.0
9595
if isActive.Valid && isActive.Bool {
96-
isActiveValue = 1
96+
isActiveValue = 1.0
9797
}
9898
slotNameLabel := "unknown"
9999
if slotName.Valid {
@@ -120,7 +120,7 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance
120120
}
121121
ch <- prometheus.MustNewConstMetric(
122122
pgReplicationSlotIsActiveDesc,
123-
prometheus.GaugeValue, float64(isActiveValue), slotNameLabel,
123+
prometheus.GaugeValue, isActiveValue, slotNameLabel,
124124
)
125125
}
126126
if err := rows.Err(); err != nil {

collector/pg_stat_bgwriter.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
130130
return err
131131
}
132132

133-
var cptMetric float64
133+
cptMetric := 0.0
134134
if cpt.Valid {
135135
cptMetric = float64(cpt.Int64)
136136
}
@@ -139,7 +139,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
139139
prometheus.CounterValue,
140140
cptMetric,
141141
)
142-
var cprMetric float64
142+
cprMetric := 0.0
143143
if cpr.Valid {
144144
cprMetric = float64(cpr.Int64)
145145
}
@@ -148,7 +148,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
148148
prometheus.CounterValue,
149149
cprMetric,
150150
)
151-
var cpwtMetric float64
151+
cpwtMetric := 0.0
152152
if cpwt.Valid {
153153
cpwtMetric = float64(cpwt.Float64)
154154
}
@@ -157,7 +157,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
157157
prometheus.CounterValue,
158158
cpwtMetric,
159159
)
160-
var cpstMetric float64
160+
cpstMetric := 0.0
161161
if cpst.Valid {
162162
cpstMetric = float64(cpst.Float64)
163163
}
@@ -166,7 +166,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
166166
prometheus.CounterValue,
167167
cpstMetric,
168168
)
169-
var bcpMetric float64
169+
bcpMetric := 0.0
170170
if bcp.Valid {
171171
bcpMetric = float64(bcp.Int64)
172172
}
@@ -175,7 +175,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
175175
prometheus.CounterValue,
176176
bcpMetric,
177177
)
178-
var bcMetric float64
178+
bcMetric := 0.0
179179
if bc.Valid {
180180
bcMetric = float64(bc.Int64)
181181
}
@@ -184,7 +184,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
184184
prometheus.CounterValue,
185185
bcMetric,
186186
)
187-
var mwcMetric float64
187+
mwcMetric := 0.0
188188
if mwc.Valid {
189189
mwcMetric = float64(mwc.Int64)
190190
}
@@ -193,7 +193,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
193193
prometheus.CounterValue,
194194
mwcMetric,
195195
)
196-
var bbMetric float64
196+
bbMetric := 0.0
197197
if bb.Valid {
198198
bbMetric = float64(bb.Int64)
199199
}
@@ -202,7 +202,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
202202
prometheus.CounterValue,
203203
bbMetric,
204204
)
205-
var bbfMetric float64
205+
bbfMetric := 0.0
206206
if bbf.Valid {
207207
bbfMetric = float64(bbf.Int64)
208208
}
@@ -211,7 +211,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
211211
prometheus.CounterValue,
212212
bbfMetric,
213213
)
214-
var baMetric float64
214+
baMetric := 0.0
215215
if ba.Valid {
216216
baMetric = float64(ba.Int64)
217217
}
@@ -220,7 +220,7 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, instance *instance, c
220220
prometheus.CounterValue,
221221
baMetric,
222222
)
223-
var srMetric float64
223+
srMetric := 0.0
224224
if sr.Valid {
225225
srMetric = float64(sr.Time.Unix())
226226
}

collector/pg_stat_database.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
276276
datnameLabel = datname.String
277277
}
278278

279-
var numBackendsMetric float64
279+
numBackendsMetric := 0.0
280280
if numBackends.Valid {
281281
numBackendsMetric = numBackends.Float64
282282
}
@@ -288,7 +288,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
288288
datnameLabel,
289289
)
290290

291-
var xactCommitMetric float64
291+
xactCommitMetric := 0.0
292292
if xactCommit.Valid {
293293
xactCommitMetric = xactCommit.Float64
294294
}
@@ -300,7 +300,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
300300
datnameLabel,
301301
)
302302

303-
var xactRollbackMetric float64
303+
xactRollbackMetric := 0.0
304304
if xactRollback.Valid {
305305
xactRollbackMetric = xactRollback.Float64
306306
}
@@ -312,7 +312,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
312312
datnameLabel,
313313
)
314314

315-
var blksReadMetric float64
315+
blksReadMetric := 0.0
316316
if blksRead.Valid {
317317
blksReadMetric = blksRead.Float64
318318
}
@@ -324,7 +324,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
324324
datnameLabel,
325325
)
326326

327-
var blksHitMetric float64
327+
blksHitMetric := 0.0
328328
if blksHit.Valid {
329329
blksHitMetric = blksHit.Float64
330330
}
@@ -336,7 +336,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
336336
datnameLabel,
337337
)
338338

339-
var tupReturnedMetric float64
339+
tupReturnedMetric := 0.0
340340
if tupReturned.Valid {
341341
tupReturnedMetric = tupReturned.Float64
342342
}
@@ -348,7 +348,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
348348
datnameLabel,
349349
)
350350

351-
var tupFetchedMetric float64
351+
tupFetchedMetric := 0.0
352352
if tupFetched.Valid {
353353
tupFetchedMetric = tupFetched.Float64
354354
}
@@ -360,7 +360,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
360360
datnameLabel,
361361
)
362362

363-
var tupInsertedMetric float64
363+
tupInsertedMetric := 0.0
364364
if tupInserted.Valid {
365365
tupInsertedMetric = tupInserted.Float64
366366
}
@@ -372,7 +372,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
372372
datnameLabel,
373373
)
374374

375-
var tupUpdatedMetric float64
375+
tupUpdatedMetric := 0.0
376376
if tupUpdated.Valid {
377377
tupUpdatedMetric = tupUpdated.Float64
378378
}
@@ -384,7 +384,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
384384
datnameLabel,
385385
)
386386

387-
var tupDeletedMetric float64
387+
tupDeletedMetric := 0.0
388388
if tupDeleted.Valid {
389389
tupDeletedMetric = tupDeleted.Float64
390390
}
@@ -396,7 +396,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
396396
datnameLabel,
397397
)
398398

399-
var conflictsMetric float64
399+
conflictsMetric := 0.0
400400
if conflicts.Valid {
401401
conflictsMetric = conflicts.Float64
402402
}
@@ -408,7 +408,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
408408
datnameLabel,
409409
)
410410

411-
var tempFilesMetric float64
411+
tempFilesMetric := 0.0
412412
if tempFiles.Valid {
413413
tempFilesMetric = tempFiles.Float64
414414
}
@@ -420,7 +420,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
420420
datnameLabel,
421421
)
422422

423-
var tempBytesMetric float64
423+
tempBytesMetric := 0.0
424424
if tempBytes.Valid {
425425
tempBytesMetric = tempBytes.Float64
426426
}
@@ -432,7 +432,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
432432
datnameLabel,
433433
)
434434

435-
var deadlocksMetric float64
435+
deadlocksMetric := 0.0
436436
if deadlocks.Valid {
437437
deadlocksMetric = deadlocks.Float64
438438
}
@@ -444,7 +444,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
444444
datnameLabel,
445445
)
446446

447-
var blkReadTimeMetric float64
447+
blkReadTimeMetric := 0.0
448448
if blkReadTime.Valid {
449449
blkReadTimeMetric = blkReadTime.Float64
450450
}
@@ -456,7 +456,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
456456
datnameLabel,
457457
)
458458

459-
var blkWriteTimeMetric float64
459+
blkWriteTimeMetric := 0.0
460460
if blkWriteTime.Valid {
461461
blkWriteTimeMetric = blkWriteTime.Float64
462462
}
@@ -468,7 +468,7 @@ func (PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, c
468468
datnameLabel,
469469
)
470470

471-
var statsResetMetric float64
471+
statsResetMetric := 0.0
472472
if statsReset.Valid {
473473
statsResetMetric = float64(statsReset.Time.Unix())
474474
}

collector/pg_stat_statements.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
123123
queryidLabel = queryid.String
124124
}
125125

126-
var callsTotalMetric float64
126+
callsTotalMetric := 0.0
127127
if callsTotal.Valid {
128128
callsTotalMetric = float64(callsTotal.Int64)
129129
}
@@ -134,7 +134,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
134134
userLabel, datnameLabel, queryidLabel,
135135
)
136136

137-
var secondsTotalMetric float64
137+
secondsTotalMetric := 0.0
138138
if secondsTotal.Valid {
139139
secondsTotalMetric = secondsTotal.Float64
140140
}
@@ -145,7 +145,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
145145
userLabel, datnameLabel, queryidLabel,
146146
)
147147

148-
var rowsTotalMetric float64
148+
rowsTotalMetric := 0.0
149149
if rowsTotal.Valid {
150150
rowsTotalMetric = float64(rowsTotal.Int64)
151151
}
@@ -156,7 +156,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
156156
userLabel, datnameLabel, queryidLabel,
157157
)
158158

159-
var blockReadSecondsTotalMetric float64
159+
blockReadSecondsTotalMetric := 0.0
160160
if blockReadSecondsTotal.Valid {
161161
blockReadSecondsTotalMetric = blockReadSecondsTotal.Float64
162162
}
@@ -167,7 +167,7 @@ func (PGStatStatementsCollector) Update(ctx context.Context, instance *instance,
167167
userLabel, datnameLabel, queryidLabel,
168168
)
169169

170-
var blockWriteSecondsTotalMetric float64
170+
blockWriteSecondsTotalMetric := 0.0
171171
if blockWriteSecondsTotal.Valid {
172172
blockWriteSecondsTotalMetric = blockWriteSecondsTotal.Float64
173173
}

0 commit comments

Comments
 (0)