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

Storage: Add support for sortBy selector #80680

Merged
merged 11 commits into from
Feb 7, 2024
Merged

Conversation

DanCech
Copy link
Collaborator

@DanCech DanCech commented Jan 16, 2024

This PR adds support for sorting lists by specifying a field selector like grafana.app/sortBy="title", including support for paging.

I opted to implement paging via offset rather than uids because of the complexity involved in building where clauses when sorting by multiple dimensions (e.g. for grafana.app/sortBy=a;b desc the WHERE clause would need to be (a > ? OR (a = ? AND (b < ? OR (b = ? AND uid > ?)))) vs the simplicity of an offset-based approach.

The other change from our standard semantics is that when specifying multiple columns the separator is a semicolon rather than a comma, using a comma resulted in an error from the k8s field selector parser like:

Error from server (BadRequest): Unable to find "playlist.grafana.app/v0alpha1, Resource=playlists" that match label selector "", field selector "grafana.app/sortBy=created_at desc,name asc": invalid selector: 'grafana.app/sortBy=created_at desc,name asc'; can't understand 'name asc'

This appears to be due to the chained selectors syntax which supports sending multiple field selector expressions separated with commas.

Will take this out of draft status once I've had a chance to add tests.

@DanCech DanCech requested a review from a team as a code owner January 16, 2024 22:50
@grafana-delivery-bot grafana-delivery-bot bot added this to the 10.4.x milestone Jan 16, 2024
@DanCech DanCech changed the title Storage: add support for sortBy field selector DRAFT Storage: add support for sortBy field selector Jan 16, 2024
@ryantxu
Copy link
Member

ryantxu commented Jan 16, 2024

https://clusterpedia.io/docs/usage/search/multi-cluster/#sorting-by-multiple-fields -- is an interesting alternative. In that model, we would support something like:

-l "search.grafana.app/orderby in (modified desc, title)"

I like they this more explicitly flips things to a "search" context

+1 for offset -- i can't think of a better option, the downside is if things get modified or deleted between page requests 😬

@DanCech
Copy link
Collaborator Author

DanCech commented Jan 17, 2024

I would be absolutely fine with switching to label selectors which would give us more flexibility (and more concise kubectl cli syntax), if we do that would you want to keep folder as a field selector or just flip everything back to label selectors?

@DanCech DanCech requested a review from a team as a code owner January 19, 2024 16:08
@DanCech DanCech requested review from papagian, suntala and idafurjes and removed request for a team January 19, 2024 16:08
@DanCech
Copy link
Collaborator Author

DanCech commented Jan 19, 2024

tests are now working, but the sqlite "database table is locked" issue is popping up when running migrations against sqlite.

@DanCech
Copy link
Collaborator Author

DanCech commented Jan 23, 2024 via email

Copy link
Contributor

@suntala suntala left a comment

Choose a reason for hiding this comment

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

Added a couple of small comments and a question. I plan on looking into the code some more later on.

@DanCech DanCech changed the title DRAFT Storage: add support for sortBy field selector Storage: add support for sortBy field selector Jan 29, 2024
@DanCech DanCech changed the title Storage: add support for sortBy field selector Storage: Add support for sortBy selector Jan 29, 2024
Copy link
Member

@ryantxu ryantxu left a comment

Choose a reason for hiding this comment

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

🎉

@DanCech DanCech merged commit 1f14617 into main Feb 7, 2024
12 checks passed
@DanCech DanCech deleted the unified-storage-sort-by branch February 7, 2024 20:05
Ukochka pushed a commit that referenced this pull request Feb 14, 2024
* add support for sortBy field selector

* use label selectors instead of field selectors

* set entity_labels on create & update

* make entity server integration tests work

* test fixes

* be more consistent with handling of empty body, meta or status

* workaround for database is locked errors during migration

* fix double import of sqlite3

* rename functions and tidy up

* refactor update

* disable integration tests until we can fix the database locking issue
@aangelisc aangelisc modified the milestones: 10.4.x, 10.4.0 Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants