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: Filter workflows by "Finished before" and "Created Since" via API. Fixes #13151 #13962

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Adrien-D
Copy link
Member

@Adrien-D Adrien-D commented Dec 2, 2024

Fixes #13151

Motivation

  • "Finished before" and "Created Since" are filtering workflows client-side so not all workflows are shown

Modifications

  • I implemented createdAfter and finishedBefore on server side similarly to UI: 3.5 missing name + name prefix filters for archived workflows #12161.
  • Remark on implementation: createdAfter is based on metadata.creationTimestamp which is stored as json so I needed to extract it is the request here
  • I didn't update the CLI as mentioned here by @agilgur5 as I never worked with the CLI and don't really know what to do. Can someone give me an insight on that or maybe we could split this in another issue to implement in the CLI later ?

Verification

  • Tests for ListWokflows function
  • Local testing on existing worflows
Initial workflows screenshot
Filtering created since screenshot
Filtering finished before screenshot
Filtering finished before screenshot

@Adrien-D Adrien-D marked this pull request as draft December 2, 2024 16:38
@Adrien-D Adrien-D force-pushed the filter-finished-before branch from 68410e6 to 1d278eb Compare December 2, 2024 16:46
@agilgur5
Copy link

agilgur5 commented Dec 2, 2024

  • I didn't update the CLI as mentioned here by @agilgur5 as I never worked with the CLI and don't really know what to do. Can someone give me an insight on that [...]?

The CLI is one of the most straightforward parts of the codebase (simpler than the UI and API, IMO, so should be easier than the parts you've already went through!); each command has a file (e.g. cmd/argo/commands/list.go) with around ~100-200 LoC each (depending on the number of flags).

You can see the existing client-side date filters in the list command in this block:

if flags.createdSince != "" && flags.finishedBefore != "" {
startTime, err := argotime.ParseSince(flags.createdSince)
if err != nil {
return nil, err
}
endTime, err := argotime.ParseSince(flags.finishedBefore)
if err != nil {
return nil, err
}
workflows = workflows.Filter(wfv1.WorkflowRanBetween(*startTime, *endTime))
} else {
if flags.createdSince != "" {
t, err := argotime.ParseSince(flags.createdSince)
if err != nil {
return nil, err
}
workflows = workflows.Filter(wfv1.WorkflowCreatedAfter(*t))
}
if flags.finishedBefore != "" {
t, err := argotime.ParseSince(flags.finishedBefore)
if err != nil {
return nil, err
}
workflows = workflows.Filter(wfv1.WorkflowFinishedBefore(*t))
}
}

Similar to the UI changes, those should be changed to be passed to the API instead of running client-side. The API call is made a few lines above in this block:

wfList, err := serviceClient.ListWorkflows(ctx, &workflowpkg.WorkflowListRequest{
Namespace: flags.namespace,
ListOptions: listOpts,
Fields: flags.displayFields(),
})

@@ -45,7 +45,7 @@ func (w *archivedWorkflowServer) ListArchivedWorkflows(ctx context.Context, req
listOptions = *req.ListOptions
}

options, err := sutils.BuildListOptions(listOptions, req.Namespace, req.NamePrefix, "")
options, err := sutils.BuildListOptions(listOptions, req.Namespace, req.NamePrefix, "", "", "")
Copy link

@agilgur5 agilgur5 Dec 2, 2024

Choose a reason for hiding this comment

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

this should work on archived workflows too -- per #13151 (comment), no longer having a server-side date filter available in the archived UI is the regression at the core of the issue (that stems from 3.5's archived/live UI unification / #11121).

that half is actually a fix to a 3.5 regression, not a feature (as the feature was unintentionally partially removed in 3.5. the other half that adds it for live workflows via the SQLiteDB is a new feature; though as filtering on both is now required, that can be seen as a prereq for the fix)

Note that there is existing SQL code for minStartedAt and maxStartedAt, which were used before #11840, that could be re-used (renaming in the API might be breaking though if they were exposed before?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed I missed that part for archived workflows, I'll change that and add tests.

For minStartedAt and maxStartedAt I didn't used those because I wasn't sure if they were still used somehow, and because they are not based on the same attribute so the query will be different. I can rename in the API if you tell me it's safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to update the code like this, but it seems that createdAfter and finishedBefore have no effect, not sure they are passed down to the API call. I spent few time trying to understand what's going on, do you have any idea ? I must miss something

var workflows wfv1.Workflows
createdAfter := ""
finishedBefore := ""
if flags.createdSince != "" {
	createdTime, err := argotime.ParseSince(flags.createdSince)
	if err != nil {
		return nil, err
	}
	createdAfter = createdTime.Format(time.RFC3339)
}
if flags.finishedBefore != "" {
	finishedTime, err := argotime.ParseSince(flags.createdSince)
	if err != nil {
		return nil, err
	}
	finishedBefore = finishedTime.Format(time.RFC3339)
}

for {
	log.WithField("listOpts", listOpts).Debug()
	wfList, err := serviceClient.ListWorkflows(ctx, &workflowpkg.WorkflowListRequest{
		Namespace:      flags.namespace,
		ListOptions:    listOpts,
		Fields:         flags.displayFields(),
		CreatedAfter:   createdAfter,
		FinishedBefore: finishedBefore,
	})
	if err != nil {
		return nil, err
	}
	workflows = append(workflows, wfList.Items...)
	if wfList.Continue == "" {
		break
	}
	listOpts.Continue = wfList.Continue
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@tooptoop4 what would be the best ? I'm a bit stuck with the CLI..!

Can we split this in another issue for later so we can merge this work already ?

Copy link
Contributor

Choose a reason for hiding this comment

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

🚢 📦

@agilgur5
Copy link

agilgur5 commented Dec 2, 2024

Verification

you'll want to test when both are set simultaneously as well since there are some edge cases with that, although now that these are in the API, that can be covered with back-end tests (i.e. instead of manual testing)

and ensure that with and without archived workflows works correctly

@tooptoop4
Copy link
Contributor

@agilgur5 join the band again 🎸

@agilgur5
Copy link

agilgur5 commented Dec 3, 2024

My original rationale and the original problems therein have not changed, so that won't happen, but if I'm tagged somewhere (as I was here) and it's related to something I wrote, I do try to be helpful as a general principle.
I didn't do an in-depth review, but as I was looking through anyway, I reviewed a small bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI: "Finished before" field only affects visible Workflows
3 participants