From 4de8fa31200070a9b20501910c1f4093f204a2f1 Mon Sep 17 00:00:00 2001 From: Viraj Raiyani <144381122+vraiyaninv@users.noreply.github.com> Date: Mon, 8 Jan 2024 13:00:53 -0800 Subject: [PATCH] move pod start/end time to a common template vars (#4676) pod start/end time is useful to have even with TemplateSchemeTaskExecution, to construct precise timerange in the URL. Signed-off-by: vraiyani Co-authored-by: David Espejo <82604841+davidmirror-ops@users.noreply.github.com> Co-authored-by: Kevin Su --- .../tasks/pluginmachinery/tasklog/template.go | 24 +++++++++++-------- .../pluginmachinery/tasklog/template_test.go | 12 ++++++++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go index ea5c5f373c9..3b319f291e1 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go @@ -113,16 +113,6 @@ func (input Input) templateVarsForScheme(scheme TemplateScheme) TemplateVars { TemplateVar{defaultRegexes.ContainerName, input.ContainerName}, TemplateVar{defaultRegexes.ContainerID, containerID}, TemplateVar{defaultRegexes.Hostname, input.HostName}, - TemplateVar{defaultRegexes.PodRFC3339StartTime, input.PodRFC3339StartTime}, - TemplateVar{defaultRegexes.PodRFC3339FinishTime, input.PodRFC3339FinishTime}, - TemplateVar{ - defaultRegexes.PodUnixStartTime, - strconv.FormatInt(input.PodUnixStartTime, 10), - }, - TemplateVar{ - defaultRegexes.PodUnixFinishTime, - strconv.FormatInt(input.PodUnixFinishTime, 10), - }, ) if gotExtraTemplateVars { vars = append(vars, input.ExtraTemplateVarsByScheme.Pod...) @@ -187,6 +177,20 @@ func (input Input) templateVarsForScheme(scheme TemplateScheme) TemplateVars { } } + vars = append( + vars, + TemplateVar{defaultRegexes.PodRFC3339StartTime, input.PodRFC3339StartTime}, + TemplateVar{defaultRegexes.PodRFC3339FinishTime, input.PodRFC3339FinishTime}, + TemplateVar{ + defaultRegexes.PodUnixStartTime, + strconv.FormatInt(input.PodUnixStartTime, 10), + }, + TemplateVar{ + defaultRegexes.PodUnixFinishTime, + strconv.FormatInt(input.PodUnixFinishTime, 10), + }, + ) + return vars } diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go index ad6eef25a36..eedc2e622c7 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go @@ -71,8 +71,12 @@ func Test_Input_templateVarsForScheme(t *testing.T) { PodUnixFinishTime: 12345, } taskExecutionBase := Input{ - LogName: "main_logs", - TaskExecutionID: dummyTaskExecID(), + LogName: "main_logs", + TaskExecutionID: dummyTaskExecID(), + PodRFC3339StartTime: "1970-01-01T01:02:03+01:00", + PodRFC3339FinishTime: "1970-01-01T04:25:45+01:00", + PodUnixStartTime: 123, + PodUnixFinishTime: 12345, } flyinBase := Input{ HostName: "my-host", @@ -178,6 +182,10 @@ func Test_Input_templateVarsForScheme(t *testing.T) { {defaultRegexes.ExecutionName, "my-execution-name"}, {defaultRegexes.ExecutionProject, "my-execution-project"}, {defaultRegexes.ExecutionDomain, "my-execution-domain"}, + {defaultRegexes.PodRFC3339StartTime, "1970-01-01T01:02:03+01:00"}, + {defaultRegexes.PodRFC3339FinishTime, "1970-01-01T04:25:45+01:00"}, + {defaultRegexes.PodUnixStartTime, "123"}, + {defaultRegexes.PodUnixFinishTime, "12345"}, }, nil, nil,