Skip to content

Commit

Permalink
Merge pull request #33 from rbvigilante/punycode-pipeline-names
Browse files Browse the repository at this point in the history
Punycode pipeline names
  • Loading branch information
lox authored Nov 16, 2017
2 parents 3a440c0 + 106a76d commit d79ac43
Show file tree
Hide file tree
Showing 34 changed files with 21,778 additions and 14 deletions.
8 changes: 7 additions & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"regexp"
"time"

"golang.org/x/net/idna"
bk "gopkg.in/buildkite/go-buildkite.v2/buildkite"
)

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

pipeline := *build.Pipeline.Name
pipeline, ucErr := idna.ToASCII(*build.Pipeline.Name)

if ucErr != nil {
log.Printf("Error converting pipeline name '%s' to ASCII: %s", *build.Pipeline.Name, ucErr)
continue
}

if _, ok := r.Pipelines[pipeline]; !ok {
r.Pipelines[pipeline] = newCounts()
Expand Down
49 changes: 37 additions & 12 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func newTestCollector() *Collector {
{State: bk.String("scheduled"), AgentQueryRules: []string{"queue=default"}},
},
},
{
Pipeline: &bk.Pipeline{Name: bk.String("vicuñas")},
State: bk.String("scheduled"),
Jobs: []*bk.Job{
{State: bk.String("scheduled"), AgentQueryRules: []string{"queue=default"}},
},
},
},
},
agentService: &testAgentService{
Expand Down Expand Up @@ -58,19 +65,19 @@ func TestCollectorWithRunningBuildsForAllQueues(t *testing.T) {
Expected int
}{
{"Totals", res.Totals, RunningBuildsCount, 1},
{"Totals", res.Totals, ScheduledBuildsCount, 1},
{"Totals", res.Totals, ScheduledBuildsCount, 2},
{"Totals", res.Totals, RunningJobsCount, 1},
{"Totals", res.Totals, ScheduledJobsCount, 2},
{"Totals", res.Totals, UnfinishedJobsCount, 3},
{"Totals", res.Totals, ScheduledJobsCount, 3},
{"Totals", res.Totals, UnfinishedJobsCount, 4},
{"Totals", res.Totals, TotalAgentCount, 1},
{"Totals", res.Totals, BusyAgentCount, 1},
{"Totals", res.Totals, IdleAgentCount, 0},

{"Queue.default", res.Queues["default"], RunningBuildsCount, 1},
{"Queue.default", res.Queues["default"], ScheduledBuildsCount, 1},
{"Queue.default", res.Queues["default"], ScheduledBuildsCount, 2},
{"Queue.default", res.Queues["default"], RunningJobsCount, 1},
{"Queue.default", res.Queues["default"], ScheduledJobsCount, 1},
{"Queue.default", res.Queues["default"], UnfinishedJobsCount, 2},
{"Queue.default", res.Queues["default"], ScheduledJobsCount, 2},
{"Queue.default", res.Queues["default"], UnfinishedJobsCount, 3},
{"Queue.default", res.Queues["default"], TotalAgentCount, 1},
{"Queue.default", res.Queues["default"], BusyAgentCount, 1},
{"Queue.default", res.Queues["default"], IdleAgentCount, 0},
Expand Down Expand Up @@ -101,6 +108,15 @@ func TestCollectorWithRunningBuildsForAllQueues(t *testing.T) {
{"Pipeline.alpacas", res.Pipelines["alpacas"], TotalAgentCount, 0},
{"Pipeline.alpacas", res.Pipelines["alpacas"], BusyAgentCount, 0},
{"Pipeline.alpacas", res.Pipelines["alpacas"], IdleAgentCount, 0},

{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], RunningBuildsCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], ScheduledBuildsCount, 1},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], RunningJobsCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], ScheduledJobsCount, 1},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], UnfinishedJobsCount, 1},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], TotalAgentCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], BusyAgentCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], IdleAgentCount, 0},
}

for queue, _ := range res.Queues {
Expand Down Expand Up @@ -137,19 +153,19 @@ func TestCollectorWithRunningBuildsForASingleQueue(t *testing.T) {
Expected int
}{
{"Totals", res.Totals, RunningBuildsCount, 1},
{"Totals", res.Totals, ScheduledBuildsCount, 1},
{"Totals", res.Totals, ScheduledBuildsCount, 2},
{"Totals", res.Totals, RunningJobsCount, 1},
{"Totals", res.Totals, ScheduledJobsCount, 1},
{"Totals", res.Totals, UnfinishedJobsCount, 2},
{"Totals", res.Totals, ScheduledJobsCount, 2},
{"Totals", res.Totals, UnfinishedJobsCount, 3},
{"Totals", res.Totals, TotalAgentCount, 1},
{"Totals", res.Totals, BusyAgentCount, 1},
{"Totals", res.Totals, IdleAgentCount, 0},

{"Queue.default", res.Queues["default"], RunningBuildsCount, 1},
{"Queue.default", res.Queues["default"], ScheduledBuildsCount, 1},
{"Queue.default", res.Queues["default"], ScheduledBuildsCount, 2},
{"Queue.default", res.Queues["default"], RunningJobsCount, 1},
{"Queue.default", res.Queues["default"], ScheduledJobsCount, 1},
{"Queue.default", res.Queues["default"], UnfinishedJobsCount, 2},
{"Queue.default", res.Queues["default"], ScheduledJobsCount, 2},
{"Queue.default", res.Queues["default"], UnfinishedJobsCount, 3},
{"Queue.default", res.Queues["default"], TotalAgentCount, 1},
{"Queue.default", res.Queues["default"], BusyAgentCount, 1},
{"Queue.default", res.Queues["default"], IdleAgentCount, 0},
Expand All @@ -171,6 +187,15 @@ func TestCollectorWithRunningBuildsForASingleQueue(t *testing.T) {
{"Pipeline.alpacas", res.Pipelines["alpacas"], TotalAgentCount, 0},
{"Pipeline.alpacas", res.Pipelines["alpacas"], BusyAgentCount, 0},
{"Pipeline.alpacas", res.Pipelines["alpacas"], IdleAgentCount, 0},

{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], RunningBuildsCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], ScheduledBuildsCount, 1},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], RunningJobsCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], ScheduledJobsCount, 1},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], UnfinishedJobsCount, 1},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], TotalAgentCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], BusyAgentCount, 0},
{"Pipeline.vicuñas", res.Pipelines["xn--vicuas-zwa"], IdleAgentCount, 0},
}

for queue, _ := range res.Queues {
Expand Down
27 changes: 27 additions & 0 deletions vendor/golang.org/x/net/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/golang.org/x/net/PATENTS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d79ac43

Please sign in to comment.