refactor: fix lint errors; improve error handling

This commit is contained in:
yusing
2026-02-22 16:04:25 +08:00
parent 3a7d1f8b18
commit 0f78158c64
40 changed files with 191 additions and 136 deletions

View File

@@ -51,19 +51,6 @@ const (
SystemInfoAggregateModeSensorTemperature SystemInfoAggregateMode = "sensor_temperature" // @name SystemInfoAggregateModeSensorTemperature
)
var allQueries = []SystemInfoAggregateMode{
SystemInfoAggregateModeCPUAverage,
SystemInfoAggregateModeMemoryUsage,
SystemInfoAggregateModeMemoryUsagePercent,
SystemInfoAggregateModeDisksReadSpeed,
SystemInfoAggregateModeDisksWriteSpeed,
SystemInfoAggregateModeDisksIOPS,
SystemInfoAggregateModeDiskUsage,
SystemInfoAggregateModeNetworkSpeed,
SystemInfoAggregateModeNetworkTransfer,
SystemInfoAggregateModeSensorTemperature,
}
var Poller = period.NewPoller("system_info", getSystemInfo, aggregate)
func isNoDataAvailable(err error) bool {

View File

@@ -123,6 +123,18 @@ func TestSerialize(t *testing.T) {
for i := range 5 {
entries[i] = testInfo
}
var allQueries = []SystemInfoAggregateMode{
SystemInfoAggregateModeCPUAverage,
SystemInfoAggregateModeMemoryUsage,
SystemInfoAggregateModeMemoryUsagePercent,
SystemInfoAggregateModeDisksReadSpeed,
SystemInfoAggregateModeDisksWriteSpeed,
SystemInfoAggregateModeDisksIOPS,
SystemInfoAggregateModeDiskUsage,
SystemInfoAggregateModeNetworkSpeed,
SystemInfoAggregateModeNetworkTransfer,
SystemInfoAggregateModeSensorTemperature,
}
for _, query := range allQueries {
t.Run(string(query), func(t *testing.T) {
_, result := aggregate(entries, url.Values{"aggregate": []string{string(query)}})

View File

@@ -3,6 +3,7 @@ package uptime
import (
"context"
"errors"
"math"
"net/url"
"slices"
"time"
@@ -70,7 +71,7 @@ func aggregateStatuses(entries []StatusByAlias, query url.Values) (int, Aggregat
for alias, status := range entry.Map {
statuses[alias] = append(statuses[alias], Status{
Status: status.Status,
Latency: int32(status.Latency.Milliseconds()),
Latency: int32(min(math.MaxInt32, status.Latency.Milliseconds())), //nolint:gosec
Timestamp: entry.Timestamp,
})
}
@@ -134,7 +135,6 @@ func (rs RouteStatuses) aggregate(limit int, offset int) Aggregated {
status := types.StatusUnknown
if state := config.ActiveState.Load(); state != nil {
// FIXME: pass ctx to getRoute
r, ok := entrypoint.FromCtx(state.Context()).GetRoute(alias)
if ok {
mon := r.HealthMonitor()