Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
if: steps.go-setup.outputs.cache-hit != 'true'
run: make install-tools
- name: Lint
run: GOOS=${{ matrix.goos }} GOARCH=amd64 make -j2 golint GROUP=${{ matrix.group }}
run: GOOS=${{ matrix.goos }} GOARCH=amd64 make -j2 golint -k GROUP=${{ matrix.group }}
lint:
if: ${{ github.actor != 'dependabot[bot]' && always() }}
runs-on: ubuntu-24.04
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ issues:

linters:
enable:
- contextcheck
- copyloopvar
- decorder
- depguard
Expand All @@ -36,6 +37,7 @@ linters:
- gosec
- govet
- misspell
- noctx
- nolintlint
- predeclared
- reassign
Expand Down
50 changes: 42 additions & 8 deletions cmd/opampsupervisor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,12 @@ func TestSupervisorStartsCollectorWithNoOpAMPServerWithNoLastRemoteConfig(t *tes

// Verify the collector runs eventually by pinging the healthcheck extension
require.Eventually(t, func() bool {
resp, err := http.DefaultClient.Get("http://localhost:13133")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://localhost:13133", http.NoBody)
if err != nil {
t.Logf("Failed to create request: %s", err)
return false
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Logf("Failed healthcheck: %s", err)
return false
Expand Down Expand Up @@ -559,7 +564,12 @@ func TestSupervisorStartsCollectorWithNoOpAMPServerUsingLastRemoteConfig(t *test

// Verify the collector runs eventually by pinging the healthcheck extension
require.Eventually(t, func() bool {
resp, err := http.DefaultClient.Get(fmt.Sprintf("http://localhost:%d", healthcheckPort))
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, fmt.Sprintf("http://localhost:%d", healthcheckPort), http.NoBody)
if err != nil {
t.Logf("Failed to create request: %s", err)
return false
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Logf("Failed healthcheck: %s", err)
return false
Expand Down Expand Up @@ -647,7 +657,12 @@ func TestSupervisorStartsCollectorWithRemoteConfigAndExecParams(t *testing.T) {

for _, port := range []int{healthcheckPort, secondHealthcheckPort} {
require.Eventually(t, func() bool {
resp, err := http.DefaultClient.Get(fmt.Sprintf("http://localhost:%d", port))
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, fmt.Sprintf("http://localhost:%d", port), http.NoBody)
if err != nil {
t.Logf("Failed to create request: %s", err)
return false
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Logf("Failed healthcheck: %s", err)
return false
Expand Down Expand Up @@ -707,7 +722,9 @@ func TestSupervisorStartsWithNoOpAMPServer(t *testing.T) {

// Verify the collector is not running after 250 ms by checking the healthcheck endpoint
time.Sleep(250 * time.Millisecond)
_, err := http.DefaultClient.Get("http://localhost:12345")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://localhost:12345", http.NoBody)
require.NoError(t, err)
_, err = http.DefaultClient.Do(req)

if runtime.GOOS != "windows" {
require.ErrorContains(t, err, "connection refused")
Expand Down Expand Up @@ -1911,7 +1928,12 @@ func TestSupervisorStopsAgentProcessWithEmptyConfigMap(t *testing.T) {

// Use health check endpoint to determine if the collector is actually running
require.Eventually(t, func() bool {
resp, err := http.DefaultClient.Get("http://localhost:13133")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://localhost:13133", http.NoBody)
if err != nil {
t.Logf("Failed to create request: %s", err)
return false
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Logf("Failed agent healthcheck request: %s", err)
return false
Expand Down Expand Up @@ -1943,7 +1965,9 @@ func TestSupervisorStopsAgentProcessWithEmptyConfigMap(t *testing.T) {

// Verify the collector is not running after 250 ms by checking the healthcheck endpoint
require.EventuallyWithT(t, func(tt *assert.CollectT) {
_, err := http.DefaultClient.Get("http://localhost:12345")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://localhost:12345", http.NoBody)
assert.NoError(tt, err)
_, err = http.DefaultClient.Do(req)
if runtime.GOOS != "windows" {
assert.ErrorContains(tt, err, "connection refused")
} else {
Expand Down Expand Up @@ -2319,7 +2343,12 @@ func TestSupervisorHealthCheckServer(t *testing.T) {

// Wait for the health check server to start
require.Eventually(t, func() bool {
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/health", randomPort))
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, fmt.Sprintf("http://localhost:%d/health", randomPort), http.NoBody)
if err != nil {
t.Logf("Failed to create request: %s", err)
return false
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Logf("Failed health check request: %s", err)
return false
Expand Down Expand Up @@ -2358,7 +2387,12 @@ func TestSupervisorHealthCheckServerBackendConnError(t *testing.T) {

// Wait for the health check server to start
require.Eventually(t, func() bool {
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/health", healthcheckPort))
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, fmt.Sprintf("http://localhost:%d/health", healthcheckPort), http.NoBody)
if err != nil {
t.Logf("Failed to create request: %s", err)
return false
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Logf("Failed health check request: %s", err)
return false
Expand Down
22 changes: 13 additions & 9 deletions cmd/opampsupervisor/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2125,12 +2125,16 @@ func TestSupervisor_HealthCheckServer(t *testing.T) {
addr := fmt.Sprintf("localhost:%d", s.config.HealthCheck.Port())
require.NotEmpty(t, addr)

sendHealthCheckRequest := func() (*http.Response, error) {
return http.Get(fmt.Sprintf("http://%s/health", addr))
sendHealthCheckRequest := func(t *testing.T) (*http.Response, error) {
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, fmt.Sprintf("http://%s/health", addr), http.NoBody)
if err != nil {
return nil, err
}
return http.DefaultClient.Do(req)
}

t.Run("Health check server startup", func(t *testing.T) {
resp, respErr := sendHealthCheckRequest()
resp, respErr := sendHealthCheckRequest(t)
require.NoError(t, respErr)
defer resp.Body.Close()
body, bodyErr := io.ReadAll(resp.Body)
Expand All @@ -2142,7 +2146,7 @@ func TestSupervisor_HealthCheckServer(t *testing.T) {
s.cfgState.Store(healthyConfig)
s.persistentState = &persistentState{InstanceID: testUUID}

resp, respErr := sendHealthCheckRequest()
resp, respErr := sendHealthCheckRequest(t)
require.NoError(t, respErr)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
Expand All @@ -2155,7 +2159,7 @@ func TestSupervisor_HealthCheckServer(t *testing.T) {
})
s.persistentState = nil

resp, respErr := sendHealthCheckRequest()
resp, respErr := sendHealthCheckRequest(t)
require.NoError(t, respErr)
defer resp.Body.Close()
assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode)
Expand All @@ -2168,7 +2172,7 @@ func TestSupervisor_HealthCheckServer(t *testing.T) {
})
s.cfgState = &atomic.Value{}

resp, respErr := sendHealthCheckRequest()
resp, respErr := sendHealthCheckRequest(t)
require.NoError(t, respErr)
defer resp.Body.Close()
assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode)
Expand All @@ -2181,7 +2185,7 @@ func TestSupervisor_HealthCheckServer(t *testing.T) {
})
s.cfgState = &atomic.Value{}

resp, respErr := sendHealthCheckRequest()
resp, respErr := sendHealthCheckRequest(t)
require.NoError(t, respErr)
defer resp.Body.Close()
assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode)
Expand All @@ -2207,14 +2211,14 @@ func TestSupervisor_HealthCheckServer(t *testing.T) {
})

t.Run("Health check server shutdown is handled gracefully in Supervisor.Shutdown", func(t *testing.T) {
resp, err := sendHealthCheckRequest()
resp, err := sendHealthCheckRequest(t)
require.NoError(t, err)
resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)

s.Shutdown()

_, err = sendHealthCheckRequest()
_, err = sendHealthCheckRequest(t)
assert.Error(t, err)
})
}
14 changes: 7 additions & 7 deletions exporter/mezmoexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func newLogsExporter(config *Config, settings component.TelemetrySettings, build
return e
}

func (m *mezmoExporter) pushLogData(_ context.Context, ld plog.Logs) error {
func (m *mezmoExporter) pushLogData(ctx context.Context, ld plog.Logs) error {
m.wg.Add(1)
defer m.wg.Done()

return m.logDataToMezmo(ld)
return m.logDataToMezmo(ctx, ld)
}

func (m *mezmoExporter) start(ctx context.Context, host component.Host) (err error) {
Expand All @@ -72,7 +72,7 @@ func (m *mezmoExporter) stop(context.Context) (err error) {
return nil
}

func (m *mezmoExporter) logDataToMezmo(ld plog.Logs) error {
func (m *mezmoExporter) logDataToMezmo(ctx context.Context, ld plog.Logs) error {
var errs error

var lines []mezmoLogLine
Expand Down Expand Up @@ -147,7 +147,7 @@ func (m *mezmoExporter) logDataToMezmo(ld plog.Logs) error {
if newBufSize >= maxBodySize-2 {
str := b.String()
str = str[:len(str)-1] + "]}"
if errs := m.sendLinesToMezmo(str); errs != nil {
if errs := m.sendLinesToMezmo(ctx, str); errs != nil {
return errs
}
b.Reset()
Expand All @@ -161,11 +161,11 @@ func (m *mezmoExporter) logDataToMezmo(ld plog.Logs) error {
}
}

return m.sendLinesToMezmo(b.String() + "]}")
return m.sendLinesToMezmo(ctx, b.String()+"]}")
}

func (m *mezmoExporter) sendLinesToMezmo(post string) (errs error) {
req, _ := http.NewRequest(http.MethodPost, m.config.IngestURL, strings.NewReader(post))
func (m *mezmoExporter) sendLinesToMezmo(ctx context.Context, post string) (errs error) {
req, _ := http.NewRequestWithContext(ctx, http.MethodPost, m.config.IngestURL, strings.NewReader(post))
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("User-Agent", m.userAgentString)
Expand Down
4 changes: 3 additions & 1 deletion exporter/prometheusexporter/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func TestEndToEndSummarySupport(t *testing.T) {
// 4. Scrape from the Prometheus receiver to ensure that we export summary metrics
wg.Wait()

res, err := http.Get("http://" + exporterCfg.Endpoint + "/metrics")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+exporterCfg.Endpoint+"/metrics", http.NoBody)
require.NoError(t, err)
res, err := http.DefaultClient.Do(req)
require.NoError(t, err, "Failed to scrape from the exporter")
prometheusExporterScrape, err := io.ReadAll(res.Body)
res.Body.Close()
Expand Down
40 changes: 28 additions & 12 deletions exporter/prometheusexporter/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ func TestPrometheusExporter_WithTLS(t *testing.T) {

assert.NoError(t, exp.ConsumeMetrics(t.Context(), md))

rsp, err := httpClient.Get("https://" + addr + "/metrics")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "https://"+addr+"/metrics", http.NoBody)
require.NoError(t, err)
rsp, err := httpClient.Do(req)
require.NoError(t, err, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, rsp.StatusCode, "Mismatched HTTP response status code")
Expand Down Expand Up @@ -209,8 +211,10 @@ func TestPrometheusExporter_endToEndMultipleTargets(t *testing.T) {
assert.NoError(t, exp.ConsumeMetrics(t.Context(), metricBuilder(int64(delta), "metric_2_", "cpu-exporter", "localhost:8080")))
assert.NoError(t, exp.ConsumeMetrics(t.Context(), metricBuilder(int64(delta), "metric_2_", "cpu-exporter", "localhost:8081")))

res, err1 := http.Get("http://" + addr + "/metrics")
require.NoError(t, err1, "Failed to perform a scrape")
req, err1 := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err1)
res, err2 := http.DefaultClient.Do(req)
require.NoError(t, err2, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, res.StatusCode, "Mismatched HTTP response status code")
blob, _ := io.ReadAll(res.Body)
Expand Down Expand Up @@ -239,7 +243,9 @@ func TestPrometheusExporter_endToEndMultipleTargets(t *testing.T) {
exp.(*wrapMetricsExporter).exporter.collector.accumulator.(*lastValueAccumulator).metricExpiration = 1 * time.Millisecond
time.Sleep(10 * time.Millisecond)

res, err := http.Get("http://" + addr + "/metrics")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err)
res, err := http.DefaultClient.Do(req)
require.NoError(t, err, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, res.StatusCode, "Mismatched HTTP response status code")
Expand Down Expand Up @@ -281,8 +287,10 @@ func TestPrometheusExporter_endToEnd(t *testing.T) {
for delta := 0; delta <= 20; delta += 10 {
assert.NoError(t, exp.ConsumeMetrics(t.Context(), metricBuilder(int64(delta), "metric_2_", "cpu-exporter", "localhost:8080")))

res, err1 := http.Get("http://" + addr + "/metrics")
require.NoError(t, err1, "Failed to perform a scrape")
req, err1 := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err1)
res, err2 := http.DefaultClient.Do(req)
require.NoError(t, err2, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, res.StatusCode, "Mismatched HTTP response status code")
blob, _ := io.ReadAll(res.Body)
Expand All @@ -307,7 +315,9 @@ func TestPrometheusExporter_endToEnd(t *testing.T) {
exp.(*wrapMetricsExporter).exporter.collector.accumulator.(*lastValueAccumulator).metricExpiration = 1 * time.Millisecond
time.Sleep(10 * time.Millisecond)

res, err := http.Get("http://" + addr + "/metrics")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err)
res, err := http.DefaultClient.Do(req)
require.NoError(t, err, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, res.StatusCode, "Mismatched HTTP response status code")
Expand Down Expand Up @@ -350,8 +360,10 @@ func TestPrometheusExporter_endToEndWithTimestamps(t *testing.T) {
for delta := 0; delta <= 20; delta += 10 {
assert.NoError(t, exp.ConsumeMetrics(t.Context(), metricBuilder(int64(delta), "metric_2_", "node-exporter", "localhost:8080")))

res, err1 := http.Get("http://" + addr + "/metrics")
require.NoError(t, err1, "Failed to perform a scrape")
req, err1 := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err1)
res, err2 := http.DefaultClient.Do(req)
require.NoError(t, err2, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, res.StatusCode, "Mismatched HTTP response status code")
blob, _ := io.ReadAll(res.Body)
Expand All @@ -376,7 +388,9 @@ func TestPrometheusExporter_endToEndWithTimestamps(t *testing.T) {
exp.(*wrapMetricsExporter).exporter.collector.accumulator.(*lastValueAccumulator).metricExpiration = 1 * time.Millisecond
time.Sleep(10 * time.Millisecond)

res, err := http.Get("http://" + addr + "/metrics")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err)
res, err := http.DefaultClient.Do(req)
require.NoError(t, err, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, res.StatusCode, "Mismatched HTTP response status code")
Expand Down Expand Up @@ -420,7 +434,9 @@ func TestPrometheusExporter_endToEndWithResource(t *testing.T) {

assert.NoError(t, exp.ConsumeMetrics(t.Context(), md))

rsp, err := http.Get("http://" + addr + "/metrics")
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err)
rsp, err := http.DefaultClient.Do(req)
require.NoError(t, err, "Failed to perform a scrape")

assert.Equal(t, http.StatusOK, rsp.StatusCode, "Mismatched HTTP response status code")
Expand Down Expand Up @@ -679,7 +695,7 @@ this_one_there_where_{arch="x86",instance="test-instance",job="test-service",os=
assert.NoError(t, exp.ConsumeMetrics(t.Context(), md))

// Scrape metrics, with the Accept header set to the value specified in the test case
req, err := http.NewRequest(http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "http://"+addr+"/metrics", http.NoBody)
require.NoError(t, err)
for k, v := range tt.extraHeaders {
req.Header.Set(k, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func Test_PushMetricsConcurrent(t *testing.T) {

// Ensure that the test server is up before making the requests
assert.EventuallyWithT(t, func(c *assert.CollectT) {
resp, checkRequestErr := http.Get(server.URL)
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, server.URL, http.NoBody)
require.NoError(c, err)
resp, checkRequestErr := http.DefaultClient.Do(req)
require.NoError(c, checkRequestErr)
assert.NoError(c, resp.Body.Close())
}, 15*time.Second, 100*time.Millisecond)
Expand Down
6 changes: 3 additions & 3 deletions exporter/signalfxexporter/internal/apm/correlations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ func (cc *Client) makeRequest(r *request) {

switch r.operation {
case http.MethodGet:
req, err = http.NewRequest(r.operation, endpoint, http.NoBody)
req, err = http.NewRequestWithContext(context.Background(), r.operation, endpoint, http.NoBody)
case http.MethodPut:
// TODO: pool the reader
endpoint = fmt.Sprintf("%s/%s", endpoint, r.Type)
req, err = http.NewRequest(r.operation, endpoint, strings.NewReader(r.Value))
req, err = http.NewRequestWithContext(context.Background(), r.operation, endpoint, strings.NewReader(r.Value))
req.Header.Add("Content-Type", "text/plain")
case http.MethodDelete:
endpoint = fmt.Sprintf("%s/%s/%s", endpoint, r.Type, url.PathEscape(r.Value))
req, err = http.NewRequest(r.operation, endpoint, http.NoBody)
req, err = http.NewRequestWithContext(context.Background(), r.operation, endpoint, http.NoBody)
default:
err = errors.New("unknown operation")
}
Expand Down
Loading
Loading