mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
*: remove use of golang.org/x/net/context (#4869)
* *: remove use of golang.org/x/net/context Signed-off-by: Simon Pasquier <spasquie@redhat.com> * scrape: fix TestTargetScrapeScrapeCancel Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
ca93fd544b
commit
ed19373a78
|
@ -27,7 +27,6 @@ import (
|
|||
"github.com/go-kit/kit/log"
|
||||
"github.com/go-kit/kit/log/level"
|
||||
"github.com/prometheus/common/model"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -106,7 +105,12 @@ func (c *Client) Write(samples model.Samples) error {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := ctxhttp.Post(ctx, http.DefaultClient, u.String(), contentTypeJSON, bytes.NewBuffer(buf))
|
||||
req, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(buf))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", contentTypeJSON)
|
||||
resp, err := http.DefaultClient.Do(req.WithContext(ctx))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus"
|
||||
config_util "github.com/prometheus/common/config"
|
||||
"github.com/prometheus/common/model"
|
||||
old_ctx "golang.org/x/net/context"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
|
||||
"github.com/prometheus/prometheus/config"
|
||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||
|
@ -124,7 +122,7 @@ type Options struct {
|
|||
ExternalLabels model.LabelSet
|
||||
RelabelConfigs []*config.RelabelConfig
|
||||
// Used for sending HTTP requests to the Alertmanager.
|
||||
Do func(ctx old_ctx.Context, client *http.Client, req *http.Request) (*http.Response, error)
|
||||
Do func(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)
|
||||
|
||||
Registerer prometheus.Registerer
|
||||
}
|
||||
|
@ -206,12 +204,19 @@ func newAlertMetrics(r prometheus.Registerer, queueCap int, queueLen, alertmanag
|
|||
return m
|
||||
}
|
||||
|
||||
func do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
}
|
||||
return client.Do(req.WithContext(ctx))
|
||||
}
|
||||
|
||||
// NewManager is the manager constructor.
|
||||
func NewManager(o *Options, logger log.Logger) *Manager {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
if o.Do == nil {
|
||||
o.Do = ctxhttp.Do
|
||||
o.Do = do
|
||||
}
|
||||
if logger == nil {
|
||||
logger = log.NewNopLogger()
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
old_ctx "golang.org/x/net/context"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
config_util "github.com/prometheus/common/config"
|
||||
|
@ -212,7 +211,7 @@ func TestCustomDo(t *testing.T) {
|
|||
|
||||
var received bool
|
||||
h := NewManager(&Options{
|
||||
Do: func(ctx old_ctx.Context, client *http.Client, req *http.Request) (*http.Response, error) {
|
||||
Do: func(_ context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
|
||||
received = true
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ import (
|
|||
config_util "github.com/prometheus/common/config"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/version"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
|
||||
"github.com/prometheus/prometheus/config"
|
||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||
|
@ -469,7 +468,7 @@ func (s *targetScraper) scrape(ctx context.Context, w io.Writer) (string, error)
|
|||
s.req = req
|
||||
}
|
||||
|
||||
resp, err := ctxhttp.Do(ctx, s.client, s.req)
|
||||
resp, err := s.client.Do(s.req.WithContext(ctx))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -1252,8 +1252,11 @@ func TestTargetScrapeScrapeCancel(t *testing.T) {
|
|||
}()
|
||||
|
||||
go func() {
|
||||
if _, err := ts.scrape(ctx, ioutil.Discard); err != context.Canceled {
|
||||
errc <- fmt.Errorf("Expected context cancelation error but got: %s", err)
|
||||
_, err := ts.scrape(ctx, ioutil.Discard)
|
||||
if err == nil {
|
||||
errc <- fmt.Errorf("Expected error but got nil")
|
||||
} else if ctx.Err() != context.Canceled {
|
||||
errc <- fmt.Errorf("Expected context cancelation error but got: %s", ctx.Err())
|
||||
}
|
||||
close(errc)
|
||||
}()
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
"github.com/prometheus/common/model"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
|
||||
config_util "github.com/prometheus/common/config"
|
||||
"github.com/prometheus/prometheus/prompb"
|
||||
|
@ -90,7 +89,7 @@ func (c *Client) Store(ctx context.Context, req *prompb.WriteRequest) error {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
|
||||
defer cancel()
|
||||
|
||||
httpResp, err := ctxhttp.Do(ctx, c.client, httpReq)
|
||||
httpResp, err := c.client.Do(httpReq.WithContext(ctx))
|
||||
if err != nil {
|
||||
// Errors from client.Do are from (for example) network errors, so are
|
||||
// recoverable.
|
||||
|
@ -144,7 +143,7 @@ func (c *Client) Read(ctx context.Context, query *prompb.Query) (*prompb.QueryRe
|
|||
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||
defer cancel()
|
||||
|
||||
httpResp, err := ctxhttp.Do(ctx, c.client, httpReq)
|
||||
httpResp, err := c.client.Do(httpReq.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error sending request: %v", err)
|
||||
}
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -212,12 +212,12 @@ golang.org/x/crypto/ed25519
|
|||
golang.org/x/crypto/ed25519/internal/edwards25519
|
||||
golang.org/x/crypto/ssh/terminal
|
||||
# golang.org/x/net v0.0.0-20180320002117-6078986fec03
|
||||
golang.org/x/net/context/ctxhttp
|
||||
golang.org/x/net/context
|
||||
golang.org/x/net/netutil
|
||||
golang.org/x/net/trace
|
||||
golang.org/x/net/ipv4
|
||||
golang.org/x/net/ipv6
|
||||
golang.org/x/net/context/ctxhttp
|
||||
golang.org/x/net/http2
|
||||
golang.org/x/net/http2/hpack
|
||||
golang.org/x/net/internal/timeseries
|
||||
|
|
Loading…
Reference in a new issue