@@ -2,31 +2,21 @@ package cwatch
2
2
3
3
import (
4
4
"context"
5
- "log/slog"
6
- "sync"
7
- "time"
8
5
9
6
"github.com/aws/aws-sdk-go-v2/aws"
10
7
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
11
8
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
12
9
awsx "github.com/nyaruka/gocommon/aws"
13
- "github.com/nyaruka/gocommon/syncx"
14
10
)
15
11
16
12
type Service struct {
17
13
Client Client
18
14
namespace string
19
15
deployment string
20
-
21
- batcher * syncx.Batcher [types.MetricDatum ]
22
- batcherWG * sync.WaitGroup
23
16
}
24
17
25
- // NewService creates a new Cloudwatch service with the given credentials and configuration. Some behaviours depend on
26
- // the given deployment value:
27
- // - "test": metrics just logged, Queue(..) sends synchronously
28
- // - "dev": metrics just logged, Queue(..) adds to batcher
29
- // - "*": metrics sent to Cloudwatch, Queue(..) adds to batcher
18
+ // NewService creates a new Cloudwatch service with the given credentials and configuration. If deployment is given as
19
+ // "dev" or "test", then metrics are logged and not sent to Cloudwatch.
30
20
func NewService (accessKey , secretKey , region , namespace , deployment string ) (* Service , error ) {
31
21
var client Client
32
22
@@ -43,34 +33,6 @@ func NewService(accessKey, secretKey, region, namespace, deployment string) (*Se
43
33
return & Service {Client : client , namespace : namespace , deployment : deployment }, nil
44
34
}
45
35
46
- func (s * Service ) StartQueue (maxAge time.Duration ) {
47
- if s .batcher != nil {
48
- panic ("queue already started" )
49
- }
50
-
51
- s .batcherWG = & sync.WaitGroup {}
52
- s .batcher = syncx .NewBatcher (s .processBatch , 100 , maxAge , 1000 , s .batcherWG )
53
- s .batcher .Start ()
54
- }
55
-
56
- func (s * Service ) StopQueue () {
57
- if s .batcher == nil {
58
- panic ("queue wasn't started" )
59
- }
60
- s .batcher .Stop ()
61
- s .batcherWG .Wait ()
62
- }
63
-
64
- func (s * Service ) Queue (data ... types.MetricDatum ) {
65
- if s .deployment == "test" {
66
- s .Send (context .TODO (), data ... )
67
- } else {
68
- for _ , d := range data {
69
- s .batcher .Queue (d )
70
- }
71
- }
72
- }
73
-
74
36
func (s * Service ) Send (ctx context.Context , data ... types.MetricDatum ) error {
75
37
_ , err := s .Client .PutMetricData (ctx , s .prepare (data ))
76
38
return err
@@ -87,9 +49,3 @@ func (s *Service) prepare(data []types.MetricDatum) *cloudwatch.PutMetricDataInp
87
49
MetricData : data ,
88
50
}
89
51
}
90
-
91
- func (s * Service ) processBatch (batch []types.MetricDatum ) {
92
- if err := s .Send (context .TODO (), batch ... ); err != nil {
93
- slog .Error ("error sending metric data batch" , "error" , err , "count" , len (batch ))
94
- }
95
- }
0 commit comments