Skip to content
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

Merged
merged 10 commits into from
Mar 13, 2024
Merged

Conversation

matt2e
Copy link
Collaborator

@matt2e matt2e commented Mar 12, 2024

Fixes #1047
Fixes #1045

Changes ControllerKey and RunnerKey to have the format:

  • <r/c>-<hostname>-<port>-<4bytehex> for passing around
  • <hostname>-<port>-<4bytehex> in the db
  • non production environments use shorter keys: r-<incrementing-digits> and <incrementing digits> in db

@alecthomas alecthomas mentioned this pull request Mar 12, 2024
backend/controller/sql/types.go Show resolved Hide resolved
internal/model/keys.go Outdated Show resolved Hide resolved
internal/model/keys.go Outdated Show resolved Hide resolved
{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"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@matt2e matt2e force-pushed the matt2e/controller-runner-id-generation branch from 8cc2153 to 84cf1cf Compare March 12, 2024 23:38
@matt2e matt2e force-pushed the matt2e/controller-runner-id-generation branch from 86d1201 to 72a150e Compare March 13, 2024 00:32
@matt2e matt2e marked this pull request as ready for review March 13, 2024 00:32
@matt2e matt2e requested a review from alecthomas March 13, 2024 00:32
Copy link
Collaborator

@alecthomas alecthomas left a 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

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)
Copy link
Collaborator

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.

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))
Copy link
Collaborator

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.

case len(components) == 1:
//style: [<kind>-]<suffix>

suffix, err := strconv.Atoi(components[len(components)-1])
Copy link
Collaborator

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.

@matt2e
Copy link
Collaborator Author

matt2e commented Mar 13, 2024

@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.

@matt2e matt2e requested a review from alecthomas March 13, 2024 03:13
@matt2e matt2e merged commit e564ab1 into main Mar 13, 2024
11 checks passed
@matt2e matt2e deleted the matt2e/controller-runner-id-generation branch March 13, 2024 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update controller and runner ids Runners getting killed due to runner deployment directory clashes
2 participants