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

Move some code around #70

Merged
merged 4 commits into from
Jan 29, 2023

Conversation

gabriel-samfira
Copy link
Member

This change is just a couple of small fixes and moving some code around.

  • metrics are moved to its own package
  • the short ID is sanitized to replace hyphens and dashes with alphanumeric characters
  • the runner prefix is now displayed properly in pool show

Move the metrics code into its own package.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
On some providers the default character set used by shortid may lead to
errors when creating runners, due to the fact that underscores are not
allowed in their names.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
@gabriel-samfira
Copy link
Member Author

@maigl Moved the metrics stuff in a dedicated package. Also made some really small changes here and there. Functionally it should be the same. Let me know if you see any issues with any of this.

@gabriel-samfira
Copy link
Member Author

@maigl apropos, the webhooksReceived.WithLabelValues() function can panic 😄 .Replaced it with webhooksReceived.GetMetricWithLabelValues().

util/util.go Outdated
Comment on lines 355 to 356
newID = strings.Replace(newID, "_", randomCharacter(), -1)
newID = strings.Replace(newID, "-", randomCharacter(), -1)
Copy link
Contributor

@maigl maigl Jan 29, 2023

Choose a reason for hiding this comment

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

I'm no expert here. But I assume that this might compromise the uniqueness of the ids?! You can define the alphabet within the shortid lib, but if you remove '-' and '_', but it what other chars instead.
https://github.com/teris-io/shortid/blob/master/shortid.go#L85
The algorithm seems to always want 64 distinct chars. But I thought replacing '_' and '-' by '%' and '$' is not much better .. we could use some unicode 😄 here or kanjis

I really would want to avoid some non-unique issue here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I really would want to avoid some non-unique issue here.

indeed. It erred out on OpenStack when the name included an underscore 😄. The need for 64 unique characters leaves us with few options. We can leave the hyphen and maybe add a + ? Something that has a lowest chance of failing anywhere garm may be used. Will have to look at the other clouds and what limitations there are in regards to names.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove this hack as it made my eye twitch as well when I wrote it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Funny.. my openstack is fine with '_'

Copy link
Member Author

Choose a reason for hiding this comment

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

ohh wait. My bad. The error was on LXD:

Jan 27 14:18:20 garm garm[11696]: 2023/01/27 14:18:20 failed to add instance to provider: creating instance: creating instance: creating instance: Invalid instance name: Name can only contain alphanumeric and hyphen characters

The same thing seems to be true for Azure:

https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules (underscores are not allowed)

From the Azure docs above, in regards to VirtualMachines:

Can't use spaces, control characters, or these characters:
~ ! @ # $ % ^ & * ( ) = + _ [ ] { } \ | ; : . ' " , < > / ?

Windows VMs can't include period or end with hyphen.

Linux VMs can't end with period or hyphen.

Which is depressing. Need to find a way to get around this.

Copy link
Contributor

Choose a reason for hiding this comment

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

but base 64 contains '/' and '+' and also '=' for padding at the end.

I also like the shortid though, 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

base 62 does not 😄 should be alphanumeric (including upper/lower case)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like this:

Screenshot from 2023-01-29 17-51-27

Copy link
Contributor

Choose a reason for hiding this comment

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

okay .. never heard of that ;)
sgtm

Comment on lines 98 to 100
c.mux.Lock()
defer c.mux.Unlock()
c.cachedControllerInfo = controllerInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this cached here again? This will only help if runner.GetControllerInfo fails but did work some rounds before, right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The os.Hostname() call can fail, which means we'll end up with no hostname when it does. At least for that call. The cache is to fall back on previous value. What I dislike is that I had to duplicate this in 2 places. I Think I'll add a retry strategy instead and remove the cache.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd still like to know when something fails and react accordingly, than to ignore the error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the caches and just added a retry in GetControllerInfo(). If it errs there, we just surface that error further along and log it.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
@gabriel-samfira gabriel-samfira merged commit 1867bba into cloudbase:main Jan 29, 2023
@gabriel-samfira gabriel-samfira deleted the move-some-code-around branch January 30, 2023 16:18
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.

2 participants