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): separate methods for internal and SPDK logging setting #726

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:

Separate the setting of instance-manager log level from that for v2 data engine (spdk_tgt).

Special notes for your reviewer:

Additional documentation or context

Copy link

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request introduces modifications to the logging functionality within the pkg/instance/log.go file. A new method, LogSetLevel, is added to the V1DataEngineInstanceOps struct, enabling log level adjustments for the instance manager across different engine types. The existing LogSetLevel method for V2DataEngineInstanceOps is updated to streamline log level handling and improve error messaging. Overall, the changes enhance the clarity and functionality of log level management for various data engines.

Changes

File Change Summary
pkg/instance/log.go - Added LogSetLevel method to V1DataEngineInstanceOps.
- Modified LogSetLevel method for V2DataEngineInstanceOps to remove SPDK-specific checks and improve error handling.
- Updated comments for clarity.

Assessment against linked issues

Objective Addressed Explanation
Configure the log level of other system and user managed components (6702)

Possibly related PRs

  • fix(logging): handle RPC call to set V1 log level #717: The changes in this PR also modify the LogSetLevel method for both V1DataEngineInstanceOps and V2DataEngineInstanceOps in the same pkg/instance/log.go file, focusing on logging functionality and error handling, which directly relates to the modifications made in the main PR.

Suggested reviewers

  • shuo-wu
  • derekbit

Warning

Rate limit exceeded

@james-munson has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 43 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f0141ff and 72cd9ae.

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package qcow: could not load export data: no export data for "github.com/longhorn/longhorn-engine/pkg/qcow""
level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package qcow: could not load export data: no export data for "github.com/longhorn/longhorn-engine/pkg/qcow""


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f0141ff and 72cd9ae.

📒 Files selected for processing (1)
  • pkg/instance/log.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/instance/log.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 (3)
pkg/instance/log.go (3)

Line range hint 46-53: LGTM! Consider enhancing the documentation.

The implementation correctly separates the instance-manager logging from SPDK logging. The method is well-structured and handles errors appropriately.

Consider adding a code example in the comment to show the expected log level format:

-// This method is used to set instance-manager internal log level regardless of engine type.
+// This method is used to set instance-manager internal log level regardless of engine type.
+// Example: req.Level should be one of "debug", "info", "warn", "error", etc.

Line range hint 46-70: Consider future logging enhancements.

The current implementation successfully separates instance-manager and SPDK logging. For future improvements, consider:

  1. Adding metrics/monitoring for log level changes
  2. Implementing a mechanism to persist log level settings across restarts
  3. Adding an audit trail for logging configuration changes

This would further enhance the logging management capabilities requested in issue #6702.


Add validation for SPDK log levels.

Based on the SPDK client implementation, we should validate the log levels before making the SPDK client call. The supported SPDK log levels are: "disabled", "error", "warn", "notice", "info", "debug" (default is "notice").

func (ops V2DataEngineInstanceOps) LogSetLevel(ctx context.Context, req *rpc.LogSetLevelRequest) (resp *emptypb.Empty, err error) {
	spdkLevel := strings.ToUpper(req.Level)

+	// Validate SPDK log levels
+	validLevels := map[string]bool{
+		"DISABLED": true,
+		"ERROR":    true,
+		"WARN":     true,
+		"NOTICE":   true,
+		"INFO":     true,
+		"DEBUG":    true,
+	}
+	if !validLevels[spdkLevel] {
+		return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "invalid SPDK log level: %s. Supported levels are: disabled, error, warn, notice, info, debug", req.Level)
+	}

	c, err := spdkclient.NewSPDKClient(ops.spdkServiceAddress)
🔗 Analysis chain

Line range hint 55-70: Add validation for SPDK log levels.

While the implementation correctly handles the SPDK log level setting, it would be beneficial to validate the input before making the SPDK client call.

Consider adding validation:

 func (ops V2DataEngineInstanceOps) LogSetLevel(ctx context.Context, req *rpc.LogSetLevelRequest) (resp *emptypb.Empty, err error) {
 	spdkLevel := strings.ToUpper(req.Level)
+	// Validate SPDK log levels
+	validLevels := map[string]bool{
+		"ERROR": true,
+		"WARN":  true,
+		"INFO":  true,
+		"DEBUG": true,
+	}
+	if !validLevels[spdkLevel] {
+		return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "invalid log level for v2 data engine: %s", spdkLevel)
+	}

Let's verify the supported SPDK log levels:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for SPDK log level definitions or usage
rg -A 5 'log.*level.*spdk|spdk.*log.*level' --type cpp --type c

Length of output: 65


Script:

#!/bin/bash
# Let's check the SPDK client implementation to understand the log levels
ast-grep --pattern 'func LogSetLevel($$$)'

# Also check for any constants or documentation about log levels
rg -i "log.*level" -A 5 -B 5

Length of output: 135238


Script:

#!/bin/bash
# Let's check the SPDK client implementation to understand the supported log levels
ast-grep --pattern 'func ($name) LogSetLevel($$$)'

# Also check for any SPDK log level constants or documentation
rg -i "spdk.*log.*level" -A 3 -B 3

Length of output: 23593

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cca5967 and f0141ff.

📒 Files selected for processing (1)
  • pkg/instance/log.go (3 hunks)
🔇 Additional comments (1)
pkg/instance/log.go (1)

67-67: LGTM! Improved error message clarity.

The error message now clearly indicates that this is related to the v2 data engine, which improves debuggability.

@james-munson james-munson changed the title fix(logging) separate methods for internal and SPDK logging setting fix(logging): separate methods for internal and SPDK logging setting Nov 26, 2024
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.

1 participant