-
Notifications
You must be signed in to change notification settings - Fork 886
Add knobs on LB sandbox #2154
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
Merged
Merged
Add knobs on LB sandbox #2154
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,23 @@ | ||
| package overlay | ||
|
|
||
| import ( | ||
| "io/ioutil" | ||
| "path" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| "github.com/docker/libnetwork/osl/kernel" | ||
| ) | ||
|
|
||
| type conditionalCheck func(val1, val2 string) bool | ||
|
|
||
| type osValue struct { | ||
| value string | ||
| checkFn conditionalCheck | ||
| } | ||
|
|
||
| var osConfig = map[string]osValue{ | ||
| var ovConfig = map[string]*kernel.OSValue{ | ||
| "net.ipv4.neigh.default.gc_thresh1": {"8192", checkHigher}, | ||
| "net.ipv4.neigh.default.gc_thresh2": {"49152", checkHigher}, | ||
| "net.ipv4.neigh.default.gc_thresh3": {"65536", checkHigher}, | ||
| } | ||
|
|
||
| func propertyIsValid(val1, val2 string, check conditionalCheck) bool { | ||
| if check == nil || check(val1, val2) { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func checkHigher(val1, val2 string) bool { | ||
| val1Int, _ := strconv.ParseInt(val1, 10, 32) | ||
| val2Int, _ := strconv.ParseInt(val2, 10, 32) | ||
| return val1Int < val2Int | ||
| } | ||
|
|
||
| // writeSystemProperty writes the value to a path under /proc/sys as determined from the key. | ||
| // For e.g. net.ipv4.ip_forward translated to /proc/sys/net/ipv4/ip_forward. | ||
| func writeSystemProperty(key, value string) error { | ||
| keyPath := strings.Replace(key, ".", "/", -1) | ||
| return ioutil.WriteFile(path.Join("/proc/sys", keyPath), []byte(value), 0644) | ||
| } | ||
|
|
||
| func readSystemProperty(key string) (string, error) { | ||
| keyPath := strings.Replace(key, ".", "/", -1) | ||
| value, err := ioutil.ReadFile(path.Join("/proc/sys", keyPath)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return string(value), nil | ||
| } | ||
|
|
||
| func applyOStweaks() { | ||
| for k, v := range osConfig { | ||
| // read the existing property from disk | ||
| oldv, err := readSystemProperty(k) | ||
| if err != nil { | ||
| logrus.Errorf("error reading the kernel parameter %s, error: %s", k, err) | ||
| continue | ||
| } | ||
|
|
||
| if propertyIsValid(oldv, v.value, v.checkFn) { | ||
| // write new prop value to disk | ||
| if err := writeSystemProperty(k, v.value); err != nil { | ||
| logrus.Errorf("error setting the kernel parameter %s = %s, (leaving as %s) error: %s", k, v.value, oldv, err) | ||
| continue | ||
| } | ||
| logrus.Debugf("updated kernel parameter %s = %s (was %s)", k, v.value, oldv) | ||
| } | ||
| } | ||
| kernel.ApplyOSTweaks(ovConfig) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package kernel | ||
|
|
||
| type conditionalCheck func(val1, val2 string) bool | ||
|
|
||
| // OSValue represents a tuple, value defired, check function when to apply the value | ||
| type OSValue struct { | ||
| Value string | ||
| CheckFn conditionalCheck | ||
| } | ||
|
|
||
| func propertyIsValid(val1, val2 string, check conditionalCheck) bool { | ||
| if check == nil || check(val1, val2) { | ||
| return true | ||
| } | ||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package kernel | ||
|
|
||
| import ( | ||
| "io/ioutil" | ||
| "path" | ||
| "strings" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| // writeSystemProperty writes the value to a path under /proc/sys as determined from the key. | ||
| // For e.g. net.ipv4.ip_forward translated to /proc/sys/net/ipv4/ip_forward. | ||
| func writeSystemProperty(key, value string) error { | ||
| keyPath := strings.Replace(key, ".", "/", -1) | ||
| return ioutil.WriteFile(path.Join("/proc/sys", keyPath), []byte(value), 0644) | ||
| } | ||
|
|
||
| // readSystemProperty reads the value from the path under /proc/sys and returns it | ||
| func readSystemProperty(key string) (string, error) { | ||
| keyPath := strings.Replace(key, ".", "/", -1) | ||
| value, err := ioutil.ReadFile(path.Join("/proc/sys", keyPath)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return strings.TrimSpace(string(value)), nil | ||
| } | ||
|
|
||
| // ApplyOSTweaks applies the configuration values passed as arguments | ||
| func ApplyOSTweaks(osConfig map[string]*OSValue) { | ||
| for k, v := range osConfig { | ||
| // read the existing property from disk | ||
| oldv, err := readSystemProperty(k) | ||
| if err != nil { | ||
| logrus.WithError(err).Errorf("error reading the kernel parameter %s", k) | ||
| continue | ||
| } | ||
|
|
||
| if propertyIsValid(oldv, v.Value, v.CheckFn) { | ||
| // write new prop value to disk | ||
| if err := writeSystemProperty(k, v.Value); err != nil { | ||
| logrus.WithError(err).Errorf("error setting the kernel parameter %s = %s, (leaving as %s)", k, v.Value, oldv) | ||
| continue | ||
| } | ||
| logrus.Debugf("updated kernel parameter %s = %s (was %s)", k, v.Value, oldv) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package kernel | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| _ "github.com/docker/libnetwork/testutils" | ||
| ) | ||
|
|
||
| func TestReadWriteKnobs(t *testing.T) { | ||
| for _, k := range []string{ | ||
| "net.ipv4.neigh.default.gc_thresh1", | ||
| "net.ipv4.neigh.default.gc_thresh2", | ||
| "net.ipv4.neigh.default.gc_thresh3", | ||
| } { | ||
| // Check if the test is able to read the value | ||
| v, err := readSystemProperty(k) | ||
| if err != nil { | ||
| logrus.WithError(err).Warnf("Path %v not readable", k) | ||
| // the path is not there, skip this key | ||
| continue | ||
| } | ||
| // Test the write | ||
| assert.NoError(t, writeSystemProperty(k, "10000")) | ||
| newV, err := readSystemProperty(k) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, newV, "10000") | ||
| // Restore value | ||
| assert.NoError(t, writeSystemProperty(k, v)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // +build !linux | ||
|
|
||
| package kernel | ||
|
|
||
| // ApplyOSTweaks applies the configuration values passed as arguments | ||
| func ApplyOSTweaks(osConfig map[string]*OSValue) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 long as we are touching this ... do we want to add a debug log when we don't update a property to indicate why? Something like:
Just a thought.