Skip to content

Commit 5e20615

Browse files
authored
added zero-events on untriggered codes (#301)
1 parent 2ca8a71 commit 5e20615

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/main/java/software/amazon/cloudformation/LambdaWrapper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,8 @@ private void publishExceptionMetric(final Action action, final Throwable ex, fin
487487
private void
488488
publishExceptionCodeAndCountMetric(final Action action, final HandlerErrorCode handlerErrorCode, final boolean thrown) {
489489
if (this.metricsPublisherProxy != null) {
490-
EnumSet.allOf(HandlerErrorCode.class).stream()
491-
// publishing 0 value for all (if not thrown) otherwise filtered
492-
.filter(errorCode -> errorCode.equals(handlerErrorCode) || !thrown)
493-
.forEach(errorCode -> this.metricsPublisherProxy.publishExceptionByErrorCodeMetric(Instant.now(), action,
494-
errorCode, thrown));
490+
EnumSet.allOf(HandlerErrorCode.class).forEach(errorCode -> this.metricsPublisherProxy
491+
.publishExceptionByErrorCodeMetric(Instant.now(), action, errorCode, thrown && errorCode == handlerErrorCode));
495492
this.metricsPublisherProxy.publishExceptionCountMetric(Instant.now(), action, thrown);
496493
}
497494
}

src/test/java/software/amazon/cloudformation/LambdaWrapperTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,31 +392,30 @@ public void invokeHandler_InProgress_returnsInProgress(final String requestDataP
392392
verifyInitialiseRuntime();
393393

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

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

402402
// verify output response
403403
verifyHandlerResponse(out, ProgressEvent.<TestModel, TestContext>builder().status(OperationStatus.IN_PROGRESS)
404404
.resourceModel(TestModel.builder().property1("abc").property2(123).build()).build());
405-
verify(providerMetricsPublisher, atLeastOnce()).publishExceptionByErrorCodeMetric(any(Instant.class), eq(action),
406-
any(), eq(Boolean.FALSE));
407-
verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), eq(action), eq(Boolean.FALSE));
408405
} else {
409406
verifyHandlerResponse(out,
410407
ProgressEvent.<TestModel, TestContext>builder().status(OperationStatus.FAILED)
411408
.errorCode(HandlerErrorCode.InternalFailure).message("READ and LIST handlers must return synchronously.")
412409
.build());
413410
verify(providerMetricsPublisher).publishExceptionMetric(any(Instant.class), eq(action),
414411
any(TerminalException.class), eq(HandlerErrorCode.InternalFailure));
415-
verify(providerMetricsPublisher).publishExceptionByErrorCodeMetric(any(Instant.class), eq(action),
416-
eq(HandlerErrorCode.InternalFailure), eq(Boolean.TRUE));
417-
verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), eq(action), eq(Boolean.TRUE));
412+
418413
}
419414

415+
verify(providerMetricsPublisher, atLeastOnce()).publishExceptionByErrorCodeMetric(any(Instant.class), eq(action),
416+
any(), any(Boolean.class));
417+
verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), any(), any(Boolean.class));
418+
420419
// validation failure metric should not be published
421420
verifyNoMoreInteractions(providerMetricsPublisher);
422421

@@ -811,8 +810,8 @@ public void invokeHandler_metricPublisherThrowable_returnsFailureResponse() thro
811810
// verify initialiseRuntime was called and initialised dependencies
812811
verifyInitialiseRuntime();
813812

814-
verify(providerMetricsPublisher).publishExceptionByErrorCodeMetric(any(Instant.class), any(Action.class),
815-
any(HandlerErrorCode.class), any(Boolean.class));
813+
verify(providerMetricsPublisher, atLeastOnce()).publishExceptionByErrorCodeMetric(any(Instant.class),
814+
any(Action.class), any(HandlerErrorCode.class), any(Boolean.class));
816815

817816
verify(providerMetricsPublisher).publishExceptionCountMetric(any(Instant.class), any(Action.class),
818817
any(Boolean.class));

0 commit comments

Comments
 (0)