-
Notifications
You must be signed in to change notification settings - Fork 435
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 cgroups v2 support to resourcemanager #1744
Changes from 1 commit
5c1d6c7
0009f06
232ded2
42a4693
7146e9e
bace811
33f6343
89acabd
a007e25
325566f
56a6f11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,52 +6,57 @@ package resourcemanager | |
import ( | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func updateFakeCgroupv1Files(c *cgroupsV1MemoryLimitChecker, limit, usage, inactive int) error { | ||
limitFile, err := os.Create(c.limitFile) | ||
func updateFakeCgroupFiles(c *cgroupsMemoryLimitChecker, limit, usage, inactive int) error { | ||
limitFile, err := os.Create(c.files.limitFile) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = fmt.Fprintf(limitFile, "%d\n", limit) | ||
if err != nil { | ||
if _, err = fmt.Fprintf(limitFile, "%d\n", limit); err != nil { | ||
return err | ||
} | ||
|
||
usageFile, err := os.Create(c.usageFile) | ||
usageFile, err := os.Create(c.files.usageFile) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = fmt.Fprintf(usageFile, "%d\n", usage) | ||
if err != nil { | ||
if _, err = fmt.Fprintf(usageFile, "%d\n", usage); err != nil { | ||
return err | ||
} | ||
|
||
statsFile, err := os.Create(c.statsFile) | ||
statsFile, err := os.Create(c.files.statsFile) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = fmt.Fprintf(statsFile, `total_cache 1029980160 | ||
if _, err = fmt.Fprintf(statsFile, `total_cache 1029980160 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: _, err = .... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
total_rss 1016209408 | ||
total_inactive_file %d | ||
total_active_file 321544192 | ||
`, inactive) | ||
if err != nil { | ||
`, inactive); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func TestCgroupsv1MemoryLimit(t *testing.T) { | ||
func TestCgroupsMemoryLimit(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test basically has duplicate code for 3 subtests. You can just describe each as a test-case and de-duplicate the code. (Sorry overlooked on the first review). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
cgroupDir := t.TempDir() | ||
c := newCgroupsV1MemoryLimitChecker(cgroupDir, 95) | ||
testFiles := cgroupsMemoryFiles{ | ||
limitFile: cgroupDir + "/memory.limit_in_bytes", | ||
usageFile: cgroupDir + "/memory.usage_in_bytes", | ||
statsFile: cgroupDir + "/memory.stat", | ||
inactiveRe: regexp.MustCompile(`total_inactive_file (\d+)`), | ||
} | ||
|
||
c := newCgroupsMemoryLimitChecker(testFiles, 95) | ||
_, err := c.isLimitExceeded() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: inline. Same below if _, err := ... ; err == nil { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if err == nil { | ||
t.Error("Should fail open if can't read files") | ||
} | ||
|
||
err = updateFakeCgroupv1Files(c, 1000, 1000, 51) | ||
err = updateFakeCgroupFiles(c, 1000, 1000, 51) | ||
if err != nil { | ||
t.Error(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When errors are not nil, there's probably no use of continuing the test, so this should be Fatal instead. Same below/up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I had used the wrong one by mistake. |
||
} | ||
|
@@ -63,7 +68,7 @@ func TestCgroupsv1MemoryLimit(t *testing.T) { | |
t.Error("Expected under limit") | ||
} | ||
|
||
err = updateFakeCgroupv1Files(c, 1000, 1000, 50) | ||
err = updateFakeCgroupFiles(c, 1000, 1000, 50) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
@@ -74,5 +79,4 @@ func TestCgroupsv1MemoryLimit(t *testing.T) { | |
if !exceeded { | ||
t.Error("Expected over limit") | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I've mentioned in original review where this was introduced, please return concrete type here, as returning interfaces are not idiomatic in Go. You can change this function to:
Then in the call site you can call this, check with error.Is(err, errNotSupported) to instantiate trivialLimitChecker{} when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored it as suggested.