Skip to content

Commit

Permalink
[general] cleaning up nits from #2049 and #2055
Browse files Browse the repository at this point in the history
  • Loading branch information
arnikola committed Dec 3, 2019
1 parent f47d350 commit 8b7e574
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 236 deletions.
46 changes: 23 additions & 23 deletions scripts/docker-integration-tests/query_fanout/restrict.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ import (
"github.com/stretchr/testify/require"
)

type tester struct{}

// Ensure tester is a TestingT and set a global `t`.
var t require.TestingT = &tester{}

var (
// name is global and set on startup.
name string
// clusters are constant, set by the test harness.
clusters = []string{"coordinator-cluster-a", "coordinator-cluster-b"}
)

func (t *tester) Errorf(format string, args ...interface{}) {
_, fn, line, _ := runtime.Caller(4)
args[2] = fmt.Sprintf(" at %s:%d:\n%v", fn, line, args[2])
fmt.Printf(format, args...)
}

func (t *tester) FailNow() {
os.Exit(1)
}

func main() {
var ts int
flag.IntVar(&ts, "t", -1, "metric name to search")
Expand Down Expand Up @@ -93,24 +115,6 @@ func mustMatcher(t models.MatchType, n string, v string) models.Matcher {
return m
}

type tester struct{}

// Ensure tester is a TestingT and set a global `t`.
var t require.TestingT = &tester{}

// name is global and set on startup.
var name string

func (t *tester) Errorf(format string, args ...interface{}) {
_, fn, line, _ := runtime.Caller(4)
args[2] = fmt.Sprintf(" at %s:%d:\n%v", fn, line, args[2])
fmt.Printf(format, args...)
}

func (t *tester) FailNow() {
os.Exit(1)
}

func mustParseOpts(o handler.StringTagOptions) string {
m, err := json.Marshal(o)
require.NoError(t, err, "cannot marshal to json")
Expand All @@ -124,13 +128,12 @@ func bothClusterDefaultStrip(url string) {
},
})

resp, err := queryWithHeader(url, string(m))
resp, err := queryWithHeader(url, m)
require.NoError(t, err, "failed to query")

data := resp.Data.Result
data.Sort()
require.Equal(t, len(data), 2)
clusters := []string{"coordinator-cluster-a", "coordinator-cluster-b"}
for i, d := range data {
require.Equal(t, 2, len(d.Metric))
require.Equal(t, name, d.Metric["__name__"])
Expand All @@ -152,7 +155,6 @@ func bothClusterCustomStrip(url string) {
data := resp.Data.Result
data.Sort()
require.Equal(t, len(data), 2)
clusters := []string{"coordinator-cluster-a", "coordinator-cluster-b"}
for i, d := range data {
require.Equal(t, 2, len(d.Metric))
require.Equal(t, clusters[i], d.Metric["cluster"])
Expand All @@ -174,7 +176,6 @@ func bothClusterNoStrip(url string) {
data := resp.Data.Result
data.Sort()
require.Equal(t, len(data), 2)
clusters := []string{"coordinator-cluster-a", "coordinator-cluster-b"}
for i, d := range data {
require.Equal(t, 3, len(d.Metric))
require.Equal(t, name, d.Metric["__name__"])
Expand All @@ -197,7 +198,6 @@ func bothClusterMultiStrip(url string) {
data := resp.Data.Result
data.Sort()
require.Equal(t, len(data), 2)
clusters := []string{"coordinator-cluster-a", "coordinator-cluster-b"}
for i, d := range data {
require.Equal(t, 1, len(d.Metric))
require.Equal(t, clusters[i], d.Metric["cluster"])
Expand Down
2 changes: 1 addition & 1 deletion src/query/api/v1/handler/graphite/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
)

var (
// FindHTTPMethods is the HTTP methods used with this resource.
// FindHTTPMethods are the HTTP methods for this handler.
FindHTTPMethods = []string{http.MethodGet, http.MethodPost}
)

Expand Down
2 changes: 1 addition & 1 deletion src/query/api/v1/handler/graphite/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (
)

var (
// ReadHTTPMethods is the HTTP methods used with this resource.
// ReadHTTPMethods are the HTTP methods used with this resource.
ReadHTTPMethods = []string{http.MethodGet, http.MethodPost}
)

Expand Down
2 changes: 1 addition & 1 deletion src/query/api/v1/handler/prometheus/native/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestParamParsing_POST(t *testing.T) {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

r, err := testParseParams(req)
require.Nil(t, err, "unable to parse request")
require.NoError(t, err, "unable to parse request")
require.Equal(t, promQuery, r.Query)
}

Expand Down
2 changes: 1 addition & 1 deletion src/query/api/v1/handler/prometheus/native/list_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
)

var (
// ListTagsHTTPMethods are the HTTP methods used with this resource.
// ListTagsHTTPMethods are the HTTP methods for this handler.
ListTagsHTTPMethods = []string{http.MethodGet, http.MethodPost}
)

Expand Down
3 changes: 1 addition & 2 deletions src/query/api/v1/handler/prometheus/native/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ const (
)

var (
// PromReadHTTPMethods is the valid HTTP methods used with this
// resource.
// PromReadHTTPMethods are the HTTP methods for this handler.
PromReadHTTPMethods = []string{
http.MethodGet,
http.MethodPost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ const (
)

var (
// PromReadInstantHTTPMethods is the valid HTTP methods used with this
// resource.
// PromReadInstantHTTPMethods are the HTTP methods for this handler.
PromReadInstantHTTPMethods = []string{
http.MethodGet,
http.MethodPost,
Expand Down
5 changes: 3 additions & 2 deletions src/query/api/v1/handler/prometheus/remote/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ const (
)

var (
// PromSeriesMatchHTTPMethods are the HTTP methods used with this resource.
// PromSeriesMatchHTTPMethods are the HTTP methods for this handler.
PromSeriesMatchHTTPMethods = []string{http.MethodGet, http.MethodPost}
)

// PromSeriesMatchHandler represents a handler for prometheus series matcher endpoint.
// PromSeriesMatchHandler represents a handler for
// the prometheus series matcher endpoint.
type PromSeriesMatchHandler struct {
storage storage.Storage
tagOptions models.TagOptions
Expand Down
26 changes: 11 additions & 15 deletions src/query/api/v1/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,10 @@ func (h *Handler) RegisterRoutes() error {
).Methods(remote.TagValuesHTTPMethod)

// List tag endpoints
for _, method := range native.ListTagsHTTPMethods {
h.router.HandleFunc(native.ListTagsURL,
wrapped(native.NewListTagsHandler(h.storage, h.fetchOptionsBuilder,
nowFn, h.instrumentOpts)).ServeHTTP,
).Methods(method)
}
h.router.HandleFunc(native.ListTagsURL,
wrapped(native.NewListTagsHandler(h.storage, h.fetchOptionsBuilder,
nowFn, h.instrumentOpts)).ServeHTTP,
).Methods(native.ListTagsHTTPMethods...)

// Query parse endpoints
h.router.HandleFunc(native.PromParseURL,
Expand All @@ -269,18 +267,16 @@ func (h *Handler) RegisterRoutes() error {
).Methods(native.PromThresholdHTTPMethod)

// Series match endpoints
for _, method := range remote.PromSeriesMatchHTTPMethods {
h.router.HandleFunc(remote.PromSeriesMatchURL,
wrapped(remote.NewPromSeriesMatchHandler(h.storage,
h.tagOptions, h.fetchOptionsBuilder, h.instrumentOpts)).ServeHTTP,
).Methods(method)
}
h.router.HandleFunc(remote.PromSeriesMatchURL,
wrapped(remote.NewPromSeriesMatchHandler(h.storage,
h.tagOptions, h.fetchOptionsBuilder, h.instrumentOpts)).ServeHTTP,
).Methods(remote.PromSeriesMatchHTTPMethods...)

// Debug endpoints
h.router.HandleFunc(validator.PromDebugURL,
wrapped(validator.NewPromDebugHandler(nativePromReadHandler,
h.fetchOptionsBuilder, *h.config.LookbackDuration, h.instrumentOpts)).ServeHTTP,
).Methods(validator.PromDebugHTTPMethod)
wrapped(validator.NewPromDebugHandler(
nativePromReadHandler, h.fetchOptionsBuilder, *h.config.LookbackDuration,
h.instrumentOpts)).ServeHTTP).Methods(validator.PromDebugHTTPMethod)

// Graphite endpoints
h.router.HandleFunc(graphite.ReadURL,
Expand Down
Loading

0 comments on commit 8b7e574

Please sign in to comment.