Skip to content
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

ACS-8766: Adjust live-ingester logging to be more descriptive in case of error #666

Conversation

krdabrowski
Copy link
Contributor

…ing-to-be-more-descriptive-in-case-of-error

# Conflicts:
#	common-test/src/main/java/org/alfresco/hxi_connector/common/test/docker/util/DockerContainers.java
Copy link
Member

@tpage-alfresco tpage-alfresco left a comment

Choose a reason for hiding this comment

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

The log quality looks much better 👍

I'm not convinced by the method of masking sensitive data out of the log using a regex. Instead I think it would be better to selectively choose data to be included in the log. With the current proposal then there's a risk that the name of a field could change, e.g. secret could be renamed token by a library upgrade, and then the masking would stop working. I don't think any of the tests here would catch this problem either.

I know it's more work, but I think it would be better to create our own text renderers for the problematic fields.

@krdabrowski
Copy link
Contributor Author

krdabrowski commented Sep 20, 2024

@tpage-alfresco I've adjusted the way of masking stuff according to our conversation on Slack. Please could you review it one more time? 🙏

Copy link
Contributor

@mpichura mpichura left a comment

Choose a reason for hiding this comment

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

LGTM, as discussed, you may want to call logMaskedExchangeState direclty in .process() instead of creating/calling a private method in each RouteBuilder it used.

@krdabrowski
Copy link
Contributor Author

@mpichura fixed - thanks!

@@ -112,7 +116,7 @@ STORAGE_LOCATION_HEADER, wrapRawToken(fileUploadRequest.storageLocation()),
.withHeaders(headers)
.withBody(fileData)
.request();
log.atDebug().log("Upload :: {} rendition of the node: {} successfully uploaded to pre-signed URL: {}", fileUploadRequest.contentType(), nodeId, fileUploadRequest.storageLocation().getPath());
log.info("Storage :: Rendition of type: {} for node: {} successfully uploaded to pre-signed URL: {}", fileUploadRequest.contentType(), nodeId, fileUploadRequest.storageLocation().getPath());
Copy link
Member

Choose a reason for hiding this comment

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

You should use atInfo() to avoid the PMD issue (since PMD doesn't know how long the calls to contentType(), storageLocation() and getPath() will take).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - thanks!

@@ -123,7 +127,7 @@ STORAGE_LOCATION_HEADER, wrapRawToken(fileUploadRequest.storageLocation()),
}
catch (IOException ioe)
{
log.atDebug().log("Upload :: Stream reset failed due to: {}", ioe.getMessage());
log.warn("Storage :: Rendition stream NOT reset properly after node %s content upload fail due to: %s".formatted(nodeId, ioe.getMessage()), ioe);
Copy link
Member

Choose a reason for hiding this comment

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

Similarly I think we want atWarn() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - thanks!

…ing-to-be-more-descriptive-in-case-of-error

# Conflicts:
#	live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/config/jackson/DeleteNodeEventSerializer.java
Copy link
Member

@tpage-alfresco tpage-alfresco left a comment

Choose a reason for hiding this comment

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

One more change I think is worth doing.

@@ -50,6 +51,8 @@
public class ATSTransformResponseHandler extends RouteBuilder
{
private static final String ROUTE_ID = "transform-events-consumer";
private static final int EXPECTED_STATUS_CODE = 201;
private static final String EXPECTED_STATUS_CODE_REGEX = "[\\s\\S]*\"status\"\\s*:\\s*%s[\\s\\S]*".formatted(EXPECTED_STATUS_CODE);
Copy link
Member

Choose a reason for hiding this comment

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

I wrote a comment suggesting this, but it disappeared - thanks GitHub!

Suggested change
private static final String EXPECTED_STATUS_CODE_REGEX = "[\\s\\S]*\"status\"\\s*:\\s*%s[\\s\\S]*".formatted(EXPECTED_STATUS_CODE);
private static final String EXPECTED_STATUS_CODE_REGEX = ".*\"status\"\\s*:\\s*%s[^0-9].*".formatted(EXPECTED_STATUS_CODE);

Copy link
Member

Choose a reason for hiding this comment

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

Explanation: I think that [\\s\\S] includes all characters so is the same as . Also the status code should not be followed by another digit (and will be followed by something in a JSON response).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The [\\s\\S] is similar to ., but it also includes whitespaces, so it covers bigger set of characters to match whole sentence / paragraph (or JSON) containing expected status

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add the [^0-9] - this is to prevent the next char from being a number, yes?

Copy link
Member

@tpage-alfresco tpage-alfresco left a comment

Choose a reason for hiding this comment

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

Great - thanks for adding the tests!

@krdabrowski krdabrowski merged commit 601c0b9 into master Sep 24, 2024
37 checks passed
@krdabrowski krdabrowski deleted the feature/ACS-8766-Adjust-live-ingester-logging-to-be-more-descriptive-in-case-of-error branch September 24, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants