From 306fd73e323512a775d908ffda24d4cf5cb7fd58 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Fri, 9 Nov 2018 10:00:23 +0100 Subject: [PATCH] *: remove use of golang.org/x/net/context Signed-off-by: Simon Pasquier --- dispatch/dispatch.go | 2 +- dispatch/dispatch_test.go | 2 +- notify/impl.go | 29 ++++++++++++------- notify/impl_test.go | 2 +- notify/notify.go | 2 +- notify/notify_test.go | 6 ++-- test/with_api_v1/acceptance.go | 2 +- test/with_api_v2/acceptance.go | 2 +- .../client/alert/get_alerts_parameters.go | 3 +- .../client/alert/post_alerts_parameters.go | 3 +- .../general/get_receivers_parameters.go | 3 +- .../client/general/get_status_parameters.go | 3 +- .../receiver/get_receivers_parameters.go | 3 +- .../silence/delete_silence_parameters.go | 3 +- .../client/silence/get_silence_parameters.go | 3 +- .../client/silence/get_silences_parameters.go | 3 +- .../silence/post_silences_parameters.go | 3 +- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/dispatch/dispatch.go b/dispatch/dispatch.go index a8397abe..01182d5b 100644 --- a/dispatch/dispatch.go +++ b/dispatch/dispatch.go @@ -14,6 +14,7 @@ package dispatch import ( + "context" "fmt" "sort" "sync" @@ -22,7 +23,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" "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/provider" diff --git a/dispatch/dispatch_test.go b/dispatch/dispatch_test.go index 13099bc5..f68745b2 100644 --- a/dispatch/dispatch_test.go +++ b/dispatch/dispatch_test.go @@ -14,6 +14,7 @@ package dispatch import ( + "context" "reflect" "sort" "sync" @@ -22,7 +23,6 @@ import ( "github.com/go-kit/kit/log" "github.com/prometheus/common/model" - "golang.org/x/net/context" "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/types" diff --git a/notify/impl.go b/notify/impl.go index c018a73d..d797ebb5 100644 --- a/notify/impl.go +++ b/notify/impl.go @@ -15,11 +15,13 @@ package notify import ( "bytes" + "context" "crypto/sha256" "crypto/tls" "encoding/json" "errors" "fmt" + "io" "io/ioutil" "mime" "mime/multipart" @@ -37,8 +39,6 @@ import ( commoncfg "github.com/prometheus/common/config" "github.com/prometheus/common/model" "github.com/prometheus/common/version" - "golang.org/x/net/context" - "golang.org/x/net/context/ctxhttp" "github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/template" @@ -177,7 +177,7 @@ func (w *Webhook) Notify(ctx context.Context, alerts ...*types.Alert) (bool, err return false, err } - resp, err := ctxhttp.Do(ctx, c, req) + resp, err := c.Do(req.WithContext(ctx)) if err != nil { return true, err } @@ -530,7 +530,7 @@ func (n *PagerDuty) notifyV1( return false, err } - resp, err := ctxhttp.Post(ctx, c, n.conf.URL.String(), contentTypeJSON, &buf) + resp, err := post(ctx, c, n.conf.URL.String(), contentTypeJSON, &buf) if err != nil { return true, err } @@ -593,7 +593,7 @@ func (n *PagerDuty) notifyV2( return false, err } - resp, err := ctxhttp.Post(ctx, c, n.conf.URL.String(), contentTypeJSON, &buf) + resp, err := post(ctx, c, n.conf.URL.String(), contentTypeJSON, &buf) if err != nil { return true, err } @@ -815,7 +815,7 @@ func (n *Slack) Notify(ctx context.Context, as ...*types.Alert) (bool, error) { return false, err } - resp, err := ctxhttp.Post(ctx, c, n.conf.APIURL.String(), contentTypeJSON, &buf) + resp, err := post(ctx, c, n.conf.APIURL.String(), contentTypeJSON, &buf) if err != nil { return true, err } @@ -902,7 +902,7 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) return false, err } - resp, err := ctxhttp.Post(ctx, c, apiURL.String(), contentTypeJSON, &buf) + resp, err := post(ctx, c, apiURL.String(), contentTypeJSON, &buf) if err != nil { return true, err } @@ -1129,7 +1129,7 @@ func (n *OpsGenie) Notify(ctx context.Context, as ...*types.Alert) (bool, error) return false, err } - resp, err := ctxhttp.Do(ctx, c, req) + resp, err := c.Do(req.WithContext(ctx)) if err != nil { return true, err @@ -1329,7 +1329,7 @@ func (n *VictorOps) Notify(ctx context.Context, as ...*types.Alert) (bool, error return false, err } - resp, err := ctxhttp.Post(ctx, c, apiURL.String(), contentTypeJSON, &buf) + resp, err := post(ctx, c, apiURL.String(), contentTypeJSON, &buf) if err != nil { return true, err } @@ -1426,7 +1426,7 @@ func (n *Pushover) Notify(ctx context.Context, as ...*types.Alert) (bool, error) return false, err } - resp, err := ctxhttp.Post(ctx, c, u.String(), "text/plain", nil) + resp, err := post(ctx, c, u.String(), "text/plain", nil) if err != nil { return true, err } @@ -1506,3 +1506,12 @@ func hashKey(s string) string { h.Write([]byte(s)) return fmt.Sprintf("%x", h.Sum(nil)) } + +func post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) { + req, err := http.NewRequest("POST", url, body) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", bodyType) + return client.Do(req.WithContext(ctx)) +} diff --git a/notify/impl_test.go b/notify/impl_test.go index dee15a11..deba46dd 100644 --- a/notify/impl_test.go +++ b/notify/impl_test.go @@ -14,6 +14,7 @@ package notify import ( + "context" "fmt" "io/ioutil" "net/http" @@ -23,7 +24,6 @@ import ( "github.com/go-kit/kit/log" "github.com/stretchr/testify/require" - "golang.org/x/net/context" "github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/template" diff --git a/notify/notify.go b/notify/notify.go index ad0ca056..4e28428d 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -14,6 +14,7 @@ package notify import ( + "context" "fmt" "sort" "sync" @@ -25,7 +26,6 @@ import ( "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" - "golang.org/x/net/context" "github.com/prometheus/alertmanager/cluster" "github.com/prometheus/alertmanager/config" diff --git a/notify/notify_test.go b/notify/notify_test.go index 276a2449..2fe3bd9f 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -13,6 +13,7 @@ package notify import ( + "context" "errors" "fmt" "io" @@ -23,7 +24,6 @@ import ( "github.com/go-kit/kit/log" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" - "golang.org/x/net/context" "github.com/prometheus/alertmanager/nflog" "github.com/prometheus/alertmanager/nflog/nflogpb" @@ -617,7 +617,7 @@ func TestSilenceStage(t *testing.T) { // the WasSilenced flag set to true afterwards. marker.SetSilenced(inAlerts[1].Fingerprint(), "123") - _, alerts, err := silencer.Exec(nil, log.NewNopLogger(), inAlerts...) + _, alerts, err := silencer.Exec(context.Background(), log.NewNopLogger(), inAlerts...) if err != nil { t.Fatalf("Exec failed: %s", err) } @@ -665,7 +665,7 @@ func TestInhibitStage(t *testing.T) { }) } - _, alerts, err := inhibitor.Exec(nil, log.NewNopLogger(), inAlerts...) + _, alerts, err := inhibitor.Exec(context.Background(), log.NewNopLogger(), inAlerts...) if err != nil { t.Fatalf("Exec failed: %s", err) } diff --git a/test/with_api_v1/acceptance.go b/test/with_api_v1/acceptance.go index 85b8bc66..0d302155 100644 --- a/test/with_api_v1/acceptance.go +++ b/test/with_api_v1/acceptance.go @@ -15,6 +15,7 @@ package test import ( "bytes" + "context" "encoding/json" "fmt" "io/ioutil" @@ -30,7 +31,6 @@ import ( "github.com/prometheus/client_golang/api" "github.com/prometheus/common/model" - "golang.org/x/net/context" "github.com/prometheus/alertmanager/client" ) diff --git a/test/with_api_v2/acceptance.go b/test/with_api_v2/acceptance.go index 023fb4dd..e6b977aa 100644 --- a/test/with_api_v2/acceptance.go +++ b/test/with_api_v2/acceptance.go @@ -15,6 +15,7 @@ package test import ( "bytes" + "context" "encoding/json" "fmt" "io/ioutil" @@ -35,7 +36,6 @@ import ( httptransport "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" - "golang.org/x/net/context" ) // AcceptanceTest provides declarative definition of given inputs and expected diff --git a/test/with_api_v2/api_v2_client/client/alert/get_alerts_parameters.go b/test/with_api_v2/api_v2_client/client/alert/get_alerts_parameters.go index bacb8b05..50d2c492 100644 --- a/test/with_api_v2/api_v2_client/client/alert/get_alerts_parameters.go +++ b/test/with_api_v2/api_v2_client/client/alert/get_alerts_parameters.go @@ -6,11 +6,10 @@ package alert // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/alert/post_alerts_parameters.go b/test/with_api_v2/api_v2_client/client/alert/post_alerts_parameters.go index 235b2109..c944e4fe 100644 --- a/test/with_api_v2/api_v2_client/client/alert/post_alerts_parameters.go +++ b/test/with_api_v2/api_v2_client/client/alert/post_alerts_parameters.go @@ -6,11 +6,10 @@ package alert // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/general/get_receivers_parameters.go b/test/with_api_v2/api_v2_client/client/general/get_receivers_parameters.go index 712363b4..6f585fc7 100644 --- a/test/with_api_v2/api_v2_client/client/general/get_receivers_parameters.go +++ b/test/with_api_v2/api_v2_client/client/general/get_receivers_parameters.go @@ -6,11 +6,10 @@ package general // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/general/get_status_parameters.go b/test/with_api_v2/api_v2_client/client/general/get_status_parameters.go index db0c79e6..2fae2aee 100644 --- a/test/with_api_v2/api_v2_client/client/general/get_status_parameters.go +++ b/test/with_api_v2/api_v2_client/client/general/get_status_parameters.go @@ -6,11 +6,10 @@ package general // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/receiver/get_receivers_parameters.go b/test/with_api_v2/api_v2_client/client/receiver/get_receivers_parameters.go index e0773d7b..fd2b08b0 100644 --- a/test/with_api_v2/api_v2_client/client/receiver/get_receivers_parameters.go +++ b/test/with_api_v2/api_v2_client/client/receiver/get_receivers_parameters.go @@ -6,11 +6,10 @@ package receiver // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/silence/delete_silence_parameters.go b/test/with_api_v2/api_v2_client/client/silence/delete_silence_parameters.go index 96b21e39..6b49b302 100644 --- a/test/with_api_v2/api_v2_client/client/silence/delete_silence_parameters.go +++ b/test/with_api_v2/api_v2_client/client/silence/delete_silence_parameters.go @@ -6,11 +6,10 @@ package silence // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/silence/get_silence_parameters.go b/test/with_api_v2/api_v2_client/client/silence/get_silence_parameters.go index ae9babba..bd6f3450 100644 --- a/test/with_api_v2/api_v2_client/client/silence/get_silence_parameters.go +++ b/test/with_api_v2/api_v2_client/client/silence/get_silence_parameters.go @@ -6,11 +6,10 @@ package silence // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/silence/get_silences_parameters.go b/test/with_api_v2/api_v2_client/client/silence/get_silences_parameters.go index a7c2ceda..f26119be 100644 --- a/test/with_api_v2/api_v2_client/client/silence/get_silences_parameters.go +++ b/test/with_api_v2/api_v2_client/client/silence/get_silences_parameters.go @@ -6,11 +6,10 @@ package silence // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/test/with_api_v2/api_v2_client/client/silence/post_silences_parameters.go b/test/with_api_v2/api_v2_client/client/silence/post_silences_parameters.go index 767a224b..f0dd9a2c 100644 --- a/test/with_api_v2/api_v2_client/client/silence/post_silences_parameters.go +++ b/test/with_api_v2/api_v2_client/client/silence/post_silences_parameters.go @@ -6,11 +6,10 @@ package silence // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client"