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
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,8 @@ private void publishExceptionMetric(final Action action, final Throwable ex, fin
private void
publishExceptionCodeAndCountMetric(final Action action, final HandlerErrorCode handlerErrorCode, final boolean thrown) {
if (this.metricsPublisherProxy != null) {
EnumSet.allOf(HandlerErrorCode.class).stream()
// publishing 0 value for all (if not thrown) otherwise filtered
.filter(errorCode -> errorCode.equals(handlerErrorCode) || !thrown)
.forEach(errorCode -> this.metricsPublisherProxy.publishExceptionByErrorCodeMetric(Instant.now(), action,
errorCode, thrown));
EnumSet.allOf(HandlerErrorCode.class).forEach(errorCode -> this.metricsPublisherProxy
.publishExceptionByErrorCodeMetric(Instant.now(), action, errorCode, thrown && errorCode == handlerErrorCode));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should publish all those ErrorCode metrics in one PutMetric call, which can support multiple metrics in one request.. Otherwise it will consume large number of TPS, and may cause throttling.

this.metricsPublisherProxy.publishExceptionCountMetric(Instant.now(), action, thrown);
}
}
Expand Down
21 changes: 10 additions & 11 deletions src/test/java/software/amazon/cloudformation/LambdaWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,31 +392,30 @@ public void invokeHandler_InProgress_returnsInProgress(final String requestDataP
verifyInitialiseRuntime();

// all metrics should be published, once for a single invocation
verify(providerMetricsPublisher, times(1)).publishInvocationMetric(any(Instant.class), eq(action));
verify(providerMetricsPublisher, times(1)).publishDurationMetric(any(Instant.class), eq(action), anyLong());
verify(providerMetricsPublisher).publishInvocationMetric(any(Instant.class), eq(action));
verify(providerMetricsPublisher).publishDurationMetric(any(Instant.class), eq(action), anyLong());

// verify that model validation occurred for CREATE/UPDATE/DELETE
if (action == Action.CREATE || action == Action.UPDATE || action == Action.DELETE) {
verify(validator, times(1)).validateObject(any(JSONObject.class), any(JSONObject.class));
verify(validator).validateObject(any(JSONObject.class), any(JSONObject.class));

// verify output response
verifyHandlerResponse(out, ProgressEvent.<TestModel, TestContext>builder().status(OperationStatus.IN_PROGRESS)
.resourceModel(TestModel.builder().property1("abc").property2(123).build()).build());
verify(providerMetricsPublisher, atLeastOnce()).publishExceptionByErrorCodeMetric(any(Instant.class), eq(action),
any(), eq(Boolean.FALSE));
verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), eq(action), eq(Boolean.FALSE));
} else {
verifyHandlerResponse(out,
ProgressEvent.<TestModel, TestContext>builder().status(OperationStatus.FAILED)
.errorCode(HandlerErrorCode.InternalFailure).message("READ and LIST handlers must return synchronously.")
.build());
verify(providerMetricsPublisher).publishExceptionMetric(any(Instant.class), eq(action),
any(TerminalException.class), eq(HandlerErrorCode.InternalFailure));
verify(providerMetricsPublisher).publishExceptionByErrorCodeMetric(any(Instant.class), eq(action),
eq(HandlerErrorCode.InternalFailure), eq(Boolean.TRUE));
verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), eq(action), eq(Boolean.TRUE));

}

verify(providerMetricsPublisher, atLeastOnce()).publishExceptionByErrorCodeMetric(any(Instant.class), eq(action),
any(), any(Boolean.class));
verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), any(), any(Boolean.class));

// validation failure metric should not be published
verifyNoMoreInteractions(providerMetricsPublisher);

Expand Down Expand Up @@ -811,8 +810,8 @@ public void invokeHandler_metricPublisherThrowable_returnsFailureResponse() thro
// verify initialiseRuntime was called and initialised dependencies
verifyInitialiseRuntime();

verify(providerMetricsPublisher).publishExceptionByErrorCodeMetric(any(Instant.class), any(Action.class),
any(HandlerErrorCode.class), any(Boolean.class));
verify(providerMetricsPublisher, atLeastOnce()).publishExceptionByErrorCodeMetric(any(Instant.class),
any(Action.class), any(HandlerErrorCode.class), any(Boolean.class));

verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), any(Action.class),
any(Boolean.class));
Expand Down