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/ui) Sort promotions lexicographically #1949

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

webstradev
Copy link
Contributor

Closes #1930

This PR handles sorting of promotions in two places.

In the api call we simply sort on the Name which contains a prefix that is always the same for promotions you want to sort followed by a ULID. I have also adjusted the tests to test for this sorting instead of on creation time. I do this by simply creating for ULID and using them in the tests.

In te UI we have slightly more complex sorting logic and I'm not certain we want that in the API, so I have essentially made the same change in the sortPromotions function. Instead of sorting on create time we sort simply on name. I didin't use ULIDs here in the tests because it doesn't make sense to me to die the frontend to that implementation, so I just used lexicographically sortable strings in the ui tests as well.

Signed-off-by: Erik Westra <e.s.westra.95@gmail.com>
…reation time.

Signed-off-by: Erik Westra <e.s.westra.95@gmail.com>
@webstradev webstradev requested a review from a team as a code owner May 3, 2024 22:13
Copy link

netlify bot commented May 3, 2024

Deploy Preview for docs-kargo-akuity-io ready!

Name Link
🔨 Latest commit 503ed79
🔍 Latest deploy log https://app.netlify.com/sites/docs-kargo-akuity-io/deploys/6635617436cd2c00084201a1
😎 Deploy Preview https://deploy-preview-1949.kargo.akuity.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@webstradev webstradev changed the title feat(api/ui) Sort promotions lexicographically feat: (api/ui) Sort promotions lexicographically May 3, 2024
Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.25%. Comparing base (ba3601b) to head (503ed79).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1949      +/-   ##
==========================================
+ Coverage   46.20%   46.25%   +0.04%     
==========================================
  Files         235      235              
  Lines       15990    16004      +14     
==========================================
+ Hits         7388     7402      +14     
+ Misses       8244     8242       -2     
- Partials      358      360       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@krancour
Copy link
Member

krancour commented May 3, 2024

In te UI we have slightly more complex sorting logic

Ah... I think when commenting on #1930, I failed to realize that both the API server and UI were sorting these.

I would prefer the sorting to be done only on the back end, but I will ask @rbreeze to also weigh in on this opinion in case there are UI-specific reasons I am unaware of for sorting any differently than what the API server will return.

@webstradev
Copy link
Contributor Author

In te UI we have slightly more complex sorting logic

Ah... I think when commenting on #1930, I failed to realize that both the API server and UI were sorting these.

I would prefer the sorting to be done only on the back end, but I will ask @rbreeze to also weigh in on this opinion in case there are UI-specific reasons I am unaware of for sorting any differently than what the API server will return.

All good, let me know if you want me to move it completely from UI to the API. I'm pretty sure it should be easy enough, but just to confirm they are currently different.

Backend only sorts on creationTime
Frontend Sorts on a combination of phase and creation time

@krancour
Copy link
Member

krancour commented May 3, 2024

Frontend Sorts on a combination of phase and creation time

@rbreeze was this intended? Sorting by time should be adequate, right?

In case it's not clear... promos are always processed in the order they were created.

@webstradev
Copy link
Contributor Author

Just for your clarity @krancour
This test (from current main) shows how we sort in the frontend currently:

const testPromotions = [
  running1,
  pending2,
  running3,
  pending4,
  succeeded5,
  failed6,
  unknown7,
  running8,
  pending9,
  running10,
  pending11,
  succeeded12,
  errored13,
  unknown14
];

const orderedPromotions = [
  running10,
  running8,
  running3,
  running1,
  pending11,
  pending9,
  pending4,
  pending2,
  unknown14,
  errored13,
  succeeded12,
  unknown7,
  failed6,
  succeeded5
];

@hiddeco
Copy link
Contributor

hiddeco commented May 4, 2024

The way I feel you want them sorted in the UI (and arguably the API), is a bit awkward.

For things which are non-terminal (Running and Pending), you want them to be from oldest -> newest. Because that's how the queue is going through them.

For things which are terminal however (Succeeded, Errored, etc.), you want them from newest -> oldest. Because that gives you the latest Promotion which has been processed first.

Non-terminal should then go before terminal, to ensure the user has a clear view of what's being worked on.

I already wrote something which handles this type of ordering (in Go) in #1919.

@webstradev
Copy link
Contributor Author

So are we moving this completely from frontend to backend then and keeping all the sorting logic in the backend?

@hiddeco
Copy link
Contributor

hiddeco commented May 4, 2024

I think we would at least want it in the API, and for the frontend we have to await further instructions from @rbreeze.

@rbreeze
Copy link
Contributor

rbreeze commented May 6, 2024

I have no opposition to sorting lexicographically on the backend, and agree that we should rely on the backend to sort... with one caveat. The background for why the UI does sorting as it does can be found in this PR and the linked issue: #1314

To summarize, currently running promotions were often buried on the last page where they were difficult to find. Hence the phase creeping into the sorting logic. I don't think this PR will affect that logic.

@webstradev
Copy link
Contributor Author

I have no opposition to sorting lexicographically on the backend, and agree that we should rely on the backend to sort... with one caveat. The background for why the UI does sorting as it does can be found in this PR and the linked issue: #1314

To summarize, currently running promotions were often buried on the last page where they were difficult to find. Hence the phase creeping into the sorting logic. I don't think this PR will affect that logic.

Well the PR as it is currently I think is mergeable, but the suggestion was to move the sorting logic completely to the backend, and removing sorting all together from the frontend (whilst keeping the same sorting logic as describe in #1314)

Happy to change it to that if everyone is in agreement.

@rbreeze
Copy link
Contributor

rbreeze commented May 6, 2024

@webstradev Got it, makes sense. I am okay with either way. IMO the frontend sorting logic to surface currently running promotions is more of a UI feature than a "sort". So it comes down to whether we think this surfacing of running promos should happen at the API level (and therefore change the behavior of the CLI). WDYT @hiddeco @krancour ?

@hiddeco
Copy link
Contributor

hiddeco commented May 6, 2024

As the phase is also being shown for kargo get promotions, I feel the ordering I suggested in #1949 (comment) makes sense for both the frontend and the CLI (which arguably is a "TUI").

@krancour
Copy link
Member

Also agree with @hiddeco's suggestions in #1949 (comment)

@krancour
Copy link
Member

We're looking at a v0.7.0 release toward the end of this week. @webstradev should we defer this to v0.8.0?

@webstradev
Copy link
Contributor Author

We're looking at a v0.7.0 release toward the end of this week. @webstradev should we defer this to v0.8.0?

yeah sorry I've been quite busy and I've got some holidays coming up. So either defer or happy to have someone else take it over and use what I wrote so far.

@krancour krancour modified the milestones: v0.7.0, v0.8.0 May 29, 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.

Promotions should be sorted lexicographically
4 participants