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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions persist/sqldb/selector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sqldb

import (
"time"

"github.com/upper/db/v4"

"github.com/argoproj/argo-workflows/v3/server/utils"
Expand Down Expand Up @@ -53,6 +55,12 @@ func BuildWorkflowSelector(in string, inArgs []any, tableName, labelTableName st
clauses = append(clauses, db.Raw("name like ?", options.Name+"%"))
}
}
if !options.CreatedAfter.IsZero() {
clauses = append(clauses, db.Raw("json_extract(workflow, '$.metadata.creationTimestamp') >= ?", options.CreatedAfter.Format(time.RFC3339)))
}
if !options.FinishedBefore.IsZero() {
clauses = append(clauses, db.Raw("finishedat <= ?", options.FinishedBefore))
}
if options.NamePrefix != "" {
clauses = append(clauses, db.Raw("name like ?", options.NamePrefix+"%"))
}
Expand Down
288 changes: 196 additions & 92 deletions pkg/apiclient/workflow/workflow.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pkg/apiclient/workflow/workflow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ message WorkflowListRequest {
string fields = 3;
// Filter type used for name filtering. Exact | Contains | Prefix. Default to Exact
string nameFilter = 4;
string createdAfter = 5;
string finishedBefore = 6;
}

message WorkflowResubmitRequest {
Expand Down
8 changes: 6 additions & 2 deletions sdks/java/client/docs/WorkflowServiceApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions sdks/python/client/argo_workflows/api/workflow_service_api.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion sdks/python/client/docs/WorkflowServiceApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 26 additions & 8 deletions server/utils/list_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import (
)

type ListOptions struct {
Namespace, Name string
NamePrefix, NameFilter string
MinStartedAt, MaxStartedAt time.Time
LabelRequirements labels.Requirements
Limit, Offset int
ShowRemainingItemCount bool
StartedAtAscending bool
Namespace, Name string
NamePrefix, NameFilter string
MinStartedAt, MaxStartedAt time.Time
CreatedAfter, FinishedBefore time.Time
LabelRequirements labels.Requirements
Limit, Offset int
ShowRemainingItemCount bool
StartedAtAscending bool
}

func (l ListOptions) WithLimit(limit int) ListOptions {
Expand Down Expand Up @@ -52,7 +53,7 @@ func (l ListOptions) WithStartedAtAscending(ascending bool) ListOptions {
return l
}

func BuildListOptions(options metav1.ListOptions, ns, namePrefix, nameFilter string) (ListOptions, error) {
func BuildListOptions(options metav1.ListOptions, ns, namePrefix, nameFilter, createdAfter, finishedBefore string) (ListOptions, error) {
if options.Continue == "" {
options.Continue = "0"
}
Expand All @@ -75,6 +76,21 @@ func BuildListOptions(options metav1.ListOptions, ns, namePrefix, nameFilter str
name := ""
minStartedAt := time.Time{}
maxStartedAt := time.Time{}
createdAfterTime := time.Time{}
finishedBeforeTime := time.Time{}

if createdAfter != "" {
createdAfterTime, err = time.Parse(time.RFC3339, createdAfter)
if err != nil {
return ListOptions{}, ToStatusError(err, codes.Internal)
}
}
if finishedBefore != "" {
finishedBeforeTime, err = time.Parse(time.RFC3339, finishedBefore)
if err != nil {
return ListOptions{}, ToStatusError(err, codes.Internal)
}
}
showRemainingItemCount := false
for _, selector := range strings.Split(options.FieldSelector, ",") {
if len(selector) == 0 {
Expand Down Expand Up @@ -126,6 +142,8 @@ func BuildListOptions(options metav1.ListOptions, ns, namePrefix, nameFilter str
Name: name,
NamePrefix: namePrefix,
NameFilter: nameFilter,
CreatedAfter: createdAfterTime,
FinishedBefore: finishedBeforeTime,
MinStartedAt: minStartedAt,
MaxStartedAt: maxStartedAt,
LabelRequirements: requirements,
Expand Down
Loading
Loading