-
Notifications
You must be signed in to change notification settings - Fork 454
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] Fix /m3query returning 500 on invalid query argument #2916
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,14 @@ type urlTest struct { | |
func TestInvalidInstantQueryReturns400(t *testing.T) { | ||
coord := singleDBNodeDockerResources.Coordinator() | ||
|
||
instantQueryBadRequestTest := []urlTest{ | ||
urlPrefix := []string{"", "prometheus/", "m3query/"} | ||
|
||
instantQueryBadRequestTest := addPrefixes(urlPrefix, []urlTest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: make the name plural. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{"missing query", queryURL("query", "")}, | ||
{"invalid query", queryURL("query", "@!")}, | ||
{"invalid time", queryURL("time", "INVALID")}, | ||
{"invalid timeout", queryURL("timeout", "INVALID")}, | ||
} | ||
}) | ||
|
||
for _, tt := range instantQueryBadRequestTest { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
@@ -55,7 +57,9 @@ func TestInvalidInstantQueryReturns400(t *testing.T) { | |
func TestInvalidRangeQueryReturns400(t *testing.T) { | ||
coord := singleDBNodeDockerResources.Coordinator() | ||
|
||
queryBadRequestTest := []urlTest{ | ||
urlPrefix := []string{"", "prometheus/", "m3query/"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: make the name plural. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
queryBadRequestTest := addPrefixes(urlPrefix, []urlTest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: make the name plural. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these two tests only differ by their test table contents and so they can be safely merged. Having two separate test methods made me try figuring out what is the principal difference between them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{"missing query", queryRangeURL("query", "")}, | ||
{"invalid query", queryRangeURL("query", "@!")}, | ||
{"missing start", queryRangeURL("start", "")}, | ||
|
@@ -65,7 +69,7 @@ func TestInvalidRangeQueryReturns400(t *testing.T) { | |
{"missing step", queryRangeURL("step", "")}, | ||
{"invalid step", queryRangeURL("step", "INVALID")}, | ||
{"invalid timeout", queryRangeURL("timeout", "INVALID")}, | ||
} | ||
}) | ||
|
||
for _, tt := range queryBadRequestTest { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
@@ -74,6 +78,19 @@ func TestInvalidRangeQueryReturns400(t *testing.T) { | |
} | ||
} | ||
|
||
func addPrefixes(prefixes []string, tests []urlTest) []urlTest { | ||
res := make([]urlTest, 0) | ||
for _, prefix := range prefixes { | ||
for _, t := range tests { | ||
res = append(res, urlTest{ | ||
fmt.Sprintf("%v %v", prefix, t.name), | ||
fmt.Sprintf("%v%v", prefix, t.url), | ||
}) | ||
} | ||
} | ||
return res | ||
} | ||
|
||
func queryURL(key, value string) string { | ||
params := map[string]string{ | ||
"query": "foo", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: make the name plural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
661c9ae#diff-391a291f1f91098bc731847f8843207e5327fe87a52a4599a45ac0cf4c5732e7R39