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 Cgroup V1 block IO integration test #537

Merged
merged 4 commits into from
Dec 18, 2021
Merged

Conversation

YJDoc2
Copy link
Collaborator

@YJDoc2 YJDoc2 commented Dec 13, 2021

This adds Cgroups V1 block io integration test

@YJDoc2 YJDoc2 marked this pull request as draft December 13, 2021 15:18
@YJDoc2 YJDoc2 marked this pull request as ready for review December 13, 2021 15:19
@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Dec 13, 2021

The CI is likely to fail for the same reason as #528 (comment)
The test also give same error for youki on my local machine, but runc passes all the tests.
Once that issue is fixed, I'll run the tests on youki as well and update here.

@Furisto
Copy link
Collaborator

Furisto commented Dec 13, 2021

@YJDoc2 I fixed this problem here

@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Dec 13, 2021

Oh yes, I tested youki with that change and it passes the tests as well. I'm waiting for that PR to be merged so it will pass in the CI itself, and the I can ask for reviews. Thanks 👍

@codecov-commenter
Copy link

Codecov Report

Merging #537 (d05bb63) into main (667ef6a) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #537   +/-   ##
=======================================
  Coverage   60.52%   60.52%           
=======================================
  Files          98       98           
  Lines       12626    12626           
=======================================
  Hits         7642     7642           
  Misses       4984     4984           

Comment on lines 104 to 108
let weight_string = fs::read_to_string(format!("{}/blkio.weight", path))
.context("error in reading block io weight")?;
device.weight = weight_string
.parse()
.context("error in parsing block io weight")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let weight_string = fs::read_to_string(format!("{}/blkio.weight", path))
.context("error in reading block io weight")?;
device.weight = weight_string
.parse()
.context("error in parsing block io weight")?;
let weight_path = Path::new(path).join("blkio.weight");
let weight_string = fs::read_to_string(weight_path)
.with_context(|| format!("error in reading block io weight from {:?}", weight_path)?;
device.weight = weight_string
.parse()
.with_context(|| format!("error in parsing block io weight {:?}", weight_string))?;

There are a few more like this. You should include the full cgroup path that it attempted to read to make debugging easier.

Comment on lines 111 to 115
let leaf_weight_string = fs::read_to_string(format!("{}/blkio.leaf_weight", path))
.context("error in reading block io leaf weight")?;
device.leaf_weight = leaf_weight_string
.parse()
.context("error in parsing block io weight")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

for line in device_weight_string.lines() {
let (device_data, weight) = line
.split_once(" ")
.context("invalid weight device format")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.context("invalid weight device format")?;
with_context(|| format!("invalid weight device format: {}", line)?;

Again there are a few more instances of this. The general idea is that if you are parsing something and it fails you should include the value it tried to parse so that it is included in the output and you do not need to go hunting after the value on which it failed.

Comment on lines 210 to 215
let (device_data, rate) = line
.split_once(" ")
.context("invalid weight device format")?;
let (major_str, minor_str) = device_data
.split_once(":")
.context("invalid major-minor number format")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This snippet seems to be used a few times. Could be worth creating a method for this.

// weight ------
if supports_weight() {
if spec_block_io.weight().is_none() {
return Err(anyhow::anyhow!("spec block io weight is none"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return Err(anyhow::anyhow!("spec block io weight is none"));
bail!("spec block io weight is none");

A few more instances of this.

@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Dec 17, 2021

Hey, sorry for the mistakes 😅 😅
I had realized that the device reading code can be extracted into function, but forgot to do that before making commit and asking review 😅

I have fixed that, as well as improved error reporting as you have suggested. One of the issue that it caused is that we need to clone the path, as fs::read_to_string takes the path by value.

I'm not sure why read_to_string needs to take it by value, as I checked rust src, and it eventually calls as_ref on it, which needs only by ref, not by value... 🤔

Anyways, please take a look now, thanks :)

@Furisto
Copy link
Collaborator

Furisto commented Dec 17, 2021

I have fixed that, as well as improved error reporting as you have suggested. One of the issue that it caused is that we need to clone the path, as fs::read_to_string takes the path by value.

Can you point to a specific example? PathBuf implements AsRef so you should not need to clone it.

@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Dec 18, 2021

Can you point to a specific example? PathBuf implements AsRef so you should not need to clone it.

Yes you're right, I have been using it incorrectly 😓

I have removed the clone calls, so PTAL.

@Furisto
Copy link
Collaborator

Furisto commented Dec 18, 2021

Looks good! @utam0k Will this conflict with #514? If it does it might make more sense to merge yours first, as yours looks trickier to adapt to the changes than the other way around.

@utam0k
Copy link
Member

utam0k commented Dec 18, 2021

Looks good! @utam0k Will this conflict with #514? If it does it might make more sense to merge yours first, as yours looks trickier to adapt to the changes than the other way around.

Thank you for taking care of my pr. I still have a few things to do on that PR of mine, so you can merge this one first!

@Furisto Furisto merged commit fc70a5e into youki-dev:main Dec 18, 2021
@YJDoc2 YJDoc2 deleted the cgroups_blkio branch October 7, 2022 05:02
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.

4 participants