-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use hashing to distribute node checks
instead of querying all (valid) neighbouring pods, we filter and only query KUBENURSE_NEIGHBOUR_LIMIT other neighbours. To make sure that all nodes get the right number of queries, we hash each node name, put that in a sorted list (l), and each pod will query the e.g. 10 next nodes in the list, starting from the position given by the node name' hash. i.e. for node named n, we query the 10 next nodes in the list, starting from position l[hash(n)] + 1 cf #55 Signed-off-by: Clément Nussbaumer <[email protected]>
- Loading branch information
1 parent
4fa4b9f
commit a0b49bb
Showing
6 changed files
with
130 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,62 @@ | ||
package servicecheck | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func generateNeighbours(n int) (nh []*Neighbour) { | ||
|
||
nh = make([]*Neighbour, 0, n) | ||
|
||
for i := range n { | ||
nodeName := fmt.Sprintf("a1-k8s-abcd%03d.domain.tld", i) | ||
neigh := Neighbour{ | ||
NodeName: nodeName, | ||
NodeHash: sha256String(nodeName), | ||
} | ||
nh = append(nh, &neigh) | ||
} | ||
|
||
return | ||
} | ||
|
||
func TestNodeFiltering(t *testing.T) { | ||
|
||
n := 1_000 | ||
neighbourLimit := 10 | ||
nh := generateNeighbours(n) | ||
require.NotNil(t, nh) | ||
|
||
trueOsHostname := osHostname | ||
defer func() { osHostname = trueOsHostname }() | ||
|
||
// fake client, with a dummy neighbour pod | ||
// fakeClient := fake.NewFakeClient(&fakeNeighbourPod) | ||
checker := Checker{ | ||
NeighbourLimit: neighbourLimit, | ||
} | ||
|
||
t.Run("all nodes should get NEIGHBOUR_LIMIT checks", func(t *testing.T) { | ||
counter := make(map[string]int, n) | ||
|
||
for i := range n { | ||
osHostname = func() (name string, err error) { | ||
return nh[i].NodeName, nil | ||
} | ||
filtered := checker.filterNeighbours(nh) | ||
require.Equal(t, neighbourLimit, len(filtered)) | ||
|
||
for _, neigh := range filtered { | ||
counter[neigh.NodeName]++ | ||
} | ||
} | ||
|
||
for _, count := range counter { | ||
require.Equal(t, neighbourLimit, count, "one node didn't receive exactly NEIGHBOUR_LIMIT checks") | ||
} | ||
|
||
}) | ||
} |
This file contains 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