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

Punycode pipeline names #33

Merged
merged 2 commits into from
Nov 16, 2017
Merged

Conversation

rbvigilante
Copy link
Contributor

@rbvigilante rbvigilante commented Nov 16, 2017

We aren't necessarily amazing at Go, so apologies if we've done something anti-idiomatic.

This runs punycode over all pipeline names as metrics are collected, which should solve #32

@@ -196,7 +197,7 @@ func (c *Collector) addBuildAndJobMetrics(r *Result) error {
continue
}

pipeline := *build.Pipeline.Name
pipeline, _ := idna.ToASCII(*build.Pipeline.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a good idea to check this error and return it if it occurs! Who knows what dragons live here :)

@lox
Copy link
Contributor

lox commented Nov 16, 2017

This looks great! Thank you so much!

@@ -196,7 +197,7 @@ func (c *Collector) addBuildAndJobMetrics(r *Result) error {
continue
}

pipeline := *build.Pipeline.Name
pipeline, _ := idna.ToASCII(*build.Pipeline.Name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if we should be more worried about errors here. The only error case I can think of is malformed UTF-8, which seems like a minimal risk given that we've already read the string in to Go.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we do get an error it will result in a blank string for pipeline though, which will be a whole lot harder to troubleshoot than an explicit error.

Pipeline: &bk.Pipeline{Name: bk.String("vicuñas")},
State: bk.String("scheduled"),
Jobs: []*bk.Job{
{State: bk.String("scheduled"), AgentQueryRules: []string{"queue=default"}},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to the default queue because I couldn't find a way to add another; this means I had to change a bunch of other, unrelated numbers below. Is there a better way to do this?

Copy link
Contributor

Choose a reason for hiding this comment

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

That test needs some cleaning up to split apart those concerns, but I'm fine with it for now.

@rbvigilante rbvigilante force-pushed the punycode-pipeline-names branch from 25fb4a5 to 12d0b5b Compare November 16, 2017 02:23
pipeline, ucError := idna.ToASCII(*build.Pipeline.Name)

if ucError != nil {
return false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, not entirely sure what the idiomatic thing to do here is; I'm guessing false is a failure?

Copy link
Contributor

Choose a reason for hiding this comment

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

return ucError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That gives me

collector/collector.go:203:5: cannot use ucError (type error) as type bool in return argument

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies, code reading comprehension fail! I'd go for:

if usErr != nil {
   log.Printf("Error converting pipeline to ascii: %v", usErr)
   continue
}

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW err is usually idiomatic in golang.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just reading the code for better comprehension myself. I guess the other option would be to make the function passed into Pages return a bool, error instead of just a bool and handle it there. Then we can get what I think is the desired effect of a crash-out rather than just losing some metrics?

Copy link
Contributor

Choose a reason for hiding this comment

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

It absolutely could, but it probably should continue to process subsequent pipelines, which is why errors are handled elsewhere with continue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, so we'd prefer to just lose some metrics (which I guess is what will happen if we just log and continue? Forgive my ignorance if continue does something special to do with error handling in Go). Will amend now!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, that was generally my thinking. continue is just the usual for loop construct that will continue to the next loop iteration!

This prevents CloudWatch from complaining about pipelines with
non-ASCII characters in their names. We thought it made more sense to
do it on collection rather than in the backend to maintain consistency
of names across backends
@rbvigilante rbvigilante force-pushed the punycode-pipeline-names branch from 12d0b5b to 106a76d Compare November 16, 2017 03:43
@lox lox merged commit d79ac43 into buildkite:master Nov 16, 2017
@lox
Copy link
Contributor

lox commented Nov 16, 2017

Looks great! Thanks so much! I will get this into a new release of the elastic stack as quick as I can!

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