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

feat: add func BdevGetIostat #192

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

hookak
Copy link
Contributor

@hookak hookak commented Feb 25, 2025

Which issue(s) this PR fixes:

longhorn/longhorn#10472

Copy link

coderabbitai bot commented Feb 25, 2025

Warning

Rate limit exceeded

@derekbit has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 32 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 d5274fc and 77616cd.

📒 Files selected for processing (2)
  • pkg/spdk/client/basic.go (1 hunks)
  • pkg/spdk/types/bdev.go (1 hunks)

Walkthrough

The changes introduce a new method BdevGetIostat to the Client struct, which allows for the retrieval of I/O statistics for block devices. This method constructs a request with optional parameters, sends it using jsonCli.SendCommand, and processes the response by unmarshalling the resulting JSON. Additionally, new types (BdevIostatRequest, BdevIostatResponse, and BdevStats) are added to facilitate the structure and handling of I/O statistics data.

Changes

File(s) Changes Summary
pkg/spdk/client/basic.go Added method BdevGetIostat to the Client struct. This method constructs a BdevIostatRequest, sends a "bdev_get_iostat" command via jsonCli.SendCommand, and unmarshals the response into a BdevIostatResponse.
pkg/spdk/types/bdev.go Added new types: BdevIostatRequest, BdevIostatResponse, and BdevStats for managing and representing block device I/O statistics.

Sequence Diagram(s)

sequenceDiagram
    participant U as User/Caller
    participant C as Client
    participant J as JSON Client (jsonCli)
    
    U->>C: Call BdevGetIostat(name, perChannel)
    C->>J: Construct and send "bdev_get_iostat" request
    J-->>C: Return JSON output or error
    C->>C: Unmarshal JSON into BdevIostatResponse
    C-->>U: Return response and error (if any)
Loading

Suggested Reviewers

  • derekbit
  • c3y1huang
  • shuo-wu

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 generate docstrings to generate docstrings for this 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

🧹 Nitpick comments (1)
pkg/spdk/types/bdev.go (1)

149-163: Add documentation comments for BdevStats fields.

While the struct is well-defined, adding documentation for each field would improve code maintainability and make it easier for users to understand what each statistic represents.

Example of improved documentation:

 type BdevStats struct {
+    // Name is the identifier of the block device
     Name              string `json:"name"`
+    // BytesRead is the total number of bytes read from the device
     BytesRead         uint64 `json:"bytes_read"`
+    // NumReadOps is the count of read operations performed
     NumReadOps        uint64 `json:"num_read_ops"`
     // Continue documenting other fields...
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eabe34a and 5a30bb5.

📒 Files selected for processing (2)
  • pkg/spdk/client/basic.go (1 hunks)
  • pkg/spdk/types/bdev.go (1 hunks)
🔇 Additional comments (3)
pkg/spdk/client/basic.go (1)

1317-1339: Well-implemented method for retrieving block device I/O statistics.

The BdevGetIostat method properly implements the functionality to retrieve I/O statistics for block devices. Good job providing clear documentation for the parameters and properly handling potential errors.

pkg/spdk/types/bdev.go (2)

139-142: Clean type definition for BdevIostatRequest.

The struct is well-defined with appropriate JSON tags, following the project's conventions.


144-147: Good response structure design.

The BdevIostatResponse type properly encapsulates the response data with the tick rate and a collection of device statistics.

@hookak hookak force-pushed the LH10472_v2_volume_metrics branch from 5a30bb5 to 8c9f9d4 Compare February 25, 2025 15:30
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

🧹 Nitpick comments (1)
pkg/spdk/client/basic.go (1)

1317-1339: Ensure consistent error handling with the rest of the codebase

The implementation is functional, but the error handling style differs slightly from other methods in the file.

Consider using the errors.Wrapf function from the "github.com/pkg/errors" package for consistency with other methods in the file:

 func (c *Client) BdevGetIostat(name string, perChannel bool) (resp *spdktypes.BdevIostatResponse, err error) {
 	req := spdktypes.BdevIostatRequest{
 		Name:       name,
 		PerChannel: perChannel,
 	}

 	cmdOutput, err := c.jsonCli.SendCommand("bdev_get_iostat", req)
 	if err != nil {
-		return nil, fmt.Errorf("failed to execute bdev_get_iostat: %v", err)
+		return nil, errors.Wrapf(err, "failed to execute bdev_get_iostat")
 	}

 	resp = &spdktypes.BdevIostatResponse{}
 	if err := json.Unmarshal(cmdOutput, resp); err != nil {
-		return nil, fmt.Errorf("failed to parse bdev_get_iostat response: %v", err)
+		return nil, errors.Wrapf(err, "failed to parse bdev_get_iostat response")
 	}

 	return resp, nil
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a30bb5 and 8c9f9d4.

📒 Files selected for processing (2)
  • pkg/spdk/client/basic.go (1 hunks)
  • pkg/spdk/types/bdev.go (1 hunks)
🔇 Additional comments (4)
pkg/spdk/types/bdev.go (3)

139-142: Well-defined request structure

The new BdevIostatRequest type is correctly structured with appropriate JSON tags and optional fields marked with omitempty, following the pattern of other request types in this file.


144-148: Clear response structure design

The BdevIostatResponse type properly captures the expected response format with TickRate, Ticks, and an array of BdevStats.


150-164: Comprehensive statistics structure

The BdevStats type thoroughly captures all relevant I/O metrics including read/write operations, bytes transferred, latency measurements, and queue depths.

pkg/spdk/client/basic.go (1)

1319-1322: Clear documentation for the method

The documentation clearly explains the purpose and parameters of the method, following the same style as other methods in the file.

derekbit
derekbit previously approved these changes Feb 27, 2025
Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM

Bdevs []BdevStats `json:"bdevs"`
}

type BdevStats struct {
Copy link
Member

Choose a reason for hiding this comment

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

WriteLatencyTicks uint64 `json:"write_latency_ticks"`
UnmapLatencyTicks uint64 `json:"unmap_latency_ticks"`
QueueDepth uint64 `json:"queue_depth"`
IoTime uint64 `json:"io_time"`
Copy link
Member

Choose a reason for hiding this comment

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

@hookak What is io_time and weighted_io_time in the stat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@derekbit weighted_io_time is the sum of all I/O request execution times, calculated as I/O execution time × queue depth.
This link will help with understanding(https://github.com/spdk/spdk/blob/e01cb43b8578f9155d07a9bc6eee4e70a3af96b0/include/spdk/bdev.h#L1052-L1068)

Copy link
Member

Choose a reason for hiding this comment

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

Good to know. Thank you @hookak.

@derekbit
Copy link
Member

cc @c3y1huang @shuo-wu @PhanLe1010 for review.

@hookak hookak force-pushed the LH10472_v2_volume_metrics branch from 7de4084 to d5274fc Compare February 27, 2025 03:55
Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the contribution.

@derekbit
Copy link
Member

CI failed due to the zypper package installation. I will manage to resolve it soon.

@derekbit derekbit force-pushed the LH10472_v2_volume_metrics branch from d5274fc to 77616cd Compare February 27, 2025 07:09
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 22.46%. Comparing base (203be6c) to head (77616cd).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/spdk/client/basic.go 0.00% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
- Coverage   22.52%   22.46%   -0.07%     
==========================================
  Files          34       34              
  Lines        5007     5022      +15     
==========================================
  Hits         1128     1128              
- Misses       3702     3717      +15     
  Partials      177      177              
Flag Coverage Δ
unittests 22.46% <0.00%> (-0.07%) ⬇️

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.

@derekbit derekbit merged commit 6cca30b into longhorn:main Feb 27, 2025
5 of 9 checks passed
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