chore: remove all remaining uses of golang.org/x/net/context (#47564)

* chore: remove all remaining uses of  golang.org/x/net/context

This PR finishes the work started in #47532, replacing all calls to that package with the stdlib context and using http.NewRequestWithContext to include the context where necessary.

Bonus: small formatting fixes to goimports in these files.

closes #44178

* tweak: use context.Background in favor of TODO for tests
This commit is contained in:
Kristin Laemmert
2022-04-11 14:20:10 -04:00
committed by GitHub
parent 03ba91e8a4
commit 8f6877e12a
10 changed files with 36 additions and 38 deletions
+4 -5
View File
@@ -15,7 +15,6 @@ import (
"time"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/net/context/ctxhttp"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
@@ -148,7 +147,7 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
s.logger.Debug("Graphite request", "params", formData)
}
graphiteReq, err := s.createRequest(dsInfo, formData)
graphiteReq, err := s.createRequest(ctx, dsInfo, formData)
if err != nil {
return &result, err
}
@@ -163,7 +162,7 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
defer span.End()
s.tracer.Inject(ctx, graphiteReq.Header, span)
res, err := ctxhttp.Do(ctx, dsInfo.HTTPClient, graphiteReq)
res, err := dsInfo.HTTPClient.Do(graphiteReq)
if err != nil {
return &result, err
}
@@ -252,14 +251,14 @@ func (s *Service) toDataFrames(response *http.Response) (frames data.Frames, err
return frames, nil
}
func (s *Service) createRequest(dsInfo *datasourceInfo, data url.Values) (*http.Request, error) {
func (s *Service) createRequest(ctx context.Context, dsInfo *datasourceInfo, data url.Values) (*http.Request, error) {
u, err := url.Parse(dsInfo.URL)
if err != nil {
return nil, err
}
u.Path = path.Join(u.Path, "render")
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(data.Encode()))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, u.String(), strings.NewReader(data.Encode()))
if err != nil {
s.logger.Info("Failed to create request", "error", err)
return nil, fmt.Errorf("failed to create request: %w", err)