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

Fix: fix the log for log data #754

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion pkg/server/domain/service/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"hash/fnv"
"io"
"regexp"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -61,6 +62,8 @@ const (
labelPipeline = "pipeline.oam.dev/name"
)

var re = regexp.MustCompile(`"((?:[^"\\]|\\.)*)"`)

// PipelineService is the interface for pipeline service
type PipelineService interface {
CreatePipeline(ctx context.Context, req apis.CreatePipelineRequest) (*apis.PipelineBase, error)
Expand Down Expand Up @@ -491,10 +494,23 @@ func (p pipelineRunServiceImpl) GetPipelineRunLog(ctx context.Context, pipelineR
var logs string
switch {
case logConfig.Data:
var id string
for _, s := range pipelineRun.Status.Steps {
if s.Name == step {
id = s.ID
break
}
for _, sub := range s.SubStepsStatus {
if sub.Name == step {
id = sub.ID
break
}
}
}
logs, err = getResourceLogs(ctx, p.KubeConfig, p.KubeClient, []wfTypes.Resource{{
Namespace: velatypes.DefaultKubeVelaNS,
LabelSelector: map[string]string{"app.kubernetes.io/name": "vela-workflow"},
}}, []string{fmt.Sprintf(`step_name="%s"`, step), fmt.Sprintf("%s/%s", project.GetNamespace(), pipelineRun.PipelineRunName), "cue logs"})
}}, []string{fmt.Sprintf(`stepSessionID="%s"`, id), fmt.Sprintf("%s/%s", project.GetNamespace(), pipelineRun.PipelineRunName), "cue logs"})
if err != nil {
return apis.GetPipelineRunLogResponse{}, err
}
Expand Down Expand Up @@ -684,6 +700,10 @@ func getResourceLogs(ctx context.Context, config *rest.Config, cli client.Client
}
}
if shouldPrint {
match := re.FindStringSubmatch(s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this change?

Copy link
Member Author

@FogDong FogDong Apr 12, 2023

Choose a reason for hiding this comment

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

The log data is formatted to string in the controller, with some suffix like stepSessionID=id, Name=name, the regex fill out the suffix and remain the data that users care about.

if len(match) > 1 {
s = strings.ReplaceAll(match[1], "\\n", "\n")
}
buf.WriteString(s)
}
}
Expand Down