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

Adding support for list rules API filter parameters #5417

Merged
merged 4 commits into from
Jun 28, 2023

Conversation

rajagopalanand
Copy link
Contributor

What this PR does:

This PR is introduces ability to filter rules in alignment with Prometheus

Checklist

  • [ X] Tests updated
  • [ X] Documentation added
  • [ X] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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()

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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 Show resolved Hide resolved
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())
Copy link
Contributor

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
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) {
Copy link
Contributor

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))
Copy link
Contributor

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"
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@alvinlin123 alvinlin123 changed the title List rules filter Adding support for list rules API filter parameters Jun 21, 2023
CHANGELOG.md Outdated Show resolved Hide resolved
pkg/ruler/ruler.go Outdated Show resolved Hide resolved
repeated string ruleGroupNames = 2;
repeated string files = 3;
string type = 4;
}
Copy link
Contributor

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?

Copy link
Contributor Author

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

@rajagopalanand rajagopalanand force-pushed the list-rules-filter branch 5 times, most recently from 1c0ceb2 to 209982f Compare June 26, 2023 00:02
@rajagopalanand rajagopalanand force-pushed the list-rules-filter branch 5 times, most recently from 2ecf6e5 to bbd2e23 Compare June 26, 2023 14:41
docs/contributing/how-integration-tests-work.md Outdated Show resolved Hide resolved
docs/contributing/how-integration-tests-work.md Outdated Show resolved Hide resolved
docs/contributing/how-integration-tests-work.md Outdated Show resolved Hide resolved
pkg/ruler/ruler_test.go Outdated Show resolved Hide resolved
@rajagopalanand rajagopalanand force-pushed the list-rules-filter branch 4 times, most recently from 9423eaf to c91ffeb Compare June 27, 2023 01:16
@rajagopalanand rajagopalanand requested a review from yeya24 June 27, 2023 02:39
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@rajagopalanand rajagopalanand force-pushed the list-rules-filter branch 2 times, most recently from c68e8fa to 7a23683 Compare June 28, 2023 20:12
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>
@alvinlin123 alvinlin123 merged commit 9e783e7 into cortexproject:master Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants