diff --git a/cmd/windows_exporter/main_test.go b/cmd/windows_exporter/main_test.go index af81f454..e3216d54 100644 --- a/cmd/windows_exporter/main_test.go +++ b/cmd/windows_exporter/main_test.go @@ -72,7 +72,7 @@ func TestRun(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - ctx, cancel := context.WithCancel(t.Context()) + ctx, cancel := context.WithCancel(context.Background()) defer cancel() if tc.config != "" { diff --git a/internal/collector/textfile/textfile_test_test.go b/internal/collector/textfile/textfile_test_test.go index e71f8fac..60c5e937 100644 --- a/internal/collector/textfile/textfile_test_test.go +++ b/internal/collector/textfile/textfile_test_test.go @@ -16,6 +16,7 @@ package textfile_test import ( + "context" "fmt" "io" "log/slog" @@ -44,7 +45,7 @@ func TestMultipleDirectories(t *testing.T) { }) collectors := collector.New(map[string]collector.Collector{textfile.Name: textFileCollector}) - require.NoError(t, collectors.Build(t.Context(), logger)) + require.NoError(t, collectors.Build(context.Background(), logger)) metrics := make(chan prometheus.Metric) got := "" @@ -81,7 +82,7 @@ func TestDuplicateFileName(t *testing.T) { }) collectors := collector.New(map[string]collector.Collector{textfile.Name: textFileCollector}) - require.NoError(t, collectors.Build(t.Context(), logger)) + require.NoError(t, collectors.Build(context.Background(), logger)) metrics := make(chan prometheus.Metric) got := "" diff --git a/internal/config/config.go b/internal/config/config.go index ea714608..4dcda129 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -16,6 +16,7 @@ package config import ( + "context" "crypto/tls" "fmt" "io" @@ -91,6 +92,7 @@ func NewConfigFileResolver(file string) (*Resolver, error) { ) if strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") { + //nolint:sloglint // we do not have an logger yet slog.Warn("Loading configuration file from URL is deprecated and will be removed in 0.31.0. Use a local file instead.") fileBytes, err = readFromURL(file) @@ -142,7 +144,7 @@ func readFromURL(file string) ([]byte, error) { client := &http.Client{Transport: tr} - req, err := http.NewRequest(http.MethodGet, file, nil) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, file, nil) if err != nil { return nil, fmt.Errorf("failed to create HTTP request: %w", err) } diff --git a/internal/utils/testutils/testutils.go b/internal/utils/testutils/testutils.go index 75546132..bf7e3894 100644 --- a/internal/utils/testutils/testutils.go +++ b/internal/utils/testutils/testutils.go @@ -16,6 +16,7 @@ package testutils import ( + "context" "errors" "io" "log/slog" @@ -47,7 +48,7 @@ func FuncBenchmarkCollector[C collector.Collector](b *testing.B, name string, co } collectors := collector.New(map[string]collector.Collector{name: c}) - require.NoError(b, collectors.Build(b.Context(), logger)) + require.NoError(b, collectors.Build(context.Background(), logger)) metrics := make(chan prometheus.Metric)