Skip to content
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

[query] Cleaning up nits from #2049 and #2055 #2056

Merged
merged 3 commits into from
Dec 10, 2019
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
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 @@ -260,12 +260,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 @@ -276,18 +274,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
2 changes: 1 addition & 1 deletion src/query/block/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func (b *ucContainerBlock) MultiSeriesIter(
batch, err := bl.MultiSeriesIter(concurrency)
if err != nil {
// NB: do not have to set the iterator error here, since not all
// contained blocks necessarily allow mutli series iteration.
// contained blocks necessarily allow multi series iteration.
return nil, err
}

Expand Down
Loading