Skip to content

Revert "Log response payload for better troubleshooting (#320)" #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2020
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
26 changes: 2 additions & 24 deletions src/main/java/software/amazon/cloudformation/AbstractWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void processRequest(final InputStream inputStream, final OutputStream out
} finally {
// A response will be output on all paths, though CloudFormation will
// not block on invoking the handlers, but rather listen for callbacks
writeResponse(outputStream, handlerResponse, request);
writeResponse(outputStream, handlerResponse);
publishExceptionCodeAndCountMetrics(request == null ? null : request.getAction(), handlerResponse.getErrorCode());
}
}
Expand Down Expand Up @@ -376,9 +376,7 @@ public void processRequest(final InputStream inputStream, final OutputStream out

}

protected void writeResponse(final OutputStream outputStream,
final ProgressEvent<ResourceT, CallbackT> response,
final HandlerRequest<ResourceT, CallbackT> request)
protected void writeResponse(final OutputStream outputStream, final ProgressEvent<ResourceT, CallbackT> response)
throws IOException {
if (response.getResourceModel() != null) {
// strip write only properties on final results, we will need the intact model
Expand All @@ -389,21 +387,10 @@ protected void writeResponse(final OutputStream outputStream,
}

String output = this.serializer.serialize(response);
if (response.getStatus() != OperationStatus.IN_PROGRESS) {
// if status is not IN_PROGRESS, it means the response has been sanitized
final String logicalResourceId = getLogicalResourceId(request);
final String stackId = getStackId(request);
this.log(String.format("StackId=%s LogicalResourceId=%s Response=%s", stackId, logicalResourceId, output));
}
outputStream.write(output.getBytes(StandardCharsets.UTF_8));
outputStream.flush();
}

protected void writeResponse(final OutputStream outputStream, final ProgressEvent<ResourceT, CallbackT> response)
throws IOException {
this.writeResponse(outputStream, response, null);
}

protected ResourceT sanitizeModel(final ResourceT model) throws IOException {
// strip write only properties on final results, we will need the intact model
// while provisioning
Expand Down Expand Up @@ -587,15 +574,6 @@ protected String getStackId(final HandlerRequest<ResourceT, CallbackT> request)
return null;
}

@VisibleForTesting
protected String getLogicalResourceId(final HandlerRequest<ResourceT, CallbackT> request) {
if (request != null && request.getRequestData() != null) {
return request.getRequestData().getLogicalResourceId();
}

return null;
}

private void replaceInMap(final Map<String, String> targetMap, final Map<String, String> sourceMap) {
if (targetMap == null) {
return;
Expand Down
12 changes: 1 addition & 11 deletions src/test/java/software/amazon/cloudformation/WrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void invokeHandler_nullResponse_returnsFailure(final String requestDataPa
}

verify(providerEventsLogger).refreshClient();
verify(providerEventsLogger, times(3)).publishLogEvent(any());
verify(providerEventsLogger, times(2)).publishLogEvent(any());
verifyNoMoreInteractions(providerEventsLogger);

// verify output response
Expand Down Expand Up @@ -1029,14 +1029,4 @@ public void getStackId_setAndGetStackId() {
assertThat(stackId).isNotNull();
assertThat(stackId).isEqualTo("AWSStackId");
}

@Test
public void getLogicalResourceId_setAndGetLogicalResourceId() {
final HandlerRequest<TestModel, TestContext> request = new HandlerRequest<>();
final RequestData<TestModel> requestData = new RequestData<>();
requestData.setLogicalResourceId("MyResource");
request.setRequestData(requestData);

assertThat(wrapper.getLogicalResourceId(request)).isEqualTo("MyResource");
}
}