-
Notifications
You must be signed in to change notification settings - Fork 36
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
Too high probability of name collision in getNameFromConnection #1589
Comments
Unfortunately, #1590 created its own problems. Although it reduced the name collision probability, it also broke some functionality. Some problems are: (1) in update situations where both old and new nsm versions are an play, we can have a mixed bag of old and new conventions. (2) Looking at A solution would be to retain the old naming convention (e.g., |
@olahg Which 90-character alphabet? I ask, because I get a bit nervous when we start using punctuation :) |
The alphabet defined here: sdk/pkg/tools/nanoid/generator.go Line 29 in e3eed82
|
@olahg I'd be very cautious about the punctuation marks... very high probability to cause problems, and absolute certainty to be a usability nightmare for cli users. Would [a-z][A-Z][0-9] (size 62) be sufficient? |
Hello, @edwarnicke, @olahg I found that the old version of the iface ID generation is about 10 times worse than the current solution. Test proof: func limitName(name string) string {
if len(name) > kernelmech.LinuxIfMaxLength {
return name[:kernelmech.LinuxIfMaxLength]
}
return name
}
func getNameFromConnection(ns string) string {
nsMaxLength := kernelmech.LinuxIfMaxLength - 5
if len(ns) > nsMaxLength {
ns = ns[:nsMaxLength]
}
name := fmt.Sprintf("%s-%s", ns, uuid.New().String())
return limitName(name)
}
func TestNoCollisions_Old(t *testing.T) {
used := make(map[string]bool)
for i := 0; i < 50*1000; i++ {
id := getNameFromConnection("lb-fe-a.tr")
_, ok := used[id]
require.False(t, ok, "Collision detected for id: %s, %d", id, i)
used[id] = true
}
}
func TestNoCollisions_New(t *testing.T) {
used := make(map[string]bool)
for i := 0; i < 50*1000; i++ {
id, err := nanoid.GenerateString(4)
require.NoError(t, err)
id = "lb-fe-a.tr-" + id
_, ok := used[id]
require.False(t, ok, "Collision detected for id: %s, %d", id, i)
used[id] = true
}
} Now we're using the Thoughts? |
Yes, this seems to be sufficient. |
I just tested this alphabet So I think that we should go with #1644 because it will allow to update to the latest NSM sdk. |
@denis-tingaikin, I'm not sure what is meant by "10 times better" or "2 times better". Can you clarify? |
@olahg Sure. When I used alphabet that you liked
It's 2 times better by collision probability. (This means, that a collision is less likely compared to the previous solution.) With current alphabet
It's 10 times better by collision probability. (This means, that a collision is less likely compared to the previous solution.) |
I also added comments in PR #1644 to clarify this point. |
We are using 4 interfaces in a pod; and the names generated are like this:
lb-fe-a.tr-626b
.We expect the probability of a name collision to be very low. Currently, it is 0.00018, which is kind of low, but not very low. After thousands of runs we do get collisions. Soon, our use case will demand that we'll have many more interfaces, in which case this probability becomes too high, e.g., for 30 interfaces the collision probability is about 0.013 (above 1 percent).
Our understanding is that names are generated here:
https://github.com/networkservicemesh/sdk/blob/main/pkg/networkservice/common/mechanisms/kernel/utils.go#L30
The collision probability could be lowered by either having a longer random suffix or using a wider alphabet for the random suffix or both. E.g., the name could be something like
lb-fe-a.tr3Q@xn
The text was updated successfully, but these errors were encountered: