diff --git a/aws/cwatch/client.go b/aws/cwatch/client.go index 47478cc..c3cb874 100644 --- a/aws/cwatch/client.go +++ b/aws/cwatch/client.go @@ -28,7 +28,7 @@ func (c *DevClient) PutMetricData(ctx context.Context, params *cloudwatch.PutMet for _, dim := range md.Dimensions { log = log.With(strings.ToLower(aws.ToString(dim.Name)), aws.ToString(dim.Value)) } - log.With("metric", aws.ToString(md.MetricName), "value", aws.ToFloat64(md.Value)).Info("put metric data") + log.With("metric", aws.ToString(md.MetricName), "value", aws.ToFloat64(md.Value), "unit", md.Unit).Info("put metric data") } c.callCount.Add(1) diff --git a/aws/cwatch/service.go b/aws/cwatch/service.go index d8caa7d..5ae07ea 100644 --- a/aws/cwatch/service.go +++ b/aws/cwatch/service.go @@ -20,7 +20,8 @@ type Service struct { batcher *syncx.Batcher[types.MetricDatum] } -// NewService creates a new Cloudwatch service with the given credentials and configuration +// NewService creates a new Cloudwatch service with the given credentials and configuration. If deployment is "dev" then +// then instead of a real Cloudwatch client, the service will get a mocked version that just logs metrics. func NewService(accessKey, secretKey, region, namespace, deployment string) (*Service, error) { var client Client @@ -75,6 +76,6 @@ func (s *Service) Prepare(data []types.MetricDatum) *cloudwatch.PutMetricDataInp func (s *Service) processBatch(batch []types.MetricDatum) { _, err := s.Client.PutMetricData(context.TODO(), s.Prepare(batch)) if err != nil { - slog.Error("error sending metrics to cloudwatch", "error", err, "count", len(batch)) + slog.Error("error sending metric data batch", "error", err, "count", len(batch)) } } diff --git a/aws/cwatch/service_test.go b/aws/cwatch/service_test.go index 481834e..6f844aa 100644 --- a/aws/cwatch/service_test.go +++ b/aws/cwatch/service_test.go @@ -46,13 +46,13 @@ func TestService(t *testing.T) { // test writing metrics directly via the client _, err = svc.Client.PutMetricData(context.Background(), svc.Prepare([]types.MetricDatum{ - {MetricName: aws.String("NumGoats"), Value: aws.Float64(10)}, - {MetricName: aws.String("NumSheep"), Dimensions: []types.Dimension{{Name: aws.String("Host"), Value: aws.String("foo1")}}, Value: aws.Float64(20)}, + {MetricName: aws.String("NumGoats"), Value: aws.Float64(10), Unit: types.StandardUnitCount}, + {MetricName: aws.String("NumSheep"), Dimensions: []types.Dimension{{Name: aws.String("Host"), Value: aws.String("foo1")}}, Value: aws.Float64(20), Unit: types.StandardUnitCount}, })) assert.NoError(t, err) // test queuing metrics to be sent by batching process - svc.Queue(types.MetricDatum{MetricName: aws.String("NumFish"), Value: aws.Float64(30)}) + svc.Queue(types.MetricDatum{MetricName: aws.String("SleepTime"), Value: aws.Float64(30), Unit: types.StandardUnitSeconds}) svc.StopQueue() wg.Wait()