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

feat(api): filter with expression language #682

Closed
wants to merge 11 commits into from
Closed

Conversation

hekike
Copy link
Contributor

@hekike hekike commented Mar 11, 2024

Example

http://localhost:8888/api/v1/meters/api_requests_total/query?windowSize=HOUR&groupBy=route&groupBy=subject&groupBy=method&filter[subject]={"$in":["customer-1","customer-2"]}&filter[route]={"$eq":"/hello"}&filter[method]={"$nin":["POST","DELETE"]}`

One of the biggest values of JSON-based filters is that we can validate them with OpenAPI. However, for some reason, this validation doesn't work for query params. It works if it's a POST payload.

@hekike hekike requested a review from tothandras March 11, 2024 01:59
@hekike hekike marked this pull request as draft March 11, 2024 02:00
@hekike hekike added area/api release-note/feature Release note: Exciting New Features labels Mar 11, 2024
@hekike hekike changed the title Feat/filter expr poc feat(api): filter with expression language Mar 11, 2024
@@ -160,9 +213,18 @@ func (resp QueryMeterResponse) Render(_ http.ResponseWriter, _ *http.Request) er
}

// RenderCSV renders the response as CSV.
func (resp QueryMeterResponse) RenderCSV(w http.ResponseWriter, r *http.Request, groupByKeys []string, meterIDOrSlug string) {
func (resp QueryMeterResponse) RenderCSV(w http.ResponseWriter, r *http.Request, _groupByKeys []string, meterIDOrSlug string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (resp QueryMeterResponse) RenderCSV(w http.ResponseWriter, r *http.Request, _groupByKeys []string, meterIDOrSlug string) {
func (resp QueryMeterResponse) RenderCSV(w http.ResponseWriter, r *http.Request, groupByKeys []string, meterIDOrSlug string) {

records := [][]string{}

// Filter out the subject from the group by keys
groupByKeys := []string{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
groupByKeys := []string{}
dataGroupByKeys := make([]string, 0, len(groupByKeys))

The slice will have at most the same length as groupByKeys

if k == "subject" {
continue
}
groupByKeys = append(groupByKeys, k)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
groupByKeys = append(groupByKeys, k)
dataGroupByKeys = append(dataGroupByKeys, k)

Copy link

Choose a reason for hiding this comment

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

There's a typo in the file name :) filLter.go

@GAlexIHU
Copy link
Contributor

Closing due to inactivity

@GAlexIHU GAlexIHU closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants