-
Notifications
You must be signed in to change notification settings - Fork 7
/
deps.go
62 lines (51 loc) · 1.84 KB
/
deps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"log"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/prometheus/client_golang/prometheus"
)
var awsRequestSeconds = prometheus.NewSummaryVec(prometheus.SummaryOpts{
Name: "monitoring_cloudwatch_aws_request_seconds",
Help: "Duration of requests we've made to the AWS service",
}, []string{"service", "call"})
var awsErrorsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "monitoring_cloudwatch_aws_errors_total",
Help: "Count of errors we've gotten from the AWS service",
}, []string{"service", "call"})
func init() {
prometheus.MustRegister(awsRequestSeconds, awsErrorsTotal)
}
func initDependencies(config configuration) (*cloudwatch.CloudWatch, error) {
sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String(config.Region),
}))
// XXX recieve session as argument
// awssession.ApplyUserAgent(sess, fmt.Sprintf("ZipRecruiter (monitoring/cloudwatch; %s; [email protected])", Version))
if config.Debug {
sess.Handlers.Send.PushFront(func(r *request.Request) {
log.Printf("Request: %s/%+v, Payload: %+v\n", r.ClientInfo.ServiceName, r.Operation, r.Params)
})
}
sess.Handlers.Send.SetBackNamed(request.NamedHandler{
Name: "Counters",
Fn: func(r *request.Request) {
service := r.ClientInfo.ServiceName
call := r.Operation.Name
duration := time.Now().Sub(r.AttemptTime).Seconds()
awsRequestSeconds.WithLabelValues(service, call).Observe(duration)
},
})
sess.Handlers.UnmarshalError.SetBackNamed(request.NamedHandler{
Name: "Counters",
Fn: func(r *request.Request) {
service := r.ClientInfo.ServiceName
call := r.Operation.Name
awsErrorsTotal.WithLabelValues(service, call).Inc()
},
})
return cloudwatch.New(sess), nil
}