-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For dev deployments, cloudwatch service should just log to console
- Loading branch information
1 parent
c430b1e
commit 108bb60
Showing
3 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cwatch | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"strings" | ||
"sync/atomic" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/cloudwatch" | ||
"github.com/aws/smithy-go/middleware" | ||
) | ||
|
||
// Client is the interface for a Cloudwatch client that can only send metrics | ||
type Client interface { | ||
PutMetricData(ctx context.Context, params *cloudwatch.PutMetricDataInput, optFns ...func(*cloudwatch.Options)) (*cloudwatch.PutMetricDataOutput, error) | ||
} | ||
|
||
type DevClient struct { | ||
callCount atomic.Int32 | ||
} | ||
|
||
func (c *DevClient) PutMetricData(ctx context.Context, params *cloudwatch.PutMetricDataInput, optFns ...func(*cloudwatch.Options)) (*cloudwatch.PutMetricDataOutput, error) { | ||
// log each metric being "sent" | ||
for _, md := range params.MetricData { | ||
log := slog.With("namespace", aws.ToString(params.Namespace)) | ||
|
||
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") | ||
} | ||
|
||
c.callCount.Add(1) | ||
|
||
return &cloudwatch.PutMetricDataOutput{ResultMetadata: middleware.Metadata{}}, nil | ||
} | ||
|
||
func (c *DevClient) CallCount() int { | ||
return int(c.callCount.Load()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters