@@ -23,11 +23,6 @@ const (
23
23
maxValuesInABatch = 150
24
24
)
25
25
26
- type Percentiles []struct {
27
- s string
28
- f float64
29
- }
30
-
31
26
// CloudWatch receives metrics observations and forwards them to CloudWatch.
32
27
// Create a CloudWatch object, use it to create metrics, and pass those metrics as
33
28
// dependencies to the components that will use them.
@@ -46,15 +41,12 @@ type CloudWatch struct {
46
41
numConcurrentRequests int
47
42
}
48
43
49
- type option func (* CloudWatch )
50
-
51
- func (s * CloudWatch ) apply (opt option ) {
52
- if opt != nil {
53
- opt (s )
54
- }
55
- }
44
+ // Option is a function adapter to change config of the CloudWatch struct
45
+ type Option func (* CloudWatch )
56
46
57
- func WithLogger (logger log.Logger ) option {
47
+ // WithLogger sets the Logger that will receive error messages generated
48
+ // during the WriteLoop. By default, fmt logger is used.
49
+ func WithLogger (logger log.Logger ) Option {
58
50
return func (c * CloudWatch ) {
59
51
c .logger = logger
60
52
}
@@ -64,7 +56,7 @@ func WithLogger(logger log.Logger) option {
64
56
// existing/default values.
65
57
// Reason is that Cloudwatch makes you pay per metric, so you can save half the money
66
58
// by only using 2 metrics instead of the default 4.
67
- func WithPercentiles (percentiles ... float64 ) option {
59
+ func WithPercentiles (percentiles ... float64 ) Option {
68
60
return func (c * CloudWatch ) {
69
61
c .percentiles = make ([]float64 , 0 , len (percentiles ))
70
62
for _ , p := range percentiles {
@@ -76,7 +68,11 @@ func WithPercentiles(percentiles ...float64) option {
76
68
}
77
69
}
78
70
79
- func WithConcurrentRequests (n int ) option {
71
+ // WithConcurrentRequests sets the upper limit on how many
72
+ // cloudwatch.PutMetricDataRequest may be under way at any
73
+ // given time. If n is greater than 20, 20 is used. By default,
74
+ // the max is set at 10 concurrent requests.
75
+ func WithConcurrentRequests (n int ) Option {
80
76
return func (c * CloudWatch ) {
81
77
if n > maxConcurrentRequests {
82
78
n = maxConcurrentRequests
@@ -89,7 +85,7 @@ func WithConcurrentRequests(n int) option {
89
85
// Namespace is applied to all created metrics and maps to the CloudWatch namespace.
90
86
// Callers must ensure that regular calls to Send are performed, either
91
87
// manually or with one of the helper methods.
92
- func New (namespace string , svc cloudwatchiface.CloudWatchAPI , options ... option ) * CloudWatch {
88
+ func New (namespace string , svc cloudwatchiface.CloudWatchAPI , options ... Option ) * CloudWatch {
93
89
cw := & CloudWatch {
94
90
sem : nil , // set below
95
91
namespace : namespace ,
@@ -102,8 +98,8 @@ func New(namespace string, svc cloudwatchiface.CloudWatchAPI, options ...option)
102
98
percentiles : []float64 {0.50 , 0.90 , 0.95 , 0.99 },
103
99
}
104
100
105
- for _ , optFunc := range options {
106
- optFunc (cw )
101
+ for _ , opt := range options {
102
+ opt (cw )
107
103
}
108
104
109
105
cw .sem = make (chan struct {}, cw .numConcurrentRequests )
0 commit comments