Skip to content

Commit

Permalink
Log metric unit too
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Dec 13, 2024
1 parent 108bb60 commit 625af7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aws/cwatch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions aws/cwatch/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 625af7d

Please sign in to comment.