Skip to content

Commit

Permalink
Track CloudFormation template sizes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Jul 27, 2016
1 parent 936b921 commit 5b085cb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scheduler/cloudformation/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/remind101/empire/pkg/bytesize"
pglock "github.com/remind101/empire/pkg/pg/lock"
"github.com/remind101/empire/scheduler"
"github.com/remind101/empire/stats"
"github.com/remind101/pkg/logger"
"golang.org/x/net/context"
)
Expand Down Expand Up @@ -217,6 +218,10 @@ func (s *Scheduler) submit(ctx context.Context, tx *sql.Tx, app *scheduler.App,
return err
}

stats.Histogram(ctx, "scheduler.cloudformation.template_size", float32(t.Size), 1.0, []string{
fmt.Sprintf("stack:%s", stackName),
})

scheduler.Publish(ctx, ss, fmt.Sprintf("Created cloudformation template: %v (%d/%d bytes)", *t.URL, t.Size, MaxTemplateSize))

tags := append(s.Tags,
Expand Down
4 changes: 4 additions & 0 deletions stats/dogstatsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ func (s *Dogstatsd) Timing(name string, value time.Duration, rate float32, tags
func (s *Dogstatsd) Gauge(name string, value float32, rate float32, tags []string) error {
return s.Client.Gauge(name, float64(value), tags, float64(rate))
}

func (s *Dogstatsd) Histogram(name string, value float32, rate float32, tags []string) error {
return s.Client.Histogram(name, float64(value), tags, float64(rate))
}
16 changes: 16 additions & 0 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Stats interface {
Inc(name string, value int64, rate float32, tags []string) error
Timing(name string, value time.Duration, rate float32, tags []string) error
Gauge(name string, value float32, rate float32, tags []string) error
Histogram(name string, value float32, rate float32, tags []string) error
}

type nullStats struct{}
Expand All @@ -29,6 +30,10 @@ func (s *nullStats) Gauge(name string, value float32, rate float32, tags []strin
return nil
}

func (s *nullStats) Histogram(name string, value float32, rate float32, tags []string) error {
return nil
}

var Null = &nullStats{}

// taggedStats wraps a Stats implementation to include some additional tags.
Expand All @@ -49,6 +54,10 @@ func (s *taggedStats) Gauge(name string, value float32, rate float32, tags []str
return s.stats.Gauge(name, value, rate, append(tags, s.tags...))
}

func (s *taggedStats) Histogram(name string, value float32, rate float32, tags []string) error {
return s.stats.Histogram(name, value, rate, append(tags, s.tags...))
}

// WithStats returns a new context.Context with the Stats implementation
// embedded.
func WithStats(ctx context.Context, stats Stats) context.Context {
Expand Down Expand Up @@ -92,6 +101,13 @@ func Gauge(ctx context.Context, name string, value float32, rate float32, tags [
return nil
}

func Histogram(ctx context.Context, name string, value float32, rate float32, tags []string) error {
if stats, ok := FromContext(ctx); ok {
return stats.Histogram(name, value, rate, tags)
}
return nil
}

type key int

const (
Expand Down
4 changes: 4 additions & 0 deletions stats/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ func (s *Statsd) Timing(name string, value time.Duration, rate float32, tags []s
func (s *Statsd) Gauge(name string, value float32, rate float32, tags []string) error {
return s.client.Gauge(name, int64(value), rate)
}

func (s *Statsd) Histogram(name string, value float32, rate float32, tags []string) error {
return s.client.Gauge(name, int64(value), rate)
}

0 comments on commit 5b085cb

Please sign in to comment.