Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfn/cfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func makeEventFunc(h Handler) eventFunc {
)
// Set default logger to output to CWL in the provider account
logging.SetProviderLogOutput(l)
m := metrics.New(cloudwatch.New(ps), event.AWSAccountID, event.ResourceType)
m := metrics.New(cloudwatch.New(ps), event.ResourceType)
re := newReportErr(m)
if err := scrubFiles("/tmp"); err != nil {
log.Printf("Error: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions cfn/metrics/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ type Publisher struct {
}

// New creates a new Publisher.
func New(client cloudwatchiface.CloudWatchAPI, account string, resType string) *Publisher {
func New(client cloudwatchiface.CloudWatchAPI, resType string) *Publisher {
if len(os.Getenv("AWS_SAM_LOCAL")) > 0 {
client = newNoopClient()
}
rn := ResourceTypeName(resType)
return &Publisher{
client: client,
logger: logging.New("metrics"),
namespace: fmt.Sprintf("%s/%s/%s", MetricNameSpaceRoot, account, rn),
namespace: fmt.Sprintf("%s/%s", MetricNameSpaceRoot, rn),
resourceType: rn,
}
}
Expand Down
33 changes: 15 additions & 18 deletions cfn/metrics/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestPublisher_PublishExceptionMetric(t *testing.T) {
type fields struct {
Client cloudwatchiface.CloudWatchAPI
resName string
account string
}
type args struct {
date time.Time
Expand All @@ -80,14 +79,14 @@ func TestPublisher_PublishExceptionMetric(t *testing.T) {
wantUnit string
wantValue float64
}{
{"testPublisherPublishExceptionMetric", fields{NewMockCloudWatchClient(), "foo::bar::test", "12345678"}, args{time.Now(), "CREATE", errors.New("failed to create\nresource")}, "HandlerException", false, "CREATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublisherPublishExceptionMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test", "12345678"}, args{time.Now(), "CREATE", errors.New("failed to create resource")}, "HandlerException", true, "CREATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublisherPublishExceptionMetric", fields{NewMockCloudWatchClient(), "foo::bar::test", "12345678"}, args{time.Now(), "UPDATE", errors.New("failed to create resource")}, "HandlerException", false, "UPDATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublisherPublishExceptionMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test", "12345678"}, args{time.Now(), "UPDATE", errors.New("failed to create resource")}, "HandlerException", true, "UPDATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublisherPublishExceptionMetric", fields{NewMockCloudWatchClient(), "foo::bar::test"}, args{time.Now(), "CREATE", errors.New("failed to create\nresource")}, "HandlerException", false, "CREATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublisherPublishExceptionMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test"}, args{time.Now(), "CREATE", errors.New("failed to create resource")}, "HandlerException", true, "CREATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublisherPublishExceptionMetric", fields{NewMockCloudWatchClient(), "foo::bar::test"}, args{time.Now(), "UPDATE", errors.New("failed to create resource")}, "HandlerException", false, "UPDATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublisherPublishExceptionMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test"}, args{time.Now(), "UPDATE", errors.New("failed to create resource")}, "HandlerException", true, "UPDATE", "failed to create resource", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
}
for i, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := New(tt.fields.Client, tt.fields.account, tt.fields.resName)
p := New(tt.fields.Client, tt.fields.resName)
t.Logf("\tTest: %d\tWhen checking %q for success", i, tt.name)
{
p.PublishExceptionMetric(tt.args.date, tt.args.action, tt.args.e)
Expand Down Expand Up @@ -141,7 +140,6 @@ func TestPublisher_PublishInvocationMetric(t *testing.T) {
type fields struct {
Client cloudwatchiface.CloudWatchAPI
resName string
account string
}
type args struct {
date time.Time
Expand All @@ -159,14 +157,14 @@ func TestPublisher_PublishInvocationMetric(t *testing.T) {
wantUnit string
wantValue float64
}{
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test", "12345678"}, args{time.Now(), "CREATE"}, "HandlerInvocationCount", false, "CREATE", "foo/bar/test", "HandlerInvocationCount", cloudwatch.StandardUnitCount, 1.0},
{"testPublishInvocationMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test", "12345678"}, args{time.Now(), "CREATE"}, "HandlerException", true, "CREATE", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test", "12345678"}, args{time.Now(), "UPDATE"}, "HandlerInvocationCount", false, "UPDATE", "foo/bar/test", "HandlerInvocationCount", cloudwatch.StandardUnitCount, 1.0},
{"testPublishInvocationMetricError", fields{NewMockCloudWatchClientError(), "foo::bar::test", "12345678"}, args{time.Now(), "UPDATE"}, "HandlerException", true, "UPDATE", "foo/bar/test", "HandlerInvocationCount", cloudwatch.StandardUnitCount, 1.0},
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test"}, args{time.Now(), "CREATE"}, "HandlerInvocationCount", false, "CREATE", "foo/bar/test", "HandlerInvocationCount", cloudwatch.StandardUnitCount, 1.0},
{"testPublishInvocationMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test"}, args{time.Now(), "CREATE"}, "HandlerException", true, "CREATE", "foo/bar/test", "HandlerException", cloudwatch.StandardUnitCount, 1.0},
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test"}, args{time.Now(), "UPDATE"}, "HandlerInvocationCount", false, "UPDATE", "foo/bar/test", "HandlerInvocationCount", cloudwatch.StandardUnitCount, 1.0},
{"testPublishInvocationMetricError", fields{NewMockCloudWatchClientError(), "foo::bar::test"}, args{time.Now(), "UPDATE"}, "HandlerException", true, "UPDATE", "foo/bar/test", "HandlerInvocationCount", cloudwatch.StandardUnitCount, 1.0},
}
for i, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := New(tt.fields.Client, tt.fields.account, tt.fields.resName)
p := New(tt.fields.Client, tt.fields.resName)
t.Logf("\tTest: %d\tWhen checking %q for success", i, tt.name)
{
p.PublishInvocationMetric(tt.args.date, tt.args.action)
Expand Down Expand Up @@ -215,7 +213,6 @@ func TestPublisher_PublishDurationMetric(t *testing.T) {
type fields struct {
Client cloudwatchiface.CloudWatchAPI
resName string
account string
}
type args struct {
date time.Time
Expand All @@ -234,14 +231,14 @@ func TestPublisher_PublishDurationMetric(t *testing.T) {
wantUnit string
wantValue float64
}{
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test", "12345678"}, args{time.Now(), "CREATE", 15.0}, "HandlerInvocationDuration", false, "CREATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
{"testPublishInvocationMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test", "12345678"}, args{time.Now(), "CREATE", 15.0}, "HandlerInvocationDuration", true, "CREATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test", "12345678"}, args{time.Now(), "UPDATE", 15.0}, "HandlerInvocationDuration", false, "UPDATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
{"testPublishInvocationMetricError", fields{NewMockCloudWatchClientError(), "foo::bar::test", "12345678"}, args{time.Now(), "UPDATE", 15.0}, "HandlerInvocationDuration", true, "UPDATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test"}, args{time.Now(), "CREATE", 15.0}, "HandlerInvocationDuration", false, "CREATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
{"testPublishInvocationMetricWantError", fields{NewMockCloudWatchClientError(), "foo::bar::test"}, args{time.Now(), "CREATE", 15.0}, "HandlerInvocationDuration", true, "CREATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
{"testPublishInvocationMetric", fields{NewMockCloudWatchClient(), "foo::bar::test"}, args{time.Now(), "UPDATE", 15.0}, "HandlerInvocationDuration", false, "UPDATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
{"testPublishInvocationMetricError", fields{NewMockCloudWatchClientError(), "foo::bar::test"}, args{time.Now(), "UPDATE", 15.0}, "HandlerInvocationDuration", true, "UPDATE", "foo/bar/test", "HandlerInvocationDuration", cloudwatch.StandardUnitMilliseconds, 15},
}
for i, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := New(tt.fields.Client, tt.fields.account, tt.fields.resName)
p := New(tt.fields.Client, tt.fields.resName)
t.Logf("\tTest: %d\tWhen checking %q for success", i, tt.name)
{
p.PublishDurationMetric(tt.args.date, tt.args.action, tt.args.sec)
Expand Down