From 8fabbbf2de3d9c4f8ec976062d111ad5b36438fb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 7 Apr 2023 10:40:56 +0800 Subject: [PATCH] Fix: use step id to filter the log data and fix the regex (#5814) Signed-off-by: FogDong (cherry picked from commit 308093159fbcb26db03fec18e5babdc32a213e8b) Co-authored-by: FogDong --- references/cli/logs.go | 2 +- references/cli/workflow.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/references/cli/logs.go b/references/cli/logs.go index ba0c17634..0ec6363db 100644 --- a/references/cli/logs.go +++ b/references/cli/logs.go @@ -35,7 +35,7 @@ import ( "github.com/oam-dev/kubevela/references/appfile" ) -var re = regexp.MustCompile(`^.*?"([^"]*)"`) +var re = regexp.MustCompile(`"((?:[^"\\]|\\.)*)"`) // NewLogsCommand creates `logs` command to tail logs of application func NewLogsCommand(c common.Args, order string, ioStreams util.IOStreams) *cobra.Command { diff --git a/references/cli/workflow.go b/references/cli/workflow.go index 4e803a4bd..0b874d48a 100644 --- a/references/cli/workflow.go +++ b/references/cli/workflow.go @@ -254,6 +254,7 @@ type WorkflowArgs struct { Writer io.Writer Args common.Args StepName string + StepID string ErrMap map[string]string App *v1beta1.Application WorkflowRun *workflowv1alpha1.WorkflowRun @@ -412,7 +413,7 @@ func (w *WorkflowArgs) printStepLogs(ctx context.Context, cli client.Client, ioS return w.printResourceLogs(ctx, cli, ioStreams, []wfTypes.Resource{{ Namespace: types.DefaultKubeVelaNS, LabelSelector: w.ControllerLabels, - }}, []string{fmt.Sprintf(`step_name="%s"`, w.StepName), fmt.Sprintf("%s/%s", w.WorkflowInstance.Namespace, w.WorkflowInstance.Name), "cue logs"}) + }}, []string{fmt.Sprintf(`stepSessionID="%s"`, w.StepID), fmt.Sprintf("%s/%s", w.WorkflowInstance.Namespace, w.WorkflowInstance.Name), "cue logs"}) case logConfig.Source != nil: if len(logConfig.Source.Resources) > 0 { return w.printResourceLogs(ctx, cli, ioStreams, logConfig.Source.Resources, nil) @@ -468,6 +469,7 @@ func (w *WorkflowArgs) selectWorkflowStep(msg string) error { return fmt.Errorf("failed to select step %s: %w", unwrapStepName(w.StepName), err) } w.StepName = unwrapStepName(stepName) + w.StepID = unwrapStepID(stepName, w.WorkflowInstance) return nil }