-
Notifications
You must be signed in to change notification settings - Fork 803
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
Adding support for list rules API filter parameters #5417
Adding support for list rules API filter parameters #5417
Conversation
8c27b9e
to
6f570e0
Compare
pkg/ruler/api.go
Outdated
@@ -119,6 +125,26 @@ func respondError(logger log.Logger, w http.ResponseWriter, msg string) { | |||
} | |||
} | |||
|
|||
func respondClientError(logger log.Logger, w http.ResponseWriter, msg string) { |
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.
what's the different of this function with respondError?
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.
That function returns 400 vs respondError returns 500. I added the function to be consistent with respondAccepted()
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.
respondAccepted() has more differences in terms of the response message. respondClientError() only difference is the status code being returned.
What about adding a status code parameter to respondError() ?
I don't think it's a good idea to move towards having dedicated methods for each response code. It's adding even more code duplication for little benefit.
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.
Changed this to return 400 and changed to return bad request/data.
CHANGELOG.md
Outdated
@@ -30,6 +30,7 @@ | |||
* [ENHANCEMENT] Store Gateway: Add new metrics `cortex_bucket_store_sent_chunk_size_bytes`, `cortex_bucket_store_postings_size_bytes` and `cortex_bucket_store_empty_postings_total`. #5397 | |||
* [ENHANCEMENT] Add jitter to lifecycler heartbeat. #5404 | |||
* [ENHANCEMENT] Store Gateway: Add config `estimated_max_series_size_bytes` and `estimated_max_chunk_size_bytes` to address data overfetch. #5401 | |||
* [ENHANCEMENT] Ruler: Support for filtering rules. #5417 |
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.
We should be more precise and mention it's for API
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.
Done
pkg/ruler/api.go
Outdated
func respondClientError(logger log.Logger, w http.ResponseWriter, msg string) { | ||
b, err := json.Marshal(&response{ | ||
Status: "error", | ||
ErrorType: v1.ErrServer, |
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.
If this function returns 4xx, then shouldn't the ErrorType be v1.ErrClient
?
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.
Changed this to v1.ErrBadData
pkg/ruler/api.go
Outdated
@@ -145,8 +171,27 @@ func (a *API) PrometheusRules(w http.ResponseWriter, req *http.Request) { | |||
return | |||
} | |||
|
|||
if err := req.ParseForm(); err != nil { | |||
level.Error(logger).Log("msg", "error parsing form/query params", "err", err) | |||
respondClientError(logger, w, err.Error()) |
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.
Are you sure req.ParseForm()
's error translate to client error? From quick look of the req.ParseForm()
's implementation, it doesn't look like client error is the right choice here.
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.
Changed this to respondBadRequest() as that is more appropriate
pkg/ruler/api.go
Outdated
@@ -119,6 +125,26 @@ func respondError(logger log.Logger, w http.ResponseWriter, msg string) { | |||
} | |||
} | |||
|
|||
func respondClientError(logger log.Logger, w http.ResponseWriter, msg string) { |
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.
respondAccepted() has more differences in terms of the response message. respondClientError() only difference is the status code being returned.
What about adding a status code parameter to respondError() ?
I don't think it's a good idea to move towards having dedicated methods for each response code. It's adding even more code duplication for little benefit.
pkg/ruler/api.go
Outdated
|
||
typ := strings.ToLower(req.URL.Query().Get("type")) | ||
if typ != "" && typ != AlertingRuleFilter && typ != RecordingRuleFilter { | ||
respondClientError(logger, w, fmt.Sprintf("not supported value %q", typ)) |
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.
"value" can be a bit vague, especially if the user provides additional parameters.
How about "unsupported rule type: %q"
?
pkg/ruler/api.go
Outdated
@@ -99,6 +100,11 @@ type recordingRule struct { | |||
EvaluationTime float64 `json:"evaluationTime"` | |||
} | |||
|
|||
const ( | |||
AlertingRuleFilter string = "alert" |
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.
maybe move this into ruler.go? as ruler need to use this const as well
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.
done
4db84b5
to
b420fb3
Compare
repeated string ruleGroupNames = 2; | ||
repeated string files = 3; | ||
string type = 4; | ||
} |
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.
Will this cause compatibility issue? During rollout, protocol changes and new/old ruler cannot communicate with each other?
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.
If the clients do not send any filters, then the results are consistent during deployment. However, if the clients start sending filters during deployment, the results are inconsistent until the deployment is complete. This is because old ruler does not filter and the new one will
1c0ceb2
to
209982f
Compare
2ecf6e5
to
bbd2e23
Compare
9423eaf
to
c91ffeb
Compare
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.
Thanks!
c68e8fa
to
7a23683
Compare
Signed-off-by: Anand Rajagopal <anrajag@amazon.com>
Signed-off-by: Anand Rajagopal <anrajag@amazon.com>
Signed-off-by: Anand Rajagopal <anrajag@amazon.com>
Signed-off-by: Anand Rajagopal <anrajag@amazon.com>
7a23683
to
0e39bd9
Compare
What this PR does:
This PR is introduces ability to filter rules in alignment with Prometheus
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]