-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: keys include host-port-suffix #1071
Conversation
{key: NewRunnerKey("r-hostwithprefixandfakeport-80", "80"), strPrefix: "r-r-hostwithprefixandfakeport-80-80-", valuePrefix: "r-hostwithprefixandfakeport-80-80-"}, | ||
|
||
// Local Keys | ||
{key: NewLocalRunnerKey(0), str: "r-0000", value: "0000"}, |
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.
Nice
8cc2153
to
84cf1cf
Compare
86d1201
to
72a150e
Compare
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.
LGTM after changing the suffix to more bits of hex-encoded randomness
internal/model/keys.go
Outdated
if d.Hostname == "" { | ||
return fmt.Sprintf("%s%04d", prefix, d.Suffix) | ||
} | ||
return fmt.Sprintf("%s%s-%s-%04d", prefix, d.Hostname, d.Port, d.Suffix) |
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.
Let's hex encode the suffix with %08x
so it's consistent with DeploymentName.
internal/model/keys.go
Outdated
func NewControllerKey() ControllerKey { return ControllerKey(ulid.Make()) } | ||
func ParseControllerKey(key string) (ControllerKey, error) { return parseKey[ControllerKey](key) } | ||
func NewControllerKey(hostname string, port string) ControllerKey { | ||
suffix, err := rand.Int(rand.Reader, big.NewInt(10000)) |
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.
Let's use 4 bytes (4294967296) of randomness so it's more consistent with DeploymentName.
internal/model/keys.go
Outdated
case len(components) == 1: | ||
//style: [<kind>-]<suffix> | ||
|
||
suffix, err := strconv.Atoi(components[len(components)-1]) |
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.
When you switch to hex encoding you can use strconv.ParseInt()
with a base of 16 here.
@alecthomas i switched to 4 bytes of randomness in production keys, moved Suffix to being a string so it can hold hex or incremental ints, and now we can have 0 based indexes again. |
Fixes #1047
Fixes #1045
Changes
ControllerKey
andRunnerKey
to have the format:<r/c>-<hostname>-<port>-<4bytehex>
for passing around<hostname>-<port>-<4bytehex>
in the dbr-<incrementing-digits>
and<incrementing digits>
in db