From 66c6b29fb0666323d5d145a2ca1d31deacf207eb Mon Sep 17 00:00:00 2001 From: Fabio Graetz Date: Fri, 8 Mar 2024 09:12:49 +0000 Subject: [PATCH] Hide certain logs once finished Signed-off-by: Fabio Graetz --- .../go/tasks/pluginmachinery/core/phase.go | 24 +++++++++++++++++++ .../tasks/pluginmachinery/tasklog/plugin.go | 1 + .../tasks/pluginmachinery/tasklog/template.go | 1 + 3 files changed, 26 insertions(+) diff --git a/flyteplugins/go/tasks/pluginmachinery/core/phase.go b/flyteplugins/go/tasks/pluginmachinery/core/phase.go index 69fbcba3a8..41635464f1 100644 --- a/flyteplugins/go/tasks/pluginmachinery/core/phase.go +++ b/flyteplugins/go/tasks/pluginmachinery/core/phase.go @@ -249,6 +249,7 @@ func PhaseInfoInitializing(t time.Time, version uint32, reason string, info *Tas } func phaseInfoFailed(p Phase, err *core.ExecutionError, info *TaskInfo, cleanupOnFailure bool) PhaseInfo { + HideLogsOnceFinished(info) if err == nil { err = &core.ExecutionError{ Code: "Unknown", @@ -266,7 +267,30 @@ func PhaseInfoRunning(version uint32, info *TaskInfo) PhaseInfo { return phaseInfo(PhaseRunning, version, nil, info, false) } +func HideLogsOnceFinished(info *TaskInfo) { + if info != nil && info.Logs != nil { + logs := info.Logs + // Delete the logs for which hideOnceFinished is true + info.Logs = make([]*core.TaskLog, 0, len(logs)) + for _, l := range logs { + if !l.HideOnceFinished { + info.Logs = append(info.Logs, l) + } + } + } +} + func PhaseInfoSuccess(info *TaskInfo) PhaseInfo { + if info != nil && info.Logs != nil { + logs := info.Logs + // Delete the logs for which hideOnceFinished is true + info.Logs = make([]*core.TaskLog, 0, len(logs)) + for _, l := range logs { + if !l.HideOnceFinished { + info.Logs = append(info.Logs, l) + } + } + } return phaseInfo(PhaseSuccess, DefaultPhaseVersion, nil, info, false) } diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go index fe81fe7509..143cf02e43 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go @@ -63,4 +63,5 @@ type TemplateLogPlugin struct { // Deprecated: Please, do not use DeprecatedScheme TemplateScheme `json:"scheme" pflag:",Templating scheme to use. Supported values are Pod and TaskExecution."` ShowWhilePending bool `json:"showWhilePending" pflag:",If true, the log link will be shown even if the task is in a pending state."` + HideOnceFinished bool `json:"hideOnceFinished" pflag:",If true, the log link will be hidden once the task has finished."` } diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go index 5e81b8dc39..19aae6ba7c 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go @@ -204,6 +204,7 @@ func (p TemplateLogPlugin) GetTaskLogs(input Input) (Output, error) { Name: p.DisplayName + input.LogName, MessageFormat: p.MessageFormat, ShowWhilePending: p.ShowWhilePending, + HideOnceFinished: p.HideOnceFinished, }) }