コード例 #1
0
ファイル: heroku.go プロジェクト: iserko/empire
func withMetrics(handlerName string, h httpx.HandlerFunc) httpx.Handler {
	return httpx.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		tags := []string{
			fmt.Sprintf("handler:%s", handlerName),
			fmt.Sprintf("user:%s", auth.UserFromContext(ctx).Name),
		}
		start := time.Now()
		err := h(ctx, w, r)
		d := time.Since(start)
		stats.Timing(ctx, fmt.Sprintf("heroku.request"), d, 1.0, tags)
		stats.Timing(ctx, fmt.Sprintf("heroku.request.%s", handlerName), d, 1.0, tags)
		return err
	})
}
コード例 #2
0
ファイル: heroku.go プロジェクト: mhahn/empire
// handle adds a new handler to the router, which also increments a counter.
func (s *Server) handle(method, path string, h httpx.HandlerFunc) {
	name := handlerName(h)

	fn := httpx.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		tags := []string{
			fmt.Sprintf("handler:%s", name),
			fmt.Sprintf("user:%s", UserFromContext(ctx).Name),
		}
		start := time.Now()
		err := h(ctx, w, r)
		d := time.Since(start)
		stats.Timing(ctx, fmt.Sprintf("heroku.request"), d, 1.0, tags)
		stats.Timing(ctx, fmt.Sprintf("heroku.request.%s", name), d, 1.0, tags)
		return err
	})

	s.mux.HandleFunc(path, fn).Methods(method)
}
コード例 #3
0
ファイル: cloudformation.go プロジェクト: mhahn/empire
func (p *metricsProvisioner) Provision(ctx context.Context, req customresources.Request) (string, interface{}, error) {
	tags := []string{
		fmt.Sprintf("resource_type:%s", req.ResourceType),
		fmt.Sprintf("request_type:%s", req.RequestType),
	}
	start := time.Now()
	id, data, err := p.Provisioner.Provision(ctx, req)
	stats.Timing(ctx, "cloudformation.provision", time.Since(start), 1.0, tags)
	return id, data, err
}
コード例 #4
0
ファイル: cloudformation.go プロジェクト: mhahn/empire
// waitFor returns a wait function that will wait for the given stack operation
// to complete, and sends status messages to the status stream, and also records
// metrics for how long the operation took.
func (s *Scheduler) waitFor(ctx context.Context, op stackOperation, ss scheduler.StatusStream) func(*cloudformation.DescribeStacksInput) error {
	waiter := waiters[op]
	wait := waiter.wait(s.cloudformation)

	return func(input *cloudformation.DescribeStacksInput) error {
		tags := []string{
			fmt.Sprintf("stack:%s", *input.StackName),
		}
		scheduler.Publish(ctx, ss, waiter.startMessage)
		start := time.Now()
		err := wait(input)
		stats.Timing(ctx, fmt.Sprintf("scheduler.cloudformation.%s", op), time.Since(start), 1.0, tags)
		if err == nil {
			scheduler.Publish(ctx, ss, waiter.successMessage)
		}
		return err
	}
}