diff --git a/flyteplugins/go/tasks/logs/logging_utils.go b/flyteplugins/go/tasks/logs/logging_utils.go index 44ae459f34..4a34419808 100644 --- a/flyteplugins/go/tasks/logs/logging_utils.go +++ b/flyteplugins/go/tasks/logs/logging_utils.go @@ -14,7 +14,7 @@ import ( ) // Internal -func GetLogsForContainerInPod(ctx context.Context, logPlugin tasklog.Plugin, taskExecID pluginsCore.TaskExecutionID, pod *v1.Pod, index uint32, nameSuffix string, extraLogTemplateVarsByScheme *tasklog.TemplateVarsByScheme, taskTemplate *core.TaskTemplate) ([]*core.TaskLog, error) { +func GetLogsForContainerInPod(ctx context.Context, logPlugin tasklog.Plugin, taskExecID pluginsCore.TaskExecutionID, pod *v1.Pod, index uint32, nameSuffix string, extraLogTemplateVars []tasklog.TemplateVar, taskTemplate *core.TaskTemplate) ([]*core.TaskLog, error) { if logPlugin == nil { return nil, nil } @@ -39,19 +39,19 @@ func GetLogsForContainerInPod(ctx context.Context, logPlugin tasklog.Plugin, tas logs, err := logPlugin.GetTaskLogs( tasklog.Input{ - PodName: pod.Name, - PodUID: string(pod.GetUID()), - Namespace: pod.Namespace, - ContainerName: pod.Spec.Containers[index].Name, - ContainerID: pod.Status.ContainerStatuses[index].ContainerID, - LogName: nameSuffix, - PodRFC3339StartTime: time.Unix(startTime, 0).Format(time.RFC3339), - PodRFC3339FinishTime: time.Unix(finishTime, 0).Format(time.RFC3339), - PodUnixStartTime: startTime, - PodUnixFinishTime: finishTime, - TaskExecutionID: taskExecID, - ExtraTemplateVarsByScheme: extraLogTemplateVarsByScheme, - TaskTemplate: taskTemplate, + PodName: pod.Name, + PodUID: string(pod.GetUID()), + Namespace: pod.Namespace, + ContainerName: pod.Spec.Containers[index].Name, + ContainerID: pod.Status.ContainerStatuses[index].ContainerID, + LogName: nameSuffix, + PodRFC3339StartTime: time.Unix(startTime, 0).Format(time.RFC3339), + PodRFC3339FinishTime: time.Unix(finishTime, 0).Format(time.RFC3339), + PodUnixStartTime: startTime, + PodUnixFinishTime: finishTime, + TaskExecutionID: taskExecID, + ExtraTemplateVars: extraLogTemplateVars, + TaskTemplate: taskTemplate, }, ) @@ -89,25 +89,25 @@ func InitializeLogPlugins(cfg *LogConfig) (tasklog.Plugin, error) { if cfg.IsKubernetesEnabled { if len(cfg.KubernetesTemplateURI) > 0 { - plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Kubernetes Logs", Scheme: tasklog.TemplateSchemePod, TemplateURIs: []tasklog.TemplateURI{cfg.KubernetesTemplateURI}, MessageFormat: core.TaskLog_JSON}) + plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Kubernetes Logs", TemplateURIs: []tasklog.TemplateURI{cfg.KubernetesTemplateURI}, MessageFormat: core.TaskLog_JSON}) } else { - plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Kubernetes Logs", Scheme: tasklog.TemplateSchemePod, TemplateURIs: []tasklog.TemplateURI{fmt.Sprintf("%s/#!/log/{{ .namespace }}/{{ .podName }}/pod?namespace={{ .namespace }}", cfg.KubernetesURL)}, MessageFormat: core.TaskLog_JSON}) + plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Kubernetes Logs", TemplateURIs: []tasklog.TemplateURI{fmt.Sprintf("%s/#!/log/{{ .namespace }}/{{ .podName }}/pod?namespace={{ .namespace }}", cfg.KubernetesURL)}, MessageFormat: core.TaskLog_JSON}) } } if cfg.IsCloudwatchEnabled { if len(cfg.CloudwatchTemplateURI) > 0 { - plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Cloudwatch Logs", Scheme: tasklog.TemplateSchemePod, TemplateURIs: []tasklog.TemplateURI{cfg.CloudwatchTemplateURI}, MessageFormat: core.TaskLog_JSON}) + plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Cloudwatch Logs", TemplateURIs: []tasklog.TemplateURI{cfg.CloudwatchTemplateURI}, MessageFormat: core.TaskLog_JSON}) } else { - plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Cloudwatch Logs", Scheme: tasklog.TemplateSchemePod, TemplateURIs: []tasklog.TemplateURI{fmt.Sprintf("https://console.aws.amazon.com/cloudwatch/home?region=%s#logEventViewer:group=%s;stream=var.log.containers.{{ .podName }}_{{ .namespace }}_{{ .containerName }}-{{ .containerId }}.log", cfg.CloudwatchRegion, cfg.CloudwatchLogGroup)}, MessageFormat: core.TaskLog_JSON}) + plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Cloudwatch Logs", TemplateURIs: []tasklog.TemplateURI{fmt.Sprintf("https://console.aws.amazon.com/cloudwatch/home?region=%s#logEventViewer:group=%s;stream=var.log.containers.{{ .podName }}_{{ .namespace }}_{{ .containerName }}-{{ .containerId }}.log", cfg.CloudwatchRegion, cfg.CloudwatchLogGroup)}, MessageFormat: core.TaskLog_JSON}) } } if cfg.IsStackDriverEnabled { if len(cfg.StackDriverTemplateURI) > 0 { - plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Stackdriver Logs", Scheme: tasklog.TemplateSchemePod, TemplateURIs: []tasklog.TemplateURI{cfg.StackDriverTemplateURI}, MessageFormat: core.TaskLog_JSON}) + plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Stackdriver Logs", TemplateURIs: []tasklog.TemplateURI{cfg.StackDriverTemplateURI}, MessageFormat: core.TaskLog_JSON}) } else { - plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Stackdriver Logs", Scheme: tasklog.TemplateSchemePod, TemplateURIs: []tasklog.TemplateURI{fmt.Sprintf("https://console.cloud.google.com/logs/viewer?project=%s&angularJsUrl=%%2Flogs%%2Fviewer%%3Fproject%%3D%s&resource=%s&advancedFilter=resource.labels.pod_name%%3D{{ .podName }}", cfg.GCPProjectName, cfg.GCPProjectName, cfg.StackdriverLogResourceName)}, MessageFormat: core.TaskLog_JSON}) + plugins = append(plugins, tasklog.TemplateLogPlugin{DisplayName: "Stackdriver Logs", TemplateURIs: []tasklog.TemplateURI{fmt.Sprintf("https://console.cloud.google.com/logs/viewer?project=%s&angularJsUrl=%%2Flogs%%2Fviewer%%3Fproject%%3D%s&resource=%s&advancedFilter=resource.labels.pod_name%%3D{{ .podName }}", cfg.GCPProjectName, cfg.GCPProjectName, cfg.StackdriverLogResourceName)}, MessageFormat: core.TaskLog_JSON}) } } @@ -117,7 +117,6 @@ func InitializeLogPlugins(cfg *LogConfig) (tasklog.Plugin, error) { tasklog.TemplateLogPlugin{ Name: logLinkType, DisplayName: fmt.Sprintf("%s logs", logLinkType), - Scheme: tasklog.TemplateSchemeDynamic, DynamicTemplateURIs: []tasklog.TemplateURI{ dynamicLogLink, }, diff --git a/flyteplugins/go/tasks/logs/logging_utils_test.go b/flyteplugins/go/tasks/logs/logging_utils_test.go index a0475a6169..6b7aaf5685 100644 --- a/flyteplugins/go/tasks/logs/logging_utils_test.go +++ b/flyteplugins/go/tasks/logs/logging_utils_test.go @@ -334,7 +334,6 @@ func TestGetLogsForContainerInPod_Templates(t *testing.T) { "https://flyte.corp.net/console/projects/{{ .executionProject }}/domains/{{ .executionDomain }}/executions/{{ .executionName }}/nodeId/{{ .nodeID }}/taskId/{{ .taskID }}/attempt/{{ .taskRetryAttempt }}/view/logs", }, MessageFormat: core.TaskLog_JSON, - Scheme: tasklog.TemplateSchemeTaskExecution, }, }, }, nil, []*core.TaskLog{ diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go index c0427c11c5..c995892d97 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go @@ -7,16 +7,6 @@ import ( pluginsCore "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core" ) -//go:generate enumer --type=TemplateScheme --trimprefix=TemplateScheme -json -yaml - -type TemplateScheme int - -const ( - TemplateSchemePod TemplateScheme = iota - TemplateSchemeTaskExecution - TemplateSchemeDynamic -) - // TemplateURI is a URI that accepts templates. See: go/tasks/pluginmachinery/tasklog/template.go for available templates. type TemplateURI = string @@ -25,31 +15,23 @@ type TemplateVar struct { Value string } -type TemplateVars []TemplateVar - -type TemplateVarsByScheme struct { - Common TemplateVars - Pod TemplateVars - TaskExecution TemplateVars -} - // Input contains all available information about task's execution that a log plugin can use to construct task's // log links. type Input struct { - HostName string - PodName string - Namespace string - ContainerName string - ContainerID string - LogName string - PodRFC3339StartTime string - PodRFC3339FinishTime string - PodUnixStartTime int64 - PodUnixFinishTime int64 - PodUID string - TaskExecutionID pluginsCore.TaskExecutionID - ExtraTemplateVarsByScheme *TemplateVarsByScheme - TaskTemplate *core.TaskTemplate + HostName string + PodName string + Namespace string + ContainerName string + ContainerID string + LogName string + PodRFC3339StartTime string + PodRFC3339FinishTime string + PodUnixStartTime int64 + PodUnixFinishTime int64 + PodUID string + TaskExecutionID pluginsCore.TaskExecutionID + ExtraTemplateVars []TemplateVar + TaskTemplate *core.TaskTemplate } // Output contains all task logs a plugin generates for a given Input. @@ -64,10 +46,10 @@ type Plugin interface { } type TemplateLogPlugin struct { + // TODO: these don't need pflags anymore? Name string `json:"name" pflag:",Name of the plugin."` DisplayName string `json:"displayName" pflag:",Display name for the generated log when displayed in the console."` TemplateURIs []TemplateURI `json:"templateUris" pflag:",URI Templates for generating task log links."` DynamicTemplateURIs []TemplateURI `json:"dynamictemplateUris" pflag:",URI Templates for generating dynamic task log links."` MessageFormat core.TaskLog_MessageFormat `json:"messageFormat" pflag:",Log Message Format."` - Scheme TemplateScheme `json:"scheme" pflag:",Templating scheme to use. Supported values are Pod and TaskExecution."` } diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go index 2bdb3f40fb..aa386ef6a9 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template.go @@ -73,7 +73,7 @@ func initDefaultRegexes() templateRegexes { var defaultRegexes = initDefaultRegexes() -func replaceAll(template string, vars TemplateVars) string { +func replaceAll(template string, vars []TemplateVar) string { for _, v := range vars { if len(v.Value) > 0 { template = v.Regex.ReplaceAllLiteralString(template, v.Value) @@ -82,14 +82,14 @@ func replaceAll(template string, vars TemplateVars) string { return template } -func (input Input) templateVarsForScheme(scheme TemplateScheme) TemplateVars { - vars := TemplateVars{ - {defaultRegexes.LogName, input.LogName}, +func (input Input) templateVarsForScheme() []TemplateVar { + vars := []TemplateVar{ + TemplateVar{defaultRegexes.LogName, input.LogName}, } - gotExtraTemplateVars := input.ExtraTemplateVarsByScheme != nil + gotExtraTemplateVars := input.ExtraTemplateVars != nil if gotExtraTemplateVars { - vars = append(vars, input.ExtraTemplateVarsByScheme.Common...) + vars = append(vars, input.ExtraTemplateVars...) } port := input.TaskTemplate.GetConfig()["port"] @@ -117,7 +117,7 @@ func (input Input) templateVarsForScheme(scheme TemplateScheme) TemplateVars { TemplateVar{defaultRegexes.Hostname, input.HostName}, ) if gotExtraTemplateVars { - vars = append(vars, input.ExtraTemplateVarsByScheme.Pod...) + vars = append(vars, input.ExtraTemplateVars...) } if input.TaskExecutionID != nil { taskExecutionIdentifier := input.TaskExecutionID.GetID() @@ -176,7 +176,7 @@ func (input Input) templateVarsForScheme(scheme TemplateScheme) TemplateVars { } } if gotExtraTemplateVars { - vars = append(vars, input.ExtraTemplateVarsByScheme.TaskExecution...) + vars = append(vars, input.ExtraTemplateVars...) } vars = append( @@ -212,7 +212,7 @@ func getDynamicLogLinkTypes(taskTemplate *core.TaskTemplate) []string { } func (p TemplateLogPlugin) GetTaskLogs(input Input) (Output, error) { - templateVars := input.templateVarsForScheme(p.Scheme) + templateVars := input.templateVarsForScheme() taskLogs := make([]*core.TaskLog, 0, len(p.TemplateURIs)) for _, templateURI := range p.TemplateURIs { taskLogs = append(taskLogs, &core.TaskLog{ diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go index f62e65250c..e7001003dc 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go @@ -100,19 +100,17 @@ func Test_Input_templateVarsForScheme(t *testing.T) { tests := []struct { name string - scheme TemplateScheme baseVars Input - extraVars *TemplateVarsByScheme - exact TemplateVars - contains TemplateVars - notContains TemplateVars + extraVars []TemplateVar + exact []TemplateVar + contains []TemplateVar + notContains []TemplateVar }{ { "pod happy path", - TemplateSchemePod, podBase, nil, - TemplateVars{ + []TemplateVar{ {defaultRegexes.LogName, "main_logs"}, {defaultRegexes.PodName, "my-pod"}, {defaultRegexes.PodUID, "my-pod-uid"}, @@ -130,19 +128,14 @@ func Test_Input_templateVarsForScheme(t *testing.T) { }, { "pod with extra vars", - TemplateSchemePod, podBase, - &TemplateVarsByScheme{ - Common: TemplateVars{ - {testRegexes.Foo, "foo"}, - }, - Pod: TemplateVars{ - {testRegexes.Bar, "bar"}, - {testRegexes.Baz, "baz"}, - }, + []TemplateVar{ + {testRegexes.Foo, "foo"}, + {testRegexes.Bar, "bar"}, + {testRegexes.Baz, "baz"}, }, nil, - TemplateVars{ + []TemplateVar{ {testRegexes.Foo, "foo"}, {testRegexes.Bar, "bar"}, {testRegexes.Baz, "baz"}, @@ -151,10 +144,9 @@ func Test_Input_templateVarsForScheme(t *testing.T) { }, { "task execution happy path", - TemplateSchemeTaskExecution, taskExecutionBase, nil, - TemplateVars{ + []TemplateVar{ {defaultRegexes.LogName, "main_logs"}, {defaultRegexes.PodName, ""}, {defaultRegexes.PodUID, ""}, @@ -182,19 +174,14 @@ func Test_Input_templateVarsForScheme(t *testing.T) { }, { "task execution with extra vars", - TemplateSchemeTaskExecution, taskExecutionBase, - &TemplateVarsByScheme{ - Common: TemplateVars{ - {testRegexes.Foo, "foo"}, - }, - TaskExecution: TemplateVars{ - {testRegexes.Bar, "bar"}, - {testRegexes.Baz, "baz"}, - }, + []TemplateVar{ + {testRegexes.Foo, "foo"}, + {testRegexes.Bar, "bar"}, + {testRegexes.Baz, "baz"}, }, nil, - TemplateVars{ + []TemplateVar{ {testRegexes.Foo, "foo"}, {testRegexes.Bar, "bar"}, {testRegexes.Baz, "baz"}, @@ -220,21 +207,19 @@ func Test_Input_templateVarsForScheme(t *testing.T) { // }, { "flyin happy path", - TemplateSchemeDynamic, flyinBase, nil, nil, - TemplateVars{ + []TemplateVar{ {defaultRegexes.Port, "1234"}, }, nil, }, { "flyin and pod happy path", - TemplateSchemeDynamic, flyinBase, nil, - TemplateVars{ + []TemplateVar{ {defaultRegexes.LogName, "main_logs"}, {defaultRegexes.Port, "1234"}, {defaultRegexes.PodName, "my-pod"}, @@ -253,12 +238,11 @@ func Test_Input_templateVarsForScheme(t *testing.T) { }, { "pod with port not affected", - TemplateSchemePod, podBase, nil, nil, nil, - TemplateVars{ + []TemplateVar{ {defaultRegexes.Port, "1234"}, }, }, @@ -266,8 +250,8 @@ func Test_Input_templateVarsForScheme(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { base := tt.baseVars - base.ExtraTemplateVarsByScheme = tt.extraVars - got := base.templateVarsForScheme(tt.scheme) + base.ExtraTemplateVars = tt.extraVars + got := base.templateVarsForScheme() if tt.exact != nil { assert.Equal(t, got, tt.exact) } @@ -466,7 +450,6 @@ func TestTemplateLogPlugin(t *testing.T) { { "task-with-task-execution-identifier", TemplateLogPlugin{ - Scheme: TemplateSchemeTaskExecution, TemplateURIs: []TemplateURI{"https://flyte.corp.net/console/projects/{{ .executionProject }}/domains/{{ .executionDomain }}/executions/{{ .executionName }}/nodeId/{{ .nodeID }}/taskId/{{ .taskID }}/attempt/{{ .taskRetryAttempt }}/view/logs"}, MessageFormat: core.TaskLog_JSON, }, @@ -498,7 +481,6 @@ func TestTemplateLogPlugin(t *testing.T) { { "mapped-task-with-task-execution-identifier", TemplateLogPlugin{ - Scheme: TemplateSchemeTaskExecution, TemplateURIs: []TemplateURI{"https://flyte.corp.net/console/projects/{{ .executionProject }}/domains/{{ .executionDomain }}/executions/{{ .executionName }}/nodeId/{{ .nodeID }}/taskId/{{ .taskID }}/attempt/{{ .subtaskParentRetryAttempt }}/mappedIndex/{{ .subtaskExecutionIndex }}/mappedAttempt/{{ .subtaskRetryAttempt }}/view/logs"}, MessageFormat: core.TaskLog_JSON, }, @@ -515,12 +497,10 @@ func TestTemplateLogPlugin(t *testing.T) { PodUnixStartTime: 123, PodUnixFinishTime: 12345, TaskExecutionID: dummyTaskExecID(), - ExtraTemplateVarsByScheme: &TemplateVarsByScheme{ - TaskExecution: TemplateVars{ - {MustCreateRegex("subtaskExecutionIndex"), "1"}, - {MustCreateRegex("subtaskRetryAttempt"), "1"}, - {MustCreateRegex("subtaskParentRetryAttempt"), "0"}, - }, + ExtraTemplateVars: []TemplateVar{ + {MustCreateRegex("subtaskExecutionIndex"), "1"}, + {MustCreateRegex("subtaskRetryAttempt"), "1"}, + {MustCreateRegex("subtaskParentRetryAttempt"), "0"}, }, }, }, @@ -538,7 +518,6 @@ func TestTemplateLogPlugin(t *testing.T) { "flyin", TemplateLogPlugin{ Name: "vscode", - Scheme: TemplateSchemeDynamic, DynamicTemplateURIs: []TemplateURI{"vscode://flyin:{{ .taskConfig.port }}/{{ .podName }}"}, MessageFormat: core.TaskLog_JSON, }, @@ -593,7 +572,6 @@ func TestTemplateLogPlugin(t *testing.T) { "flyin - no link_type in task template", TemplateLogPlugin{ Name: "vscode", - Scheme: TemplateSchemeDynamic, DynamicTemplateURIs: []TemplateURI{"vscode://flyin:{{ .taskConfig.port }}/{{ .podName }}"}, MessageFormat: core.TaskLog_JSON, DisplayName: "Flyin Logs", diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/templatescheme_enumer.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/templatescheme_enumer.go deleted file mode 100644 index d942a34344..0000000000 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/templatescheme_enumer.go +++ /dev/null @@ -1,85 +0,0 @@ -// Code generated by "enumer --type=TemplateScheme --trimprefix=TemplateScheme -json -yaml"; DO NOT EDIT. - -package tasklog - -import ( - "encoding/json" - "fmt" -) - -const _TemplateSchemeName = "PodTaskExecutionDynamic" - -var _TemplateSchemeIndex = [...]uint8{0, 3, 16, 23} - -func (i TemplateScheme) String() string { - if i < 0 || i >= TemplateScheme(len(_TemplateSchemeIndex)-1) { - return fmt.Sprintf("TemplateScheme(%d)", i) - } - return _TemplateSchemeName[_TemplateSchemeIndex[i]:_TemplateSchemeIndex[i+1]] -} - -var _TemplateSchemeValues = []TemplateScheme{0, 1, 2} - -var _TemplateSchemeNameToValueMap = map[string]TemplateScheme{ - _TemplateSchemeName[0:3]: 0, - _TemplateSchemeName[3:16]: 1, - _TemplateSchemeName[16:23]: 2, -} - -// TemplateSchemeString retrieves an enum value from the enum constants string name. -// Throws an error if the param is not part of the enum. -func TemplateSchemeString(s string) (TemplateScheme, error) { - if val, ok := _TemplateSchemeNameToValueMap[s]; ok { - return val, nil - } - return 0, fmt.Errorf("%s does not belong to TemplateScheme values", s) -} - -// TemplateSchemeValues returns all values of the enum -func TemplateSchemeValues() []TemplateScheme { - return _TemplateSchemeValues -} - -// IsATemplateScheme returns "true" if the value is listed in the enum definition. "false" otherwise -func (i TemplateScheme) IsATemplateScheme() bool { - for _, v := range _TemplateSchemeValues { - if i == v { - return true - } - } - return false -} - -// MarshalJSON implements the json.Marshaler interface for TemplateScheme -func (i TemplateScheme) MarshalJSON() ([]byte, error) { - return json.Marshal(i.String()) -} - -// UnmarshalJSON implements the json.Unmarshaler interface for TemplateScheme -func (i *TemplateScheme) UnmarshalJSON(data []byte) error { - var s string - if err := json.Unmarshal(data, &s); err != nil { - return fmt.Errorf("TemplateScheme should be a string, got %s", data) - } - - var err error - *i, err = TemplateSchemeString(s) - return err -} - -// MarshalYAML implements a YAML Marshaler for TemplateScheme -func (i TemplateScheme) MarshalYAML() (interface{}, error) { - return i.String(), nil -} - -// UnmarshalYAML implements a YAML Unmarshaler for TemplateScheme -func (i *TemplateScheme) UnmarshalYAML(unmarshal func(interface{}) error) error { - var s string - if err := unmarshal(&s); err != nil { - return err - } - - var err error - *i, err = TemplateSchemeString(s) - return err -} diff --git a/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context.go b/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context.go index 8ac4d6edc0..77b3ac6501 100644 --- a/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context.go +++ b/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context.go @@ -187,22 +187,20 @@ var logTemplateRegexes = struct { tasklog.MustCreateRegex("subtaskParentRetryAttempt"), } -func (s SubTaskExecutionID) TemplateVarsByScheme() *tasklog.TemplateVarsByScheme { - return &tasklog.TemplateVarsByScheme{ - TaskExecution: tasklog.TemplateVars{ - {Regex: logTemplateRegexes.ParentName, Value: s.parentName}, - { - Regex: logTemplateRegexes.ExecutionIndex, - Value: strconv.FormatUint(uint64(s.executionIndex), 10), - }, - { - Regex: logTemplateRegexes.RetryAttempt, - Value: strconv.FormatUint(s.subtaskRetryAttempt, 10), - }, - { - Regex: logTemplateRegexes.ParentRetryAttempt, - Value: strconv.FormatUint(uint64(s.taskRetryAttempt), 10), - }, +func (s SubTaskExecutionID) TemplateVarsByScheme() []tasklog.TemplateVar { + return []tasklog.TemplateVar{ + {Regex: logTemplateRegexes.ParentName, Value: s.parentName}, + { + Regex: logTemplateRegexes.ExecutionIndex, + Value: strconv.FormatUint(uint64(s.executionIndex), 10), + }, + { + Regex: logTemplateRegexes.RetryAttempt, + Value: strconv.FormatUint(s.subtaskRetryAttempt, 10), + }, + { + Regex: logTemplateRegexes.ParentRetryAttempt, + Value: strconv.FormatUint(uint64(s.taskRetryAttempt), 10), }, } } diff --git a/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context_test.go b/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context_test.go index c3e213e403..103980fab0 100644 --- a/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context_test.go +++ b/flyteplugins/go/tasks/plugins/array/k8s/subtask_exec_context_test.go @@ -36,13 +36,11 @@ func TestSubTaskExecutionContext(t *testing.T) { assert.Equal(t, storage.DataReference("/prefix/"), stCtx.OutputWriter().GetOutputPrefixPath()) assert.Equal(t, storage.DataReference("/raw_prefix/5/1"), stCtx.OutputWriter().GetRawOutputPrefix()) assert.Equal(t, - &tasklog.TemplateVarsByScheme{ - TaskExecution: tasklog.TemplateVars{ - {Regex: logTemplateRegexes.ParentName, Value: "notfound"}, - {Regex: logTemplateRegexes.ExecutionIndex, Value: "0"}, - {Regex: logTemplateRegexes.RetryAttempt, Value: "1"}, - {Regex: logTemplateRegexes.ParentRetryAttempt, Value: "0"}, - }, + []tasklog.TemplateVar{ + {Regex: logTemplateRegexes.ParentName, Value: "notfound"}, + {Regex: logTemplateRegexes.ExecutionIndex, Value: "0"}, + {Regex: logTemplateRegexes.RetryAttempt, Value: "1"}, + {Regex: logTemplateRegexes.ParentRetryAttempt, Value: "0"}, }, stCtx.TaskExecutionMetadata().GetTaskExecutionID().(SubTaskExecutionID).TemplateVarsByScheme(), ) diff --git a/flyteplugins/go/tasks/plugins/k8s/pod/plugin.go b/flyteplugins/go/tasks/plugins/k8s/pod/plugin.go index eae0ac98b7..f72d4eb1d7 100644 --- a/flyteplugins/go/tasks/plugins/k8s/pod/plugin.go +++ b/flyteplugins/go/tasks/plugins/k8s/pod/plugin.go @@ -146,7 +146,7 @@ func (p plugin) GetTaskPhase(ctx context.Context, pluginContext k8s.PluginContex return p.GetTaskPhaseWithLogs(ctx, pluginContext, r, logPlugin, " (User)", nil) } -func (plugin) GetTaskPhaseWithLogs(ctx context.Context, pluginContext k8s.PluginContext, r client.Object, logPlugin tasklog.Plugin, logSuffix string, extraLogTemplateVarsByScheme *tasklog.TemplateVarsByScheme) (pluginsCore.PhaseInfo, error) { +func (plugin) GetTaskPhaseWithLogs(ctx context.Context, pluginContext k8s.PluginContext, r client.Object, logPlugin tasklog.Plugin, logSuffix string, extraLogTemplateVarsByScheme []tasklog.TemplateVar) (pluginsCore.PhaseInfo, error) { pluginState := k8s.PluginState{} _, err := pluginContext.PluginStateReader().Get(&pluginState) if err != nil { diff --git a/flyteplugins/go/tasks/plugins/k8s/ray/ray.go b/flyteplugins/go/tasks/plugins/k8s/ray/ray.go index f6abb58c93..3f8d678ef5 100644 --- a/flyteplugins/go/tasks/plugins/k8s/ray/ray.go +++ b/flyteplugins/go/tasks/plugins/k8s/ray/ray.go @@ -457,13 +457,13 @@ func getEventInfoForRayJob(logConfig logs.LogConfig, pluginContext k8s.PluginCon taskExecID := pluginContext.TaskExecutionMetadata().GetTaskExecutionID() input := tasklog.Input{ - Namespace: rayJob.Namespace, - TaskExecutionID: taskExecID, - ExtraTemplateVarsByScheme: &tasklog.TemplateVarsByScheme{}, + Namespace: rayJob.Namespace, + TaskExecutionID: taskExecID, + ExtraTemplateVars: []tasklog.TemplateVar{}, } if rayJob.Status.JobId != "" { - input.ExtraTemplateVarsByScheme.Common = append( - input.ExtraTemplateVarsByScheme.Common, + input.ExtraTemplateVars = append( + input.ExtraTemplateVars, tasklog.TemplateVar{ Regex: logTemplateRegexes.RayJobID, Value: rayJob.Status.JobId, @@ -471,8 +471,8 @@ func getEventInfoForRayJob(logConfig logs.LogConfig, pluginContext k8s.PluginCon ) } if rayJob.Status.RayClusterName != "" { - input.ExtraTemplateVarsByScheme.Common = append( - input.ExtraTemplateVarsByScheme.Common, + input.ExtraTemplateVars = append( + input.ExtraTemplateVars, tasklog.TemplateVar{ Regex: logTemplateRegexes.RayClusterName, Value: rayJob.Status.RayClusterName, diff --git a/flyteplugins/go/tasks/plugins/k8s/ray/ray_test.go b/flyteplugins/go/tasks/plugins/k8s/ray/ray_test.go index b171ae9aa8..beab938768 100644 --- a/flyteplugins/go/tasks/plugins/k8s/ray/ray_test.go +++ b/flyteplugins/go/tasks/plugins/k8s/ray/ray_test.go @@ -738,7 +738,6 @@ func TestGetEventInfo_LogTemplates(t *testing.T) { TemplateURIs: []tasklog.TemplateURI{ "http://test/projects/{{ .executionProject }}/domains/{{ .executionDomain }}/executions/{{ .executionName }}/nodeId/{{ .nodeID }}/taskId/{{ .taskID }}/attempt/{{ .taskRetryAttempt }}", }, - Scheme: tasklog.TemplateSchemeTaskExecution, }, expectedTaskLogs: []*core.TaskLog{ { @@ -823,7 +822,6 @@ func TestGetEventInfo_DashboardURL(t *testing.T) { dashboardURLTemplate: tasklog.TemplateLogPlugin{ DisplayName: "Ray Dashboard", TemplateURIs: []tasklog.TemplateURI{"http://test/{{.generatedName}}"}, - Scheme: tasklog.TemplateSchemeTaskExecution, }, expectedTaskLogs: []*core.TaskLog{ {