*: remove use of golang.org/x/net/context

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2018-11-09 10:00:23 +01:00
parent 625604df90
commit 306fd73e32
17 changed files with 37 additions and 37 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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))
}

View File

@ -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"

View File

@ -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"

View File

@ -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)
}

View File

@ -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"
)

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"