From 920a2b1fa80d28bf6fe1b3e1cd107a2c0392b9d0 Mon Sep 17 00:00:00 2001 From: vraiyani Date: Thu, 4 Jan 2024 12:35:56 -0800 Subject: [PATCH] move pod start/end time to a common template vars pod start/end time is useful to have even with TemplateSchemeTaskExecution, to construct precise timerange in the URL. Signed-off-by: vraiyani --- .../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 750b1972df..a264f6429c 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go @@ -101,16 +101,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...) @@ -175,6 +165,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 f279707a3b..ccf6046d31 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, } tests := []struct { @@ -160,6 +164,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,