Skip to content

*: remove dependency on github.com/prometheus/prometheus #2009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/pkg/labels"

"github.com/prometheus/alertmanager/api/metrics"
"github.com/prometheus/alertmanager/cluster"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/pkg/parse"
"github.com/prometheus/alertmanager/pkg/labels"
"github.com/prometheus/alertmanager/provider"
"github.com/prometheus/alertmanager/silence"
"github.com/prometheus/alertmanager/silence/silencepb"
Expand Down Expand Up @@ -258,7 +257,7 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) {
}

if filter := r.FormValue("filter"); filter != "" {
matchers, err = parse.Matchers(filter)
matchers, err = labels.ParseMatchers(filter)
if err != nil {
api.respondError(w, apiError{
typ: errorBadData,
Expand Down Expand Up @@ -579,7 +578,7 @@ func (api *API) listSilences(w http.ResponseWriter, r *http.Request) {

matchers := []*labels.Matcher{}
if filter := r.FormValue("filter"); filter != "" {
matchers, err = parse.Matchers(filter)
matchers, err = labels.ParseMatchers(filter)
if err != nil {
api.respondError(w, apiError{
typ: errorBadData,
Expand Down
7 changes: 4 additions & 3 deletions api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import (
"testing"
"time"

"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"

"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/pkg/labels"
"github.com/prometheus/alertmanager/provider"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/stretchr/testify/require"
)

// fakeAlerts is a struct implementing the provider.Alerts interface for tests.
Expand Down
9 changes: 3 additions & 6 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
prometheus_model "github.com/prometheus/common/model"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/rs/cors"

"github.com/prometheus/alertmanager/api/metrics"
Expand All @@ -44,7 +43,7 @@ import (
"github.com/prometheus/alertmanager/cluster"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/pkg/parse"
"github.com/prometheus/alertmanager/pkg/labels"
"github.com/prometheus/alertmanager/provider"
"github.com/prometheus/alertmanager/silence"
"github.com/prometheus/alertmanager/silence/silencepb"
Expand Down Expand Up @@ -557,7 +556,7 @@ func (api *API) getSilencesHandler(params silence_ops.GetSilencesParams) middlew
matchers := []*labels.Matcher{}
if params.Filter != nil {
for _, matcherString := range params.Filter {
matcher, err := parse.Matcher(matcherString)
matcher, err := labels.ParseMatcher(matcherString)
if err != nil {
level.Error(api.logger).Log("msg", "failed to parse matchers", "err", err)
return alert_ops.NewGetAlertsBadRequest().WithPayload(err.Error())
Expand Down Expand Up @@ -638,8 +637,6 @@ func gettableSilenceMatchesFilterLabels(s open_api_models.GettableSilence, match
return matchFilterLabels(matchers, sms)
}

// func matchesFilterLabels(labels model.LabelSet, matchers []*labels.Matcher) bool {

func (api *API) getSilenceHandler(params silence_ops.GetSilenceParams) middleware.Responder {
sils, _, err := api.silences.Query(silence.QIDs(params.SilenceID.String()))
if err != nil {
Expand Down Expand Up @@ -776,7 +773,7 @@ func postableSilenceToProto(s *open_api_models.PostableSilence) (*silencepb.Sile
func parseFilter(filter []string) ([]*labels.Matcher, error) {
matchers := make([]*labels.Matcher, 0, len(filter))
for _, matcherString := range filter {
matcher, err := parse.Matcher(matcherString)
matcher, err := labels.ParseMatcher(matcherString)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cli/alert_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/prometheus/alertmanager/api/v2/client/alert"
"github.com/prometheus/alertmanager/cli/format"
"github.com/prometheus/alertmanager/pkg/parse"
"github.com/prometheus/alertmanager/pkg/labels"
)

type alertQueryCmd struct {
Expand Down Expand Up @@ -80,7 +80,7 @@ func (a *alertQueryCmd) queryAlerts(ctx context.Context, _ *kingpin.ParseContext
// the user wants alertname=<arg> and prepend `alertname=` to
// the front.
m := a.matcherGroups[0]
_, err := parse.Matcher(m)
_, err := labels.ParseMatcher(m)
if err != nil {
a.matcherGroups[0] = fmt.Sprintf("alertname=%s", m)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/silence_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/prometheus/alertmanager/api/v2/client/silence"
"github.com/prometheus/alertmanager/api/v2/models"
"github.com/prometheus/alertmanager/cli/format"
"github.com/prometheus/alertmanager/pkg/parse"
"github.com/prometheus/alertmanager/pkg/labels"
)

type silenceQueryCmd struct {
Expand Down Expand Up @@ -94,7 +94,7 @@ func (c *silenceQueryCmd) query(ctx context.Context, _ *kingpin.ParseContext) er
// If the parser fails then we likely don't have a (=|=~|!=|!~) so lets
// assume that the user wants alertname=<arg> and prepend `alertname=`
// to the front.
_, err := parse.Matcher(c.matchers[0])
_, err := labels.ParseMatcher(c.matchers[0])
if err != nil {
c.matchers[0] = fmt.Sprintf("alertname=%s", c.matchers[0])
}
Expand Down
44 changes: 12 additions & 32 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,33 @@ import (
"os"
"path"

"github.com/prometheus/common/model"
kingpin "gopkg.in/alecthomas/kingpin.v2"

"github.com/prometheus/alertmanager/api/v2/client/general"
"github.com/prometheus/alertmanager/api/v2/models"
"github.com/prometheus/alertmanager/config"
kingpin "gopkg.in/alecthomas/kingpin.v2"

"github.com/prometheus/alertmanager/pkg/parse"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/alertmanager/pkg/labels"
)

type ByAlphabetical []labels.Matcher

func (s ByAlphabetical) Len() int { return len(s) }
func (s ByAlphabetical) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ByAlphabetical) Less(i, j int) bool {
if s[i].Name != s[j].Name {
return s[i].Name < s[j].Name
} else if s[i].Type != s[j].Type {
return s[i].Type < s[j].Type
} else if s[i].Value != s[j].Value {
return s[i].Value < s[j].Value
}
return false
}

// GetAlertmanagerURL appends the given path to the alertmanager base URL
func GetAlertmanagerURL(p string) url.URL {
amURL := *alertmanagerURL
amURL.Path = path.Join(alertmanagerURL.Path, p)
return amURL
}

// Parse a list of matchers (cli arguments)
// parseMatchers parses a list of matchers (cli arguments).
func parseMatchers(inputMatchers []string) ([]labels.Matcher, error) {
matchers := make([]labels.Matcher, 0)
matchers := make([]labels.Matcher, 0, len(inputMatchers))

for _, v := range inputMatchers {
name, value, matchType, err := parse.Input(v)
matcher, err := labels.ParseMatcher(v)
if err != nil {
return []labels.Matcher{}, err
}

matchers = append(matchers, labels.Matcher{
Type: matchType,
Name: name,
Value: value,
})
matchers = append(matchers, *matcher)
}

return matchers, nil
Expand Down Expand Up @@ -122,20 +102,20 @@ func convertClientToCommonLabelSet(cls models.LabelSet) model.LabelSet {
return mls
}

// Parse a list of labels (cli arguments)
// parseLabels parses a list of labels (cli arguments).
func parseLabels(inputLabels []string) (models.LabelSet, error) {
labelSet := make(models.LabelSet, len(inputLabels))

for _, l := range inputLabels {
name, value, matchType, err := parse.Input(l)
matcher, err := labels.ParseMatcher(l)
if err != nil {
return models.LabelSet{}, err
}
if matchType != labels.MatchEqual {
if matcher.Type != labels.MatchEqual {
return models.LabelSet{}, errors.New("labels must be specified as key=value pairs")
}

labelSet[name] = value
labelSet[matcher.Name] = matcher.Value
}

return labelSet, nil
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/prometheus/alertmanager

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
github.com/cenkalti/backoff v0.0.0-20181003080854-62661b46c409
github.com/cespare/xxhash v1.1.0
github.com/go-kit/kit v0.9.0
Expand All @@ -17,12 +19,13 @@ require (
github.com/jessevdk/go-flags v1.4.0
github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb
github.com/matttproud/golang_protobuf_extensions v1.0.1
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/oklog/run v1.0.0
github.com/oklog/ulid v1.3.1
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/common v0.6.0
github.com/prometheus/prometheus v0.0.0-20190818123050-43acd0e2e93f
github.com/rs/cors v1.6.0
github.com/satori/go.uuid v0.0.0-20160603004225-b111a074d5ef
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
Expand Down
Loading