Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generic dynamic log links #5066

Closed
wants to merge 4 commits into from

Conversation

eapolinario
Copy link
Contributor

@eapolinario eapolinario commented Mar 15, 2024

Tracking issue

#4773

Why are the changes needed?

We need support for dynamic log links defined by tasks.

What changes were proposed in this pull request?

Add a flag to the propeller config called GenericDynamicLogLinksEnabled, which is self-explanatory. We then use a dynamic log link guard called "Generic" to guide the addition of generic dynamic log links (what I'm calling these log links defined in tasks - a better name could be in order).

How was this patch tested?

Unit tests and local sandbox.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

This PR implements generic dynamic log links support in Flyte, introducing a new 'GenericDynamicLogLinksEnabled' flag and infrastructure for task-defined dynamic log links. The implementation includes template-based log link processing and configuration updates across k8s array, spark, and ray plugins. The changes enable flexible log management through customizable log link templates.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 4

Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Mar 15, 2024
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 10 lines in your changes missing coverage. Please review.

Project coverage is 59.01%. Comparing base (44914b1) to head (a038831).
Report is 961 commits behind head on master.

Files with missing lines Patch % Lines
...ugins/go/tasks/pluginmachinery/tasklog/template.go 77.27% 7 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5066      +/-   ##
==========================================
+ Coverage   59.00%   59.01%   +0.01%     
==========================================
  Files         645      645              
  Lines       55578    55622      +44     
==========================================
+ Hits        32792    32826      +34     
- Misses      20194    20201       +7     
- Partials     2592     2595       +3     
Flag Coverage Δ
unittests 59.01% <81.81%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eapolinario
Copy link
Contributor Author

/review

@eapolinario
Copy link
Contributor Author

eapolinario commented Dec 27, 2024

Code Review Agent Run #51871a

Actionable Suggestions - 8
  • flyteplugins/go/tasks/logs/logging_utils_test.go - 1
    • Consider splitting long configuration line · Line 714-714
  • flyteplugins/go/tasks/plugins/k8s/ray/config_flags_test.go - 1
  • flyteplugins/go/tasks/logs/logging_utils.go - 1
    • Type mismatch in DynamicTemplateURIs assignment · Line 129-129
  • flyteplugins/go/tasks/pluginmachinery/core/mocks/task_overrides.go - 3
  • flyteplugins/go/tasks/pluginmachinery/tasklog/template.go - 2
Review Details
  • Files reviewed - 14 · Commit Range: eab5590..a038831
    • flyteplugins/go/tasks/logs/config.go
    • flyteplugins/go/tasks/logs/logconfig_flags.go
    • flyteplugins/go/tasks/logs/logconfig_flags_test.go
    • flyteplugins/go/tasks/logs/logging_utils.go
    • flyteplugins/go/tasks/logs/logging_utils_test.go
    • flyteplugins/go/tasks/pluginmachinery/core/mocks/task_overrides.go
    • flyteplugins/go/tasks/pluginmachinery/tasklog/template.go
    • flyteplugins/go/tasks/pluginmachinery/tasklog/template_test.go
    • flyteplugins/go/tasks/plugins/array/k8s/config_flags.go
    • flyteplugins/go/tasks/plugins/array/k8s/config_flags_test.go
    • flyteplugins/go/tasks/plugins/k8s/ray/config_flags.go
    • flyteplugins/go/tasks/plugins/k8s/ray/config_flags_test.go
    • flyteplugins/go/tasks/plugins/k8s/spark/config_flags.go
    • flyteplugins/go/tasks/plugins/k8s/spark/config_flags_test.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • GOVULNCHECK (Security Vulnerability) - ✔︎ Successful
    • OWASP (Security Vulnerability) - ✔︎ Successful
    • SNYK (Security Vulnerability) - ✔︎ Successful

AI Code Review powered by Bito Logo

@eapolinario
Copy link
Contributor Author

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Generic Dynamic Log Links Support

config.go - Added GenericDynamicLogLinksEnabled flag to LogConfig

logging_utils.go - Implemented generic dynamic log links functionality

template.go - Added support for generic dynamic log link templates and processing

Testing - Test Coverage for Generic Log Links

logging_utils_test.go - Added test cases for generic dynamic log links functionality

logconfig_flags_test.go - Added tests for generic dynamic log links config flags

template_test.go - Added test cases for template-based generic log links

config_flags_test.go - Added tests for k8s array plugin log config flags

config_flags_test.go - Added tests for spark plugin log config flags

Other Improvements - Configuration Updates

logconfig_flags.go - Added flag for enabling generic dynamic log links

config_flags.go - Added generic log links config for k8s array plugin

config_flags.go - Added Ray CRD version and service account config flags

config_flags.go - Added generic log links config for spark plugin

task_overrides.go - Updated mock implementations for task overrides

&core.TaskTemplate{
Config: map[string]string{
"link_type": "abc,defg",
"generic_dynamic_log_links": `{"links": [{"name": "abc", "display_name": "Other logs", "template_uri": "coming://from/abc"},{"name": "defg", "display_name": "defg logs", "template_uri": "coming://from/defg"}]}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider splitting long configuration line

Consider splitting the long line containing generic_dynamic_log_links configuration into multiple lines for better readability. The current line exceeds 120 characters which may impact code maintainability.

Code suggestion
Check the AI-generated fix before applying
Suggested change
"generic_dynamic_log_links": `{"links": [{"name": "abc", "display_name": "Other logs", "template_uri": "coming://from/abc"},{"name": "defg", "display_name": "defg logs", "template_uri": "coming://from/defg"}]}`,
"generic_dynamic_log_links": `{
"links": [{"name": "abc", "display_name": "Other logs", "template_uri": "coming://from/abc"},
{"name": "defg", "display_name": "defg logs", "template_uri": "coming://from/defg"}]
}`,

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +228 to +255
t.Run("Test_kubeRayCrdVersion", func(t *testing.T) {

t.Run("Override", func(t *testing.T) {
testValue := "1"

cmdFlags.Set("kubeRayCrdVersion", testValue)
if vString, err := cmdFlags.GetString("kubeRayCrdVersion"); err == nil {
testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.KubeRayCrdVersion)

} else {
assert.FailNow(t, err.Error())
}
})
})
t.Run("Test_serviceAccount", func(t *testing.T) {

t.Run("Override", func(t *testing.T) {
testValue := "1"

cmdFlags.Set("serviceAccount", testValue)
if vString, err := cmdFlags.GetString("serviceAccount"); err == nil {
testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.ServiceAccount)

} else {
assert.FailNow(t, err.Error())
}
})
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider consolidating similar test cases

Consider consolidating the test cases for kubeRayCrdVersion and serviceAccount with other similar string flag tests to reduce code duplication. The test structure and validation logic is identical across multiple test cases. A similar issue was also found in flyteplugins/go/tasks/plugins/k8s/spark/config_flags_test.go (line 270-283).

Code suggestion
Check the AI-generated fix before applying
 @@ -97,159 +97,25 @@ func TestConfig_SetFlags(t *testing.T) {
      actual := Config{}
      cmdFlags := actual.GetPFlagSet("")
      assert.True(t, cmdFlags.HasFlags())
 -    // ... existing test cases ...
 +    testStringFlag := func(t *testing.T, flagName string, field *string) {
 +        t.Run(fmt.Sprintf("Test_%s", flagName), func(t *testing.T) {
 +            t.Run("Override", func(t *testing.T) {
 +                testValue := "1"
 +                cmdFlags.Set(flagName, testValue)
 +                if vString, err := cmdFlags.GetString(flagName); err == nil {
 +                    testDecodeJson_Config(t, fmt.Sprintf("%v", vString), field)
 +                } else {
 +                    assert.FailNow(t, err.Error())
 +                }
 +            })
 +        })
 +    }
 +    testStringFlag(t, "kubeRayCrdVersion", &actual.KubeRayCrdVersion)
 +    testStringFlag(t, "serviceAccount", &actual.ServiceAccount)
  }

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

// The generic dynamic log link is special. We're going to use the string `Generic` to signal that we're using it.
// TODO: decide if it's worth doing this in a different way.
if cfg.GenericDynamicLogLinksEnabled {
dynamicPlugins = append(dynamicPlugins, tasklog.TemplateLogPlugin{Name: "Generic", DynamicTemplateURIs: []string{""}, MessageFormat: core.TaskLog_JSON})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch in DynamicTemplateURIs assignment

Consider using []tasklog.TemplateURI instead of []string for DynamicTemplateURIs to maintain type consistency. The TemplateLogPlugin struct expects DynamicTemplateURIs to be of type []TemplateURI.

Code suggestion
Check the AI-generated fix before applying
Suggested change
dynamicPlugins = append(dynamicPlugins, tasklog.TemplateLogPlugin{Name: "Generic", DynamicTemplateURIs: []string{""}, MessageFormat: core.TaskLog_JSON})
dynamicPlugins = append(dynamicPlugins, tasklog.TemplateLogPlugin{Name: "Generic", DynamicTemplateURIs: []tasklog.TemplateURI{""}, MessageFormat: core.TaskLog_JSON})

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +91 to +93
func (_m *TaskOverrides) OnGetExtendedResources() *TaskOverrides_GetExtendedResources {
c_call := _m.On("GetExtendedResources")
return &TaskOverrides_GetExtendedResources{Call: c_call}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock setup method potentially incorrect

Consider if changing OnGetExtendedResources() to OnGetContainerImage() is intentional as it appears to be replacing the extended resources mock setup with container image mock setup.

Code suggestion
Check the AI-generated fix before applying
Suggested change
func (_m *TaskOverrides) OnGetExtendedResources() *TaskOverrides_GetExtendedResources {
c_call := _m.On("GetExtendedResources")
return &TaskOverrides_GetExtendedResources{Call: c_call}
func (_m *TaskOverrides) OnGetContainerImage() *TaskOverrides_GetContainerImage {
c_call := _m.On("GetContainerImage")
return &TaskOverrides_GetContainerImage{Call: c_call}
}
func (_m *TaskOverrides) OnGetContainerImage() *TaskOverrides_GetContainerImage {
c_call := _m.On("GetContainerImage")
return &TaskOverrides_GetContainerImage{Call: c_call}

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(string)
r0 = ret.Get(0).(*flyteidlcore.ExtendedResources)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider nil check before type assertion

Consider validating the return value from ret.Get(0) before type assertion to avoid potential panic if the value is nil.

Code suggestion
Check the AI-generated fix before applying
Suggested change
}
if v := ret.Get(0); v != nil {
r0 = v.(string)
} else {
r0 = ""
}

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +93 to 95
return &TaskOverrides_GetExtendedResources{Call: c_call}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider keeping both mock methods

Consider keeping both OnGetContainerImage and OnGetExtendedResources methods since removing the container image method could break existing tests that depend on it.

Code suggestion
Check the AI-generated fix before applying
Suggested change
return &TaskOverrides_GetExtendedResources{Call: c_call}
}
func (_m *TaskOverrides) OnGetExtendedResources() *TaskOverrides_GetExtendedResources {
c_call := _m.On("GetExtendedResources")
return &TaskOverrides_GetExtendedResources{Call: c_call}
}
func (_m *TaskOverrides) OnGetContainerImage() *TaskOverrides_GetContainerImage {
c_call := _m.On("GetContainerImage")
return &TaskOverrides_GetContainerImage{Call: c_call}

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@@ -206,21 +235,44 @@
})
}

genericDynamicLogLinks := taskTemplateHasGenericDynamicLogLinksEnabled(input.TaskTemplate)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding nil check for TaskTemplate

Consider checking if input.TaskTemplate is nil before calling taskTemplateHasGenericDynamicLogLinksEnabled() to avoid potential nil pointer dereference.

Code suggestion
Check the AI-generated fix before applying
Suggested change
genericDynamicLogLinks := taskTemplateHasGenericDynamicLogLinksEnabled(input.TaskTemplate)
var genericDynamicLogLinks []genericDynamicLogLink
if input.TaskTemplate != nil {
genericDynamicLogLinks = taskTemplateHasGenericDynamicLogLinksEnabled(input.TaskTemplate)
}

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +261 to +263
} else if p.Name == dynamicLogLinkType {
if p.Name == dynamicLogLinkType {
for _, match := range taskConfigVarRegex.FindAllStringSubmatch(dynamicTemplateURI, -1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant nested if condition

Consider removing the redundant nested if condition since it's checking the same condition as the outer if statement

Code suggestion
Check the AI-generated fix before applying
Suggested change
} else if p.Name == dynamicLogLinkType {
if p.Name == dynamicLogLinkType {
for _, match := range taskConfigVarRegex.FindAllStringSubmatch(dynamicTemplateURI, -1) {
} else if p.Name == dynamicLogLinkType {
for _, match := range taskConfigVarRegex.FindAllStringSubmatch(dynamicTemplateURI, -1) {
for _, match := range taskConfigVarRegex.FindAllStringSubmatch(dynamicTemplateURI, -1) {

Code Review Run #51871a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@eapolinario
Copy link
Contributor Author

Cleaning stale PRs. Please reopen if you wan to discuss this further.

@eapolinario eapolinario closed this Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant