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

fix(logging): make RPC call to instance-manager to set log level #3280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

james-munson
Copy link
Contributor

Which issue(s) this PR fixes:

Issue longhorn/longhorn#6702

What this PR does / why we need it:

Sync the log level with instance-managers.

Special notes for your reviewer:

Additional documentation or context

Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

The changes in this pull request focus on the syncLogSettingsToInstanceManagerPod function within the InstanceManagerController class. The modifications allow the function to synchronize log levels for both version 1 and version 2 data engines, enhancing flexibility. The log level setting name has been updated for a more generalized approach, and error messages have been improved for clarity.

Changes

File Change Summary
controller/instance_manager_controller.go Modified syncLogSettingsToInstanceManagerPod to handle log level settings for both version 1 and version 2 data engines, including enhanced error messages and updated log level setting names.

Assessment against linked issues

Objective Addressed Explanation
Configure the log level of other system and user managed components via longhorn manager setting (#6702)

Suggested reviewers

  • derekbit
  • PhanLe1010

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 29f95bf and 95f3152.

📒 Files selected for processing (1)
  • controller/instance_manager_controller.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/instance_manager_controller.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
controller/instance_manager_controller.go (2)

534-547: Approve changes with suggestions for error handling improvements

The implementation for V1 data engine log level synchronization looks good. However, the error handling could be more specific to help with debugging.

Consider enhancing the error handling by adding more context:

-		err = client.LogSetLevel(longhorn.DataEngineTypeV1, "", setting.Value)
-		if err != nil {
-			return errors.Wrapf(err, "failed to set instance-manager log level from %v", settingName)
-		}
+		if err = client.LogSetLevel(longhorn.DataEngineTypeV1, "", setting.Value); err != nil {
+			return errors.Wrapf(err, "failed to set instance-manager log level to %v for data engine v1", setting.Value)
+		}

534-535: Move client.Close() defer statement up

The client.Close() defer statement should be placed immediately after client creation to ensure cleanup in all code paths.

Move the defer statement up:

 	if types.IsDataEngineV1(im.Spec.DataEngine) {
+		defer client.Close()
 		settingName := types.SettingNameLogLevel
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4864291 and 5215c8d.

📒 Files selected for processing (1)
  • controller/instance_manager_controller.go (1 hunks)

Comment on lines 534 to 547
if types.IsDataEngineV1(im.Spec.DataEngine) {
settingName := types.SettingNameLogLevel
setting, err := imc.ds.GetSettingWithAutoFillingRO(settingName)
if err != nil {
return err
}

err = client.LogSetLevel(longhorn.DataEngineTypeV1, "", setting.Value)
if err != nil {
return errors.Wrapf(err, "failed to set instance-manager log level from %v", settingName)
}

return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Why can this setting only be applied to v1 data engine? v2 data engine should be applied as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remedied and re-pushed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
controller/instance_manager_controller.go (1)

546-558: LGTM with suggestions for error handling

The implementation correctly handles log level synchronization for both V1 and V2 data engines. However, the error handling could be improved.

Consider consolidating the error handling to reduce duplication:

-			if err != nil {
-				return errors.Wrapf(err, "failed to set instance-manager log level to %v, using setting %v", setting.Value, settingName)
-			}
-		case types.SettingNameV2DataEngineLogFlags:
-			err = client.LogSetFlags(longhorn.DataEngineTypeV2, "spdk_tgt", setting.Value)
-			if err != nil {
-				return errors.Wrapf(err, "failed to set spdk_tgt log flags to %v, using setting %v", setting.Value, settingName)
-			}
+			if err != nil {
+				return errors.Wrapf(err, "failed to set %v to %v for setting %v", 
+					settingName == types.SettingNameLogLevel ? "log level" : "spdk_tgt log flags",
+					setting.Value, settingName)
+			}
+		case types.SettingNameV2DataEngineLogFlags:
+			if err := client.LogSetFlags(longhorn.DataEngineTypeV2, "spdk_tgt", setting.Value); err != nil {
+				return errors.Wrapf(err, "failed to set %v to %v for setting %v",
+					"spdk_tgt log flags", setting.Value, settingName)
+			}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5215c8d and 24d416d.

📒 Files selected for processing (1)
  • controller/instance_manager_controller.go (2 hunks)
🔇 Additional comments (1)
controller/instance_manager_controller.go (1)

535-535: LGTM: Generalized log level setting name

The change from engine-specific to a generic log level setting name improves the configurability across all Longhorn components.

Comment on lines 555 to +560
case types.SettingNameV2DataEngineLogFlags:
err = client.LogSetFlags(longhorn.DataEngineTypeV2, "spdk_tgt", setting.Value)
if err != nil {
return errors.Wrapf(err, "failed to set log flags for %v", settingName)
if types.IsDataEngineV2(im.Spec.DataEngine) {
err = client.LogSetFlags(longhorn.DataEngineTypeV2, "spdk_tgt", setting.Value)
if err != nil {
return errors.Wrapf(err, "failed to set spdk_tgt log flags to %v, using setting %v", setting.Value, settingName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we deprecating this setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the conclusion of the discussion yesterday. No need for granularity to set it separately for instance-manager and spdk_tgt. That will need to be updated in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, wait. We deprecated V2DataEngineLogLevel. LogFlags needs to remain. That is a separate feature of SPDK logging.

Comment on lines +546 to +551
case types.SettingNameLogLevel:
if types.IsDataEngineV1(im.Spec.DataEngine) {
err = client.LogSetLevel(longhorn.DataEngineTypeV1, "", setting.Value)
} else {
err = client.LogSetLevel(longhorn.DataEngineTypeV2, "", setting.Value)
}
Copy link
Contributor

@PhanLe1010 PhanLe1010 Nov 21, 2024

Choose a reason for hiding this comment

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

What about other components like UI, csi plugin, csi side car pod as mentioned at longhorn/longhorn#6702 (comment) ? Will we handle them in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be a separate PR, although less critical, since they don't log as heavily. It shouldn't gate this change.

@james-munson james-munson marked this pull request as ready for review November 21, 2024 22:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
controller/instance_manager_controller.go (1)

Line range hint 535-560: Consider adding validation for log level and flag values.

The implementation correctly handles both v1 and v2 data engines, but could benefit from validating the setting values before applying them.

Consider adding validation:

 case types.SettingNameLogLevel:
+    validLogLevels := []string{"info", "debug", "warn", "error"}
+    if !slices.Contains(validLogLevels, strings.ToLower(setting.Value)) {
+        return fmt.Errorf("invalid log level %v", setting.Value)
+    }
     if types.IsDataEngineV1(im.Spec.DataEngine) {
         err = client.LogSetLevel(longhorn.DataEngineTypeV1, "", setting.Value)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 24d416d and 29f95bf.

📒 Files selected for processing (1)
  • controller/instance_manager_controller.go (2 hunks)
🔇 Additional comments (3)
controller/instance_manager_controller.go (3)

546-551: LGTM! Clean implementation of data engine specific log level setting.

The code correctly differentiates between v1 and v2 data engines when setting log levels.


556-560: LGTM! V2-specific log flags handling.

The code correctly applies log flags only for v2 data engine.


Line range hint 577-580: LGTM! Appropriate error handling for log settings sync.

The integration properly handles log setting sync errors by logging them without blocking pod management, which is the correct approach for non-critical operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants