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

Code refactor: remove a function scope variable err for psi stats #3938

Closed
wants to merge 1 commit into from

Conversation

lifubang
Copy link
Member

Address #3900 (comment)

I think it's unnecessary to add a function scope variable suddenly. We should keep the code style like other cgroup stats.

Signed-off-by: lifubang <lifubang@acmcoder.com>
@lifubang
Copy link
Member Author

lifubang commented Jul 15, 2023

ci lint error:

Run golangci-lint run --config .golangci-extra.yml --new-from-rev=HEAD~1 --out-format=github-actions
  golangci-lint run --config .golangci-extra.yml --new-from-rev=HEAD~1 --out-format=github-actions
  shell: /usr/bin/bash -e {0}
  env:
    GO_VERSION: 1.[2](https://github.com/opencontainers/runc/actions/runs/5549548107/jobs/10133764716?pr=3938#step:6:2)0.x
Warning: var-naming: func statCpuPressure should be statCPUPressure (revive)
Error: Process completed with exit code 1.

The Extra linters are only checking new code from a pull request, it never check the old code, for example: isCpuSet, setCpu, and statCpu.
Shall we need to modify all other old code in the same file to meet the rules of extra linters? @thaJeztah @kolyshkin
I think the issue #3936 may facing the same problem.

@@ -91,3 +91,11 @@ func statCpu(dirPath string, stats *cgroups.Stats) error {
}
return nil
}

func statCpuPressure(dirPath string, stats *cgroups.Stats) error {
const file = "cpu.pressure"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would pass "cpu.pressure" directly, without adding an intermediary const. The const would make sense if we use it more than once, or if the value is complicated/long -- neither is the case here.

@kolyshkin
Copy link
Contributor

I'm neutral on this.

  • pro: GetStats looks more uniform now
  • contra: more code is added

Left a nit about using consts for file names, but overall LGTM

@kolyshkin
Copy link
Contributor

Re: linter, I think we can start naming things better (CPU not Cpu) in any new code (and also maybe rename the existing ones), but this is minor. Feel free to add //nolint:revive if you don't want to stick to what revive tells you.

@thaJeztah WDYT?

Comment on lines +195 to +201
func statIoPressure(dirPath string, stats *cgroups.Stats) error {
const file = "io.pressure"
var err error

stats.BlkioStats.PSI, err = statPSI(dirPath, file)
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rewrite this one to

func statIoPressure(dirPath string, stats *cgroups.Stats) (Err error) {
	stats.BlkioStats.PSI, Err = statPSI(dirPath, "io.pressure")
	return
}

Copy link
Contributor

Choose a reason for hiding this comment

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

but with this rewrite, it doesn't make much sense to have it as a separate function, right?

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

I don't think this makes the code much better than it is.

@kolyshkin kolyshkin closed this Jul 2, 2024
@lifubang lifubang deleted the refactor-psi branch October 15, 2024 05:51
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.

2 participants