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) {
|
func TestConvertPoolInfoToModel(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -624,13 +624,6 @@ func safePercentage(used, total float64) float64 {
|
||||||
return result
|
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
|
// safeFloat ensures a float value is not NaN or Inf
|
||||||
func safeFloat(val float64) float64 {
|
func safeFloat(val float64) float64 {
|
||||||
|
|
@ -6769,10 +6762,10 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
|
||||||
OSVersion: osVersion,
|
OSVersion: osVersion,
|
||||||
AgentVersion: agentVersion,
|
AgentVersion: agentVersion,
|
||||||
NetworkInterfaces: networkInterfaces,
|
NetworkInterfaces: networkInterfaces,
|
||||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
NetworkIn: max(0, int64(netInRate)),
|
||||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
NetworkOut: max(0, int64(netOutRate)),
|
||||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
DiskRead: max(0, int64(diskReadRate)),
|
||||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
DiskWrite: max(0, int64(diskWriteRate)),
|
||||||
Uptime: int64(res.Uptime),
|
Uptime: int64(res.Uptime),
|
||||||
Template: res.Template == 1,
|
Template: res.Template == 1,
|
||||||
LastSeen: sampleTime,
|
LastSeen: sampleTime,
|
||||||
|
|
@ -6934,10 +6927,10 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
|
||||||
Free: int64(res.MaxDisk - res.Disk),
|
Free: int64(res.MaxDisk - res.Disk),
|
||||||
Usage: safePercentage(float64(res.Disk), float64(res.MaxDisk)),
|
Usage: safePercentage(float64(res.Disk), float64(res.MaxDisk)),
|
||||||
},
|
},
|
||||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
NetworkIn: max(0, int64(netInRate)),
|
||||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
NetworkOut: max(0, int64(netOutRate)),
|
||||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
DiskRead: max(0, int64(diskReadRate)),
|
||||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
DiskWrite: max(0, int64(diskWriteRate)),
|
||||||
Uptime: int64(res.Uptime),
|
Uptime: int64(res.Uptime),
|
||||||
Template: res.Template == 1,
|
Template: res.Template == 1,
|
||||||
LastSeen: time.Now(),
|
LastSeen: time.Now(),
|
||||||
|
|
|
||||||
|
|
@ -743,10 +743,10 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cli
|
||||||
},
|
},
|
||||||
Disks: individualDisks,
|
Disks: individualDisks,
|
||||||
DiskStatusReason: diskStatusReason,
|
DiskStatusReason: diskStatusReason,
|
||||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
NetworkIn: max(0, int64(netInRate)),
|
||||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
NetworkOut: max(0, int64(netOutRate)),
|
||||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
DiskRead: max(0, int64(diskReadRate)),
|
||||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
DiskWrite: max(0, int64(diskWriteRate)),
|
||||||
Uptime: int64(vm.Uptime),
|
Uptime: int64(vm.Uptime),
|
||||||
Template: vm.Template == 1,
|
Template: vm.Template == 1,
|
||||||
LastSeen: sampleTime,
|
LastSeen: sampleTime,
|
||||||
|
|
@ -998,10 +998,10 @@ func (m *Monitor) pollContainersWithNodes(ctx context.Context, instanceName stri
|
||||||
Free: diskFreeBytes,
|
Free: diskFreeBytes,
|
||||||
Usage: diskUsagePercent,
|
Usage: diskUsagePercent,
|
||||||
},
|
},
|
||||||
NetworkIn: maxInt64(0, int64(netInRate)),
|
NetworkIn: max(0, int64(netInRate)),
|
||||||
NetworkOut: maxInt64(0, int64(netOutRate)),
|
NetworkOut: max(0, int64(netOutRate)),
|
||||||
DiskRead: maxInt64(0, int64(diskReadRate)),
|
DiskRead: max(0, int64(diskReadRate)),
|
||||||
DiskWrite: maxInt64(0, int64(diskWriteRate)),
|
DiskWrite: max(0, int64(diskWriteRate)),
|
||||||
Uptime: int64(container.Uptime),
|
Uptime: int64(container.Uptime),
|
||||||
Template: container.Template == 1,
|
Template: container.Template == 1,
|
||||||
LastSeen: time.Now(),
|
LastSeen: time.Now(),
|
||||||
|
|
|
||||||
|
|
@ -285,7 +285,7 @@ type adaptiveIntervalSelector struct {
|
||||||
errorPenalty float64
|
errorPenalty float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAdaptiveIntervalSelector(cfg SchedulerConfig) *adaptiveIntervalSelector {
|
func newAdaptiveIntervalSelector(_ SchedulerConfig) *adaptiveIntervalSelector {
|
||||||
return &adaptiveIntervalSelector{
|
return &adaptiveIntervalSelector{
|
||||||
state: make(map[string]time.Duration),
|
state: make(map[string]time.Duration),
|
||||||
rng: rand.New(rand.NewSource(time.Now().UnixNano())),
|
rng: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue