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

Add exclude pattern to access log #16891

Merged
merged 1 commit into from
Apr 30, 2021
Merged

Conversation

stuartwdouglas
Copy link
Member

Fixes #13377

@geoand geoand requested a review from cescoffier April 29, 2021 10:22
this.accessLogReceiver = accessLogReceiver;
this.formatString = handleCommonNames(formatString);
this.tokens = new ExchangeAttributeParser(classLoader, Collections.singletonList(new SubstituteEmptyWrapper("-")))
.parse(this.formatString);
if (excludePattern.isPresent()) {
this.excludePattern = Pattern.compile(excludePattern.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if it is not a valid regex?

Copy link
Member

Choose a reason for hiding this comment

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

That would like throw an exception (can't remember which one)

Copy link
Contributor

@netodevel netodevel Apr 29, 2021

Choose a reason for hiding this comment

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

anyway i think there must be a test scenario for the exception that takes place

another question that came to me,
should this invalid data not let the application start?

Copy link
Member Author

Choose a reason for hiding this comment

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

Pattern.compile is part of the JDK, I am not going at add additional tests that verify the JDK is working as expected (unless we have reason to suspect there is a bug in the JDK, which is just not the case here).

If this is invalid the application will fail to start.

Copy link
Contributor

Choose a reason for hiding this comment

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

@stuartwdouglas,
I understand that it is a JDK feature .. but what I suggested was not to test Pattern.compile was the integration of your code with it.

Analogy:
You do not test how postgresql works, but you do test the integration of your app with it.

and still has the counterpoint of how a dev in the future knows that an exception in this code snippet should stop the app from starting?
how to guarantee that the change he will make will not impact?

@@ -117,6 +120,8 @@ public void run() throws Throwable {
Path path = logDirectory.resolve("server.log");
Assertions.assertTrue(Files.exists(path));
String data = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
Assertions.assertFalse(data.contains("/health"));
Assertions.assertFalse(data.contains("/liveliness"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be a other test in case of ingestion of an invalid regex.

this.excludePattern = Pattern.compile(excludePattern.get());
} else {
this.excludePattern = null;
}
}

public AccessLogHandler(final AccessLogReceiver accessLogReceiver, String formatString, final ExchangeAttribute attribute) {
Copy link
Contributor

Choose a reason for hiding this comment

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

String formatString Should it be final? Like other constructor above.

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes no practical difference.

Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

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

LGTM,
@netodevel has done a few comment. I let you see.

* A regular expression that can be used to exclude some paths from logging.
*/
@ConfigItem
Optional<String> excludePattern;
Copy link
Contributor

Choose a reason for hiding this comment

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

I created smallrye/smallrye-config#558 which should allow using Optional<Pattern> excludePattern here

@daurrutia
Copy link

Any chance there'd be an example for path such as /auth/resources/nje61/...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add configuration property to disable http access log for certain routes
5 participants