diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go index 0de13d432c..d5e20ccb93 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go @@ -183,13 +183,6 @@ func (input Input) templateVars() []TemplateVar { }, ) - // Add values from task template config as dynamic regexes (i.e. templates prefixed by .taskConfig) - for key, value := range input.TaskTemplate.GetConfig() { - if value != "" { - vars = append(vars, TemplateVar{MustCreateDynamicLogRegex(key), value}) - } - } - return vars } @@ -219,9 +212,20 @@ func (p TemplateLogPlugin) GetTaskLogs(input Input) (Output, error) { }) } + // Compile the potential dynamic log links + dynamicLogRegex := regexp.MustCompile(`(?i){{\s*.taskConfig[\.$]([a-zA-Z_]+)\s*}}`) + for _, dynamicLogLinkType := range getDynamicLogLinkTypes(input.TaskTemplate) { for _, dynamicTemplateURI := range p.DynamicTemplateURIs { if p.Name == dynamicLogLinkType { + for _, match := range dynamicLogRegex.FindAllStringSubmatch(dynamicTemplateURI, -1) { + if len(match) > 1 { + value := input.TaskTemplate.GetConfig()[match[1]] + if value != "" { + templateVars = append(templateVars, TemplateVar{MustCreateDynamicLogRegex(match[1]), value}) + } + } + } taskLogs = append(taskLogs, &core.TaskLog{ Uri: replaceAll(dynamicTemplateURI, templateVars), Name: p.DisplayName + input.LogName, diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go index a94af5e23f..dbbab6bb11 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go @@ -83,26 +83,6 @@ func Test_Input_templateVars(t *testing.T) { PodUnixFinishTime: 12345, } - flyinBase := Input{ - HostName: "my-host", - PodName: "my-pod", - PodUID: "my-pod-uid", - Namespace: "my-namespace", - ContainerName: "my-container", - ContainerID: "docker://containerID", - LogName: "main_logs", - PodRFC3339StartTime: "1970-01-01T01:02:03+01:00", - PodRFC3339FinishTime: "1970-01-01T04:25:45+01:00", - PodUnixStartTime: 123, - PodUnixFinishTime: 12345, - TaskTemplate: &core.TaskTemplate{ - Config: map[string]string{ - "link_type": "vscode", - "port": "1234", - }, - }, - } - tests := []struct { name string baseVars Input @@ -193,38 +173,6 @@ func Test_Input_templateVars(t *testing.T) { }, nil, }, - { - "flyin happy path", - flyinBase, - nil, - nil, - []TemplateVar{ - {testRegexes.Port, "1234"}, - }, - nil, - }, - { - "flyin and pod happy path", - flyinBase, - nil, - []TemplateVar{ - {defaultRegexes.LogName, "main_logs"}, - {defaultRegexes.PodName, "my-pod"}, - {defaultRegexes.PodUID, "my-pod-uid"}, - {defaultRegexes.Namespace, "my-namespace"}, - {defaultRegexes.ContainerName, "my-container"}, - {defaultRegexes.ContainerID, "containerID"}, - {defaultRegexes.Hostname, "my-host"}, - {defaultRegexes.PodRFC3339StartTime, "1970-01-01T01:02:03+01:00"}, - {defaultRegexes.PodRFC3339FinishTime, "1970-01-01T04:25:45+01:00"}, - {defaultRegexes.PodUnixStartTime, "123"}, - {defaultRegexes.PodUnixFinishTime, "12345"}, - {testRegexes.LinkType, "vscode"}, - {testRegexes.Port, "1234"}, - }, - nil, - nil, - }, { "pod with port not affected", podBase, @@ -530,33 +478,6 @@ func TestTemplateLogPlugin(t *testing.T) { }, }, }, - // { - // "flyin - default port", - // TemplateLogPlugin{ - // Name: "vscode", - // Scheme: TemplateSchemeDynamic, - // DynamicTemplateURIs: []TemplateURI{"vscode://flyin:{{ .taskConfig.port }}/{{ .podName }}"}, - // MessageFormat: core.TaskLog_JSON, - // }, - // args{ - // input: Input{ - // PodName: "my-pod-name", - // TaskTemplate: &core.TaskTemplate{ - // Config: map[string]string{ - // "link_type": "vscode", - // }, - // }, - // }, - // }, - // Output{ - // TaskLogs: []*core.TaskLog{ - // { - // Uri: "vscode://flyin:8080/my-pod-name", - // MessageFormat: core.TaskLog_JSON, - // }, - // }, - // }, - // }, { "flyin - no link_type in task template", TemplateLogPlugin{ @@ -574,6 +495,32 @@ func TestTemplateLogPlugin(t *testing.T) { TaskLogs: []*core.TaskLog{}, }, }, + { + "kubernetes", + TemplateLogPlugin{ + TemplateURIs: []TemplateURI{"https://dashboard.k8s.net/#!/log/{{.namespace}}/{{.podName}}/pod?namespace={{.namespace}}"}, + MessageFormat: core.TaskLog_JSON, + }, + args{ + input: Input{ + PodName: "flyteexamples-development-task-name", + PodUID: "pod-uid", + Namespace: "flyteexamples-development", + ContainerName: "ignore", + ContainerID: "ignore", + LogName: "main_logs", + PodRFC3339StartTime: "1970-01-01T01:02:03+01:00", + PodRFC3339FinishTime: "1970-01-01T04:25:45+01:00", + PodUnixStartTime: 123, + PodUnixFinishTime: 12345, + }, + }, + Output{TaskLogs: []*core.TaskLog{{ + Uri: "https://dashboard.k8s.net/#!/log/flyteexamples-development/flyteexamples-development-task-name/pod?namespace=flyteexamples-development", + MessageFormat: core.TaskLog_JSON, + Name: "main_logs", + }}}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {