Skip to content

Commit

Permalink
[chore]: enable usestdlibvars linter (part 2)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Oct 30, 2024
1 parent 2e60343 commit 4bf94b0
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ linters:
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign

issues:
Expand Down
3 changes: 2 additions & 1 deletion exporter/datadogexporter/internal/clientutil/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package clientutil // import "github.com/open-telemetry/opentelemetry-collector-
import (
"context"
"errors"
"net/http"

"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
Expand Down Expand Up @@ -45,7 +46,7 @@ func ValidateAPIKey(ctx context.Context, apiKey string, logger *zap.Logger, apiC
return nil
}
if err != nil {
if httpresp != nil && httpresp.StatusCode == 403 {
if httpresp != nil && httpresp.StatusCode == http.StatusForbidden {
return WrapError(ErrInvalidAPI, httpresp)
}
logger.Warn("Error while validating API key", zap.Error(err))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func WrapError(err error, resp *http.Response) error {
}

func isNonRetriable(resp *http.Response) bool {
return resp.StatusCode == 400 || resp.StatusCode == 404 || resp.StatusCode == 413 || resp.StatusCode == 403
return resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusNotFound || resp.StatusCode == 413 || resp.StatusCode == 403
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
)

func TestWrapError(t *testing.T) {
respOK := http.Response{StatusCode: 200}
respRetriable := http.Response{StatusCode: 402}
respNonRetriable := http.Response{StatusCode: 404}
respOK := http.Response{StatusCode: http.StatusOK}
respRetriable := http.Response{StatusCode: http.StatusPaymentRequired}
respNonRetriable := http.Response{StatusCode: http.StatusNotFound}
err := fmt.Errorf("Test error")
assert.False(t, consumererror.IsPermanent(WrapError(err, &respOK)))
assert.False(t, consumererror.IsPermanent(WrapError(err, &respRetriable)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestNoRetriesOnPermanentError(t *testing.T) {
scrubber := scrub.NewScrubber()
retrier := NewRetrier(zap.NewNop(), configretry.NewDefaultBackOffConfig(), scrubber)
ctx := context.Background()
respNonRetriable := http.Response{StatusCode: 404}
respNonRetriable := http.Response{StatusCode: http.StatusNotFound}

retryNum, err := retrier.DoWithRetries(ctx, func(context.Context) error {
return WrapError(fmt.Errorf("test"), &respNonRetriable)
Expand Down
2 changes: 1 addition & 1 deletion exporter/lokiexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (l *lokiExporter) sendPushRequest(ctx context.Context, tenant string, reque
return consumererror.NewPermanent(err)
}

req, err := http.NewRequestWithContext(ctx, "POST", l.config.ClientConfig.Endpoint, bytes.NewReader(buf))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, l.config.ClientConfig.Endpoint, bytes.NewReader(buf))
if err != nil {
return consumererror.NewPermanent(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (prwe *prwExporter) execute(ctx context.Context, writeReq *prompb.WriteRequ
}

// Create the HTTP POST request to send to the endpoint
req, err := http.NewRequestWithContext(ctx, "POST", prwe.endpointURL.String(), bytes.NewReader(compressedData))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, prwe.endpointURL.String(), bytes.NewReader(compressedData))
if err != nil {
return backoff.Permanent(consumererror.NewPermanent(err))
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/signalfxexporter/dpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *sfxDPClient) postData(ctx context.Context, body io.Reader, headers map[
if !strings.HasSuffix(datapointURL.Path, "v2/datapoint") {
datapointURL.Path = path.Join(datapointURL.Path, "v2/datapoint")
}
req, err := http.NewRequestWithContext(ctx, "POST", datapointURL.String(), body)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, datapointURL.String(), body)
if err != nil {
return consumererror.NewPermanent(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/signalfxexporter/eventclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *sfxEventClient) pushLogsData(ctx context.Context, ld plog.Logs) (int, e
if !strings.HasSuffix(eventURL.Path, "v2/event") {
eventURL.Path = path.Join(eventURL.Path, "v2/event")
}
req, err := http.NewRequestWithContext(ctx, "POST", eventURL.String(), body)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, eventURL.String(), body)
if err != nil {
return ld.LogRecordCount(), consumererror.NewPermanent(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func makeHandler(t *testing.T, corCh chan<- *request, forcedRespCode *atomic.Val

body, err := io.ReadAll(r.Body)
if err != nil {
rw.WriteHeader(400)
rw.WriteHeader(http.StatusBadRequest)
return
}
cor = &request{
Expand Down
2 changes: 1 addition & 1 deletion exporter/signalfxexporter/internal/dimensions/dimclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (dc *DimensionClient) makePatchRequest(ctx context.Context, dim *DimensionU

req, err := http.NewRequestWithContext(
ctx,
"PATCH",
http.MethodPatch,
strings.TrimRight(url.String(), "/")+"/_/sfxagent",
bytes.NewReader(json))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exporter/splunkhecexporter/hec_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (hec *defaultHecWorker) send(ctx context.Context, buf buffer, headers map[s
nb := make([]byte, buf.Len())
copy(nb, buf.Bytes())
bodyBuf := bytes.NewReader(nb)
req, err := http.NewRequestWithContext(ctx, "POST", hec.url.String(), bodyBuf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, hec.url.String(), bodyBuf)
if err != nil {
return consumererror.NewPermanent(err)
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/zipkinexporter/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (ze *zipkinExporter) pushTraces(ctx context.Context, td ptrace.Traces) erro
return consumererror.NewPermanent(fmt.Errorf("failed to push trace data via Zipkin exporter: %w", err))
}

req, err := http.NewRequestWithContext(ctx, "POST", ze.url, bytes.NewReader(body))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, ze.url, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("failed to push trace data via Zipkin exporter: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/asapauthextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestRoundTripper(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, roundTripper)

req := &http.Request{Method: "Get", Header: map[string][]string{}}
req := &http.Request{Method: http.MethodGet, Header: map[string][]string{}}
resp, err := roundTripper.RoundTrip(req)
assert.NoError(t, err)
authHeaderValue := resp.Header.Get("Authorization")
Expand Down
8 changes: 4 additions & 4 deletions extension/bearertokenauthextension/bearertokenauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestBearerAuthenticatorHttp(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, c)

request := &http.Request{Method: "Get"}
request := &http.Request{Method: http.MethodGet}
resp, err := c.RoundTrip(request)
assert.NoError(t, err)
authHeaderValue := resp.Header.Get("Authorization")
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestBearerTokenFileContentUpdate(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, rt)

request := &http.Request{Method: "Get"}
request := &http.Request{Method: http.MethodGet}
resp, err := rt.RoundTrip(request)
assert.NoError(t, err)
authHeaderValue := resp.Header.Get("Authorization")
Expand All @@ -185,7 +185,7 @@ func TestBearerTokenFileContentUpdate(t *testing.T) {
assert.NoError(t, err)

// check if request is updated with the new token
request = &http.Request{Method: "Get"}
request = &http.Request{Method: http.MethodGet}
resp, err = rt.RoundTrip(request)
assert.NoError(t, err)
authHeaderValue = resp.Header.Get("Authorization")
Expand All @@ -196,7 +196,7 @@ func TestBearerTokenFileContentUpdate(t *testing.T) {
time.Sleep(5 * time.Second)

// check if request is updated with the old token
request = &http.Request{Method: "Get"}
request = &http.Request{Method: http.MethodGet}
resp, err = rt.RoundTrip(request)
assert.NoError(t, err)
authHeaderValue = resp.Header.Get("Authorization")
Expand Down
2 changes: 1 addition & 1 deletion internal/metadataproviders/azure/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (p *azureProviderImpl) Metadata(ctx context.Context) (*ComputeMetadata, err
return nil, fmt.Errorf("failed to query Azure IMDS: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {
//lint:ignore ST1005 Azure is a capitalized proper noun here
return nil, fmt.Errorf("Azure IMDS replied with status code: %s", resp.Status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (dd *ddExporter) pushTraces(ctx context.Context, td ptrace.Traces) error {
return consumererror.NewPermanent(fmt.Errorf("failed to encode msgp: %w", err))
}

req, err := http.NewRequestWithContext(ctx, "POST", dd.endpoint, &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, dd.endpoint, &buf)
if err != nil {
return fmt.Errorf("failed to push trace data via DD exporter: %w", err)
}
Expand Down

0 comments on commit 4bf94b0

Please sign in to comment.