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

Moved collector into subpackage with tests #22

Merged
merged 6 commits into from
Dec 19, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update main package to use collector package
lox committed Dec 18, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f863d0b6a4b80205f69c6e5d8660bcd3196dc173
13 changes: 7 additions & 6 deletions cloudwatch.go
Original file line number Diff line number Diff line change
@@ -6,21 +6,22 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/buildkite/buildkite-metrics/collector"
)

func cloudwatchSend(r *result) error {
func cloudwatchSend(r *collector.Result) error {
svc := cloudwatch.New(session.New())

metrics := []*cloudwatch.MetricDatum{}
metrics = append(metrics, cloudwatchMetrics(r.totals, nil)...)
metrics = append(metrics, cloudwatchMetrics(r.Totals, nil)...)

for name, c := range r.queues {
for name, c := range r.Queues {
metrics = append(metrics, cloudwatchMetrics(c, []*cloudwatch.Dimension{
{Name: aws.String("Queue"), Value: aws.String(name)},
})...)
}

for name, c := range r.pipelines {
for name, c := range r.Pipelines {
metrics = append(metrics, cloudwatchMetrics(c, []*cloudwatch.Dimension{
{Name: aws.String("Pipeline"), Value: aws.String(name)},
})...)
@@ -42,10 +43,10 @@ func cloudwatchSend(r *result) error {
return nil
}

func cloudwatchMetrics(c counts, dimensions []*cloudwatch.Dimension) []*cloudwatch.MetricDatum {
func cloudwatchMetrics(counts map[string]int, dimensions []*cloudwatch.Dimension) []*cloudwatch.MetricDatum {
m := []*cloudwatch.MetricDatum{}

for k, v := range c {
for k, v := range counts {
m = append(m, &cloudwatch.MetricDatum{
MetricName: aws.String(k),
Dimensions: dimensions,
2 changes: 1 addition & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ type Collector struct {
}
}

func NewCollector(c *bk.Client, opts Opts) *Collector {
func New(c *bk.Client, opts Opts) *Collector {
return &Collector{
Opts: opts,
buildService: c.Builds,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed this in my local copy (I'm doing a fork to add statsd support): should agentService be populated too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hrm, good point, now to figure out how it works at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just working on a PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

7 changes: 5 additions & 2 deletions lambda.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import (
"os"
"time"

"github.com/buildkite/buildkite-metrics/collector"
"github.com/eawsy/aws-lambda-go/service/lambda/runtime"
"gopkg.in/buildkite/go-buildkite.v2/buildkite"
)
@@ -26,15 +27,17 @@ func handle(evt json.RawMessage, ctx *runtime.Context) (interface{}, error) {
client := buildkite.NewClient(config.Client())
t := time.Now()

res, err := collectResults(client, collectOpts{
col := collector.New(client, collector.Opts{
OrgSlug: org,
Historical: time.Hour * 24,
})

res, err := col.Collect()
if err != nil {
return nil, err
}

dumpResults(res)
res.Dump()

err = cloudwatchSend(res)
if err != nil {