Skip to content

Commit dd713b1

Browse files
author
Thomas Delbende
committed
chore: upgrade Go dependencies and Go to 1.24
1 parent 2e6b44b commit dd713b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+636
-425
lines changed

agent/agent_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package agent
1919

2020
import (
21-
"context"
2221
"net/url"
2322
"testing"
2423
"time"
@@ -515,7 +514,7 @@ func TestSMARTStatus(t *testing.T) {
515514

516515
store := store.New("test store", time.Minute, time.Minute)
517516

518-
store.PushPoints(context.Background(), test.points)
517+
store.PushPoints(t.Context(), test.points)
519518

520519
gotMetric := statusFromLastPoint(now, store, "smart_device_health_ok", map[string]string{types.LabelName: "smart_device_health_status"}, smartHealthStatus)
521520

@@ -811,7 +810,7 @@ func TestUPSDBatteryStatus(t *testing.T) { //nolint:maintidx
811810

812811
store := store.New("test store", time.Minute, time.Minute)
813812

814-
store.PushPoints(context.Background(), test.points)
813+
store.PushPoints(t.Context(), test.points)
815814

816815
gotMetric := statusFromLastPoint(now, store, "upsd_status_flags", map[string]string{types.LabelName: "upsd_battery_status"}, upsdBatteryStatus)
817816

agent/metric_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ func Benchmark_filters_no_match(b *testing.B) {
12621262

12631263
b.ResetTimer()
12641264

1265-
for range b.N {
1265+
for b.Loop() {
12661266
copy(cop, list1)
12671267

12681268
metricFilter.FilterPoints(cop, false)
@@ -1274,7 +1274,7 @@ func Benchmark_filters_no_match(b *testing.B) {
12741274

12751275
b.ResetTimer()
12761276

1277-
for range b.N {
1277+
for b.Loop() {
12781278
copy(cop, list10)
12791279

12801280
metricFilter.FilterPoints(cop, false)
@@ -1286,7 +1286,7 @@ func Benchmark_filters_no_match(b *testing.B) {
12861286

12871287
b.ResetTimer()
12881288

1289-
for range b.N {
1289+
for b.Loop() {
12901290
copy(cop, list100)
12911291

12921292
metricFilter.FilterPoints(cop, false)
@@ -1326,7 +1326,7 @@ func Benchmark_filters_one_match_first(b *testing.B) {
13261326

13271327
b.ResetTimer()
13281328

1329-
for range b.N {
1329+
for b.Loop() {
13301330
copy(cop, list1)
13311331

13321332
metricFilter.FilterPoints(cop, false)
@@ -1338,7 +1338,7 @@ func Benchmark_filters_one_match_first(b *testing.B) {
13381338

13391339
b.ResetTimer()
13401340

1341-
for range b.N {
1341+
for b.Loop() {
13421342
copy(cop, list10)
13431343

13441344
metricFilter.FilterPoints(cop, false)
@@ -1350,7 +1350,7 @@ func Benchmark_filters_one_match_first(b *testing.B) {
13501350

13511351
b.ResetTimer()
13521352

1353-
for range b.N {
1353+
for b.Loop() {
13541354
copy(cop, list100)
13551355

13561356
metricFilter.FilterPoints(cop, false)
@@ -1384,7 +1384,7 @@ func Benchmark_filters_one_match_middle(b *testing.B) {
13841384

13851385
b.ResetTimer()
13861386

1387-
for range b.N {
1387+
for b.Loop() {
13881388
copy(cop, list10)
13891389

13901390
metricFilter.FilterPoints(cop, false)
@@ -1396,7 +1396,7 @@ func Benchmark_filters_one_match_middle(b *testing.B) {
13961396

13971397
b.ResetTimer()
13981398

1399-
for range b.N {
1399+
for b.Loop() {
14001400
copy(cop, list100)
14011401

14021402
metricFilter.FilterPoints(cop, false)
@@ -1426,7 +1426,7 @@ func Benchmark_filters_one_match_last(b *testing.B) {
14261426

14271427
b.ResetTimer()
14281428

1429-
for range b.N {
1429+
for b.Loop() {
14301430
copy(cop, list10)
14311431

14321432
metricFilter.FilterPoints(cop, false)
@@ -1438,7 +1438,7 @@ func Benchmark_filters_one_match_last(b *testing.B) {
14381438

14391439
b.ResetTimer()
14401440

1441-
for range b.N {
1441+
for b.Loop() {
14421442
copy(cop, list100)
14431443

14441444
metricFilter.FilterPoints(cop, false)
@@ -1460,7 +1460,7 @@ func Benchmark_filters_all(b *testing.B) {
14601460

14611461
b.ResetTimer()
14621462

1463-
for range b.N {
1463+
for b.Loop() {
14641464
copy(cop, list10)
14651465

14661466
metricFilter.FilterPoints(cop, false)
@@ -1472,7 +1472,7 @@ func Benchmark_filters_all(b *testing.B) {
14721472

14731473
b.ResetTimer()
14741474

1475-
for range b.N {
1475+
for b.Loop() {
14761476
copy(cop, list100)
14771477

14781478
metricFilter.FilterPoints(cop, false)
@@ -1670,7 +1670,7 @@ func Benchmark_MultipleFilters(b *testing.B) {
16701670
b.ResetTimer()
16711671

16721672
b.Run("or", func(b *testing.B) {
1673-
for range b.N {
1673+
for b.Loop() {
16741674
var allowed int
16751675

16761676
for _, lbls := range metrics {
@@ -1682,7 +1682,7 @@ func Benchmark_MultipleFilters(b *testing.B) {
16821682
})
16831683

16841684
b.Run("merge", func(b *testing.B) {
1685-
for range b.N {
1685+
for b.Loop() {
16861686
var allowed int
16871687

16881688
for _, lbls := range metrics {

bleemeo/internal/mqtt/mqtt_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func BenchmarkFailedPointsDropping(b *testing.B) {
424424

425425
b.ResetTimer()
426426

427-
for range b.N {
427+
for b.Loop() {
428428
// Add 100 more points for each metric
429429
for i := 1; i <= 10; i++ {
430430
labels := map[string]string{labelID: strconv.Itoa(i)}

bleemeo/internal/synchronizer/execution_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func TestExecution_LinkedSynchronization(t *testing.T) { //nolint:maintidx
397397
}
398398
}
399399

400-
e.applyNeedSynchronization(context.Background())
400+
e.applyNeedSynchronization(t.Context())
401401

402402
for _, request := range tt.callsToRequestSynchronizationBefore {
403403
e.RequestSynchronization(request.name, request.requestFull)

bleemeo/internal/synchronizer/helper_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (helper *syncTestHelper) pushPoints(t *testing.T, metrics []labels.Labels)
220220
t.Fatal("pushPoints called before store is initialized")
221221
}
222222

223-
helper.store.PushPoints(context.Background(), points)
223+
helper.store.PushPoints(t.Context(), points)
224224
}
225225

226226
func (helper *syncTestHelper) Close() {
@@ -274,7 +274,7 @@ func (helper *syncTestHelper) runOnceWithResult(t *testing.T) runOnceResult {
274274
func (helper *syncTestHelper) runOnceNoReset(t *testing.T) runOnceResult {
275275
t.Helper()
276276

277-
ctx := context.Background()
277+
ctx := t.Context()
278278

279279
result := runOnceResult{}
280280

bleemeo/internal/synchronizer/syncapplications/applications_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func Test_syncRemoteAndLocal(t *testing.T) {
210210
ListResponse: tt.remoteApplication,
211211
}
212212

213-
if err := syncRemoteAndLocal(context.Background(), tt.localServices, apiClient, cache); err != nil {
213+
if err := syncRemoteAndLocal(t.Context(), tt.localServices, apiClient, cache); err != nil {
214214
t.Errorf("syncRemoteAndLocal() error = %v", err)
215215
}
216216

check/process_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package check
1818

1919
import (
20-
"context"
2120
"testing"
2221

2322
"github.com/bleemeo/glouton/facts"
@@ -120,7 +119,7 @@ func Test_processMainCheck(t *testing.T) {
120119
t.Errorf("Failed to create process: %v", err)
121120
}
122121

123-
status := pc.processMainCheck(context.Background())
122+
status := pc.processMainCheck(t.Context())
124123
if status.CurrentStatus != test.expectedStatus.CurrentStatus {
125124
t.Errorf("Expected status %v, got %v", test.expectedStatus.CurrentStatus, status.CurrentStatus)
126125
} else if status.StatusDescription != test.expectedStatus.StatusDescription {

collector/collector_test.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package collector
1818

1919
import (
20-
"context"
2120
"errors"
2221
"fmt"
2322
"io"
@@ -75,7 +74,7 @@ func TestAddRemove(t *testing.T) {
7574
}
7675

7776
func TestRun(t *testing.T) {
78-
ctx := context.Background()
77+
ctx := t.Context()
7978
c := New(nil, gate.New(0))
8079
c.runOnce(ctx, time.Now())
8180

@@ -307,7 +306,7 @@ func TestMarkInactive(t *testing.T) {
307306
t1 := t0.Add(10 * time.Second)
308307
t2 := t1.Add(10 * time.Second)
309308

310-
err := c.RunGather(context.Background(), t0)
309+
err := c.RunGather(t.Context(), t0)
311310
if err != nil {
312311
t.Fatalf("Unexpected c.RunGather() error: %v", err)
313312
}
@@ -346,7 +345,7 @@ func TestMarkInactive(t *testing.T) {
346345

347346
input2.tag = "I2" // Tags have changed
348347

349-
err = c.RunGather(context.Background(), t1)
348+
err = c.RunGather(t.Context(), t1)
350349
if err != nil {
351350
t.Fatalf("Unexpected c.RunGather() error: %v", err)
352351
}
@@ -385,7 +384,7 @@ func TestMarkInactive(t *testing.T) {
385384

386385
input2bis.fields["f"] = 22.22
387386

388-
err = c.RunGather(context.Background(), t2)
387+
err = c.RunGather(t.Context(), t2)
389388
if err != nil {
390389
t.Fatalf("Unexpected c.RunGather() error: %v", err)
391390
}
@@ -511,7 +510,7 @@ func TestMarkInactiveWhileDroppingInput(t *testing.T) {
511510
wg.Done()
512511
}()
513512

514-
err = c.RunGather(context.Background(), time.Now())
513+
err = c.RunGather(t.Context(), time.Now())
515514
if err != nil {
516515
t.Fatalf("Unexpected c.RunGather() error: %v", err)
517516
}
@@ -547,7 +546,7 @@ func TestMarkInactiveWithErrors(t *testing.T) {
547546
t1 := t0.Add(10 * time.Second)
548547
t2 := t1.Add(keepMetricBecauseOfGatherErrorGraceDelay)
549548

550-
err = c.RunGather(context.Background(), t0)
549+
err = c.RunGather(t.Context(), t0)
551550
if err != nil {
552551
t.Fatal("Gathering failed:", err)
553552
}
@@ -570,7 +569,7 @@ func TestMarkInactiveWithErrors(t *testing.T) {
570569
input.fields = map[string]float64{"f2": 0.22, "f3": 33} // no value for f1
571570
input.retErr = io.ErrUnexpectedEOF // perhaps because of this error
572571

573-
err = c.RunGather(context.Background(), t1)
572+
err = c.RunGather(t.Context(), t1)
574573
if err != nil {
575574
t.Fatal("Gathering failed:", err)
576575
}
@@ -588,7 +587,7 @@ func TestMarkInactiveWithErrors(t *testing.T) {
588587
input.fields = map[string]float64{"f3": 3, "f4": 4.4} // no more value for f2 neither; a new metric appears;
589588
// the error is still present
590589

591-
err = c.RunGather(context.Background(), t2)
590+
err = c.RunGather(t.Context(), t2)
592591
if err != nil {
593592
t.Fatal("Gathering failed:", err)
594593
}
@@ -640,7 +639,7 @@ func TestErrorHandling(t *testing.T) {
640639
}
641640
}
642641

643-
err := c.RunGather(context.Background(), time.Now())
642+
err := c.RunGather(t.Context(), time.Now())
644643
expectedErrors := []error{os.ErrPermission, os.ErrPermission, io.ErrUnexpectedEOF}
645644

646645
for _, expectedErr := range expectedErrors {

config/hooks.go

+33
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,36 @@ func ParseBool(value string) (bool, error) {
143143

144144
return result, err
145145
}
146+
147+
func StringToIntSliceHookFunc(sep string) mapstructure.DecodeHookFunc {
148+
expectedToType := reflect.SliceOf(reflect.TypeFor[int]())
149+
150+
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
151+
if f.Kind() != reflect.String {
152+
return data, nil
153+
}
154+
155+
if t != expectedToType {
156+
return data, nil
157+
}
158+
159+
raw, _ := data.(string)
160+
if raw == "" {
161+
return []int{}, nil
162+
}
163+
164+
split := strings.Split(raw, sep)
165+
ints := make([]int, len(split))
166+
167+
for i, s := range split {
168+
n, err := strconv.Atoi(s)
169+
if err != nil {
170+
return nil, err
171+
}
172+
173+
ints[i] = n
174+
}
175+
176+
return ints, nil
177+
}
178+
}

config/loader.go

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ func convertTypes(
266266
blackboxModuleHookFunc(),
267267
stringToMapHookFunc(),
268268
stringToBoolHookFunc(),
269+
StringToIntSliceHookFunc(","),
269270
),
270271
Metadata: nil,
271272
ErrorUnused: true,

crashreport/crash_report_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func TestGenerateDiagnostic(t *testing.T) {
311311
return tc.diagnosticError
312312
}
313313

314-
ctx, cancel := context.WithTimeout(context.Background(), tc.ctxTimeout)
314+
ctx, cancel := context.WithTimeout(t.Context(), tc.ctxTimeout)
315315
defer cancel()
316316

317317
err := generateDiagnostic(ctx, nil, diagnosticFn)
@@ -491,7 +491,7 @@ func TestBundleCrashReportFiles(t *testing.T) { //nolint:maintidx
491491
return nil
492492
}
493493

494-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
494+
ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second)
495495
defer cancel()
496496

497497
reportPath := bundleCrashReportFiles(ctx, 2, stateDir, tc.reportingEnabled, diagnosticFn)

debouncer/debouncer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestDebouncer_Trigger(t *testing.T) {
131131
}
132132
}
133133

134-
ctx := context.Background()
134+
ctx := t.Context()
135135
t0 := time.Now()
136136
testDeadline := t0.Add(2 * tt.period).Add(maxDuration)
137137
target := func(_ context.Context) {

0 commit comments

Comments
 (0)