mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-15 01:07:32 +00:00
refactor: use builtin max() and fix unused parameter
- Replace custom maxInt64 helper with Go 1.21+ builtin max() - Mark unused cfg parameter in newAdaptiveIntervalSelector - Remove test for deleted helper function
This commit is contained in:
parent
16603e8b4a
commit
252d060a58
4 changed files with 17 additions and 35 deletions
|
|
@ -207,17 +207,6 @@ func TestSafeFloat(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMaxInt64(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := maxInt64(5, 10); got != 10 {
|
||||
t.Fatalf("expected 10, got %d", got)
|
||||
}
|
||||
if got := maxInt64(-1, -5); got != -1 {
|
||||
t.Fatalf("expected -1, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertPoolInfoToModel(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
|
|
@ -624,13 +624,6 @@ func safePercentage(used, total float64) float64 {
|
|||
return result
|
||||
}
|
||||
|
||||
// maxInt64 returns the maximum of two int64 values
|
||||
func maxInt64(a, b int64) int64 {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// safeFloat ensures a float value is not NaN or Inf
|
||||
func safeFloat(val float64) float64 {
|
||||
|
|
@ -6769,10 +6762,10 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
|
|||
OSVersion: osVersion,
|
||||
AgentVersion: agentVersion,
|
||||
NetworkInterfaces: networkInterfaces,
|
||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
||||
NetworkIn: max(0, int64(netInRate)),
|
||||
NetworkOut: max(0, int64(netOutRate)),
|
||||
DiskRead: max(0, int64(diskReadRate)),
|
||||
DiskWrite: max(0, int64(diskWriteRate)),
|
||||
Uptime: int64(res.Uptime),
|
||||
Template: res.Template == 1,
|
||||
LastSeen: sampleTime,
|
||||
|
|
@ -6934,10 +6927,10 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
|
|||
Free: int64(res.MaxDisk - res.Disk),
|
||||
Usage: safePercentage(float64(res.Disk), float64(res.MaxDisk)),
|
||||
},
|
||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
||||
NetworkIn: max(0, int64(netInRate)),
|
||||
NetworkOut: max(0, int64(netOutRate)),
|
||||
DiskRead: max(0, int64(diskReadRate)),
|
||||
DiskWrite: max(0, int64(diskWriteRate)),
|
||||
Uptime: int64(res.Uptime),
|
||||
Template: res.Template == 1,
|
||||
LastSeen: time.Now(),
|
||||
|
|
|
|||
|
|
@ -743,10 +743,10 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cli
|
|||
},
|
||||
Disks: individualDisks,
|
||||
DiskStatusReason: diskStatusReason,
|
||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
||||
NetworkIn: max(0, int64(netInRate)),
|
||||
NetworkOut: max(0, int64(netOutRate)),
|
||||
DiskRead: max(0, int64(diskReadRate)),
|
||||
DiskWrite: max(0, int64(diskWriteRate)),
|
||||
Uptime: int64(vm.Uptime),
|
||||
Template: vm.Template == 1,
|
||||
LastSeen: sampleTime,
|
||||
|
|
@ -998,10 +998,10 @@ func (m *Monitor) pollContainersWithNodes(ctx context.Context, instanceName stri
|
|||
Free: diskFreeBytes,
|
||||
Usage: diskUsagePercent,
|
||||
},
|
||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
||||
NetworkIn: max(0, int64(netInRate)),
|
||||
NetworkOut: max(0, int64(netOutRate)),
|
||||
DiskRead: max(0, int64(diskReadRate)),
|
||||
DiskWrite: max(0, int64(diskWriteRate)),
|
||||
Uptime: int64(container.Uptime),
|
||||
Template: container.Template == 1,
|
||||
LastSeen: time.Now(),
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ type adaptiveIntervalSelector struct {
|
|||
errorPenalty float64
|
||||
}
|
||||
|
||||
func newAdaptiveIntervalSelector(cfg SchedulerConfig) *adaptiveIntervalSelector {
|
||||
func newAdaptiveIntervalSelector(_ SchedulerConfig) *adaptiveIntervalSelector {
|
||||
return &adaptiveIntervalSelector{
|
||||
state: make(map[string]time.Duration),
|
||||
rng: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue