Skip to content

Commit 44103ab

Browse files
committed
fix: address lint errors in metrics collector
- Explicitly ignore error from stats.Body.Close() - Define cpuPercentMultiplier constant for magic number 100.0 - Fix WSL whitespace violations in variable declarations
1 parent 9ff40a4 commit 44103ab

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

engine/internal/srv/metrics/collector.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import (
2424
"gitlab.com/postgres-ai/database-lab/v3/version"
2525
)
2626

27+
const (
28+
// cpuPercentMultiplier converts CPU usage ratio to percentage.
29+
cpuPercentMultiplier = 100.0
30+
)
31+
2732
// containerCPUState stores previous CPU stats for delta calculation.
2833
type containerCPUState struct {
2934
totalUsage uint64
@@ -237,7 +242,7 @@ func (c *Collector) getContainerStats(ctx context.Context, clones []*models.Clon
237242

238243
var statsJSON container.StatsResponse
239244
decodeErr := json.NewDecoder(stats.Body).Decode(&statsJSON)
240-
stats.Body.Close()
245+
_ = stats.Body.Close()
241246

242247
if decodeErr != nil {
243248
log.Dbg(fmt.Sprintf("failed to decode container stats for clone %s: %v", clone.ID, decodeErr))
@@ -304,7 +309,7 @@ func (c *Collector) calculateCPUPercent(cloneID string, stats *container.StatsRe
304309
cpuCount = 1
305310
}
306311

307-
return (cpuDelta / systemDelta) * cpuCount * 100.0
312+
return (cpuDelta / systemDelta) * cpuCount * cpuPercentMultiplier
308313
}
309314

310315
func (c *Collector) cleanupStaleCPUStats(activeCloneIDs map[string]struct{}) {
@@ -324,8 +329,11 @@ func (c *Collector) collectSnapshotMetrics() {
324329

325330
c.metrics.SnapshotsTotal.Set(float64(len(snapshots)))
326331

327-
var maxAge float64
328-
var maxDataLag float64
332+
var (
333+
maxAge float64
334+
maxDataLag float64
335+
)
336+
329337
now := time.Now()
330338

331339
for _, snapshot := range snapshots {

0 commit comments

Comments
 (0)