From acab9b58e4af21018911753668bdf18ef8625c91 Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Sun, 13 Nov 2022 11:15:06 -0500 Subject: [PATCH] feat: Support disable retrieval of label values for certain keys (#9999) --- docs/environment-variables.md | 13 +++++++------ .../workflowarchive/archived_workflow_server.go | 17 +++++++++++++++++ .../archived_workflow_server_test.go | 10 ++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/environment-variables.md b/docs/environment-variables.md index dbbc7bf138a9..d68a639525ed 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -148,9 +148,10 @@ data: ## Argo Server -| Name | Type | Default | Description | -|-------------------------|----------|---------|------------------------------------------------------------------------------------------------------------------------------| -| `FIRST_TIME_USER_MODAL` | `bool` | `true` | Show this modal. | -| `FEEDBACK_MODAL` | `bool` | `true` | Show this modal. | -| `NEW_VERSION_MODAL` | `bool` | `true` | Show this modal. | -| `POD_NAMES` | `string` | `v2` | Whether to have pod names contain the template name (v2) or be the node id (v1) - should be set the same for Controller | +| Name | Type | Default | Description | +|--------------------------------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------| +| `DISABLE_VALUE_LIST_RETRIEVAL_KEY_PATTERN` | `string` | `""` | Disable the retrieval of the list of label values for keys based on this regular expression. | +| `FIRST_TIME_USER_MODAL` | `bool` | `true` | Show this modal. | +| `FEEDBACK_MODAL` | `bool` | `true` | Show this modal. | +| `NEW_VERSION_MODAL` | `bool` | `true` | Show this modal. | +| `POD_NAMES` | `string` | `v2` | Whether to have pod names contain the template name (v2) or be the node id (v1) - should be set the same for Controller | diff --git a/server/workflowarchive/archived_workflow_server.go b/server/workflowarchive/archived_workflow_server.go index c5e07f2c712f..54a088a262ee 100644 --- a/server/workflowarchive/archived_workflow_server.go +++ b/server/workflowarchive/archived_workflow_server.go @@ -3,6 +3,8 @@ package workflowarchive import ( "context" "fmt" + "os" + "regexp" "sort" "strconv" "strings" @@ -24,6 +26,8 @@ import ( "github.com/argoproj/argo-workflows/v3/workflow/util" ) +const disableValueListRetrievalKeyPattern = "DISABLE_VALUE_LIST_RETRIEVAL_KEY_PATTERN" + type archivedWorkflowServer struct { wfArchive sqldb.WorkflowArchive } @@ -184,6 +188,15 @@ func (w *archivedWorkflowServer) ListArchivedWorkflowLabelKeys(ctx context.Conte return labelkeys, nil } +func matchLabelKeyPattern(key string) bool { + pattern, _ := os.LookupEnv(disableValueListRetrievalKeyPattern) + if pattern == "" { + return false + } + match, _ := regexp.MatchString(pattern, key) + return match +} + func (w *archivedWorkflowServer) ListArchivedWorkflowLabelValues(ctx context.Context, req *workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest) (*wfv1.LabelValues, error) { options := req.ListOptions @@ -202,6 +215,10 @@ func (w *archivedWorkflowServer) ListArchivedWorkflowLabelValues(ctx context.Con } else { return nil, fmt.Errorf("operation %v is not supported", requirement.Operator()) } + if matchLabelKeyPattern(key) { + log.WithFields(log.Fields{"labelKey": key}).Info("Skipping retrieving the list of values for label key") + return &wfv1.LabelValues{Items: []string{}}, nil + } labels, err := w.wfArchive.ListWorkflowsLabelValues(key) if err != nil { diff --git a/server/workflowarchive/archived_workflow_server_test.go b/server/workflowarchive/archived_workflow_server_test.go index 387bebd28a4c..5c86e24e5c1e 100644 --- a/server/workflowarchive/archived_workflow_server_test.go +++ b/server/workflowarchive/archived_workflow_server_test.go @@ -2,6 +2,7 @@ package workflowarchive import ( "context" + "os" "testing" "time" @@ -190,6 +191,15 @@ func Test_archivedWorkflowServer(t *testing.T) { resp, err := w.ListArchivedWorkflowLabelValues(ctx, &workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest{ListOptions: &metav1.ListOptions{LabelSelector: "my-key"}}) assert.NoError(t, err) assert.Len(t, resp.Items, 2) + + assert.False(t, matchLabelKeyPattern("my-key")) + _ = os.Setenv(disableValueListRetrievalKeyPattern, "my-key") + assert.True(t, matchLabelKeyPattern("my-key")) + assert.False(t, matchLabelKeyPattern("wrong key")) + resp, err = w.ListArchivedWorkflowLabelValues(ctx, &workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest{ListOptions: &metav1.ListOptions{LabelSelector: "my-key"}}) + assert.NoError(t, err) + assert.Len(t, resp.Items, 0) + _ = os.Unsetenv(disableValueListRetrievalKeyPattern) }) t.Run("RetryArchivedWorkflow", func(t *testing.T) { _, err := w.RetryArchivedWorkflow(ctx, &workflowarchivepkg.RetryArchivedWorkflowRequest{Uid: "failed-uid"})