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 contentLogLevel task property #193

Merged
merged 1 commit into from
May 20, 2020
Merged

Add contentLogLevel task property #193

merged 1 commit into from
May 20, 2020

Conversation

fvaleri
Copy link

@fvaleri fvaleri commented May 6, 2020

We should not log record's payload by default, as it may contain sensitive information. Anyway it is useful to have a configuration option to enable/disable it for debugging purpose.

Proposing new boolean config named camel.source.logPayload.

@davsclaus
Copy link
Contributor

It appears the existing logging is at DEBUG logging level. This new option dont mention this fact so I would assume end users think its logged at INFO logging or always.

Also it may not only be message body that has sensitive data. Headers can contain autorization tokens, usernames etc. So its probably better to have this option for all of it or nothing.

Copy link
Contributor

@oscerd oscerd left a comment

Choose a reason for hiding this comment

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

This must be applied on all the entity in the exchange not body only

@fvaleri
Copy link
Author

fvaleri commented May 6, 2020

It appears the existing logging is at DEBUG logging level. This new option dont mention this fact so I would assume end users think its logged at INFO logging or always.

Yes now is at DEBUG level, which is often set when debugging issues. The proposed option logs at INFO level only if the user explicitly set camel.source.logPayload=true, so it's somewhat independent from log level (unless you set it to OFF).

Also it may not only be message body that has sensitive data. Headers can contain autorization tokens, usernames etc. So its probably better to have this option for all of it or nothing.

It's actually including all of this, maybe the option name is not clear enough. I'm open to suggestions for better wording.

@davsclaus
Copy link
Contributor

You can also have the option about the logging level, we do this in Camel, then you can set it to DEBUG, INFO, OFF etc

@fvaleri fvaleri changed the title CAMEL-15018 Add camel.source.logPayload boolean config [CAMEL-15018] Add camel.source.logPayload boolean config May 6, 2020
@fvaleri
Copy link
Author

fvaleri commented May 6, 2020

You can also have the option about the logging level, we do this in Camel, then you can set it to DEBUG, INFO, OFF etc

Good idea. Will do that.

@oscerd
Copy link
Contributor

oscerd commented May 6, 2020

For the Thread.sleep I'm already opening a PR using Awaitility

@davsclaus
Copy link
Contributor

btw for logging you can use CamelLogger that can do the INFO, DEBUG, OFF etc
https://github.com/apache/camel/blob/master/core/camel-api/src/main/java/org/apache/camel/spi/CamelLogger.java

@fvaleri
Copy link
Author

fvaleri commented May 6, 2020

For the Thread.sleep I'm already opening a PR using Awaitility

Thanks

@fvaleri fvaleri changed the title [CAMEL-15018] Add camel.source.logPayload boolean config [CAMEL-15018] Add logRecordContent boolean config property May 6, 2020
@fvaleri
Copy link
Author

fvaleri commented May 6, 2020

Added the log option at the record level. Build is failing because of that flaky test that @oscerd is fixing with another PR.

If we want to use the logging level instead of the boolean parameter, then I would need to create an utility class with a switch-case method to not hard-wire knowledge of what logging system is behind the slf4j facade. In that case we could set it to OFF by default.

@fvaleri fvaleri changed the title [CAMEL-15018] Add logRecordContent boolean config property [CAMEL-15018] Do not log ConnectRecord content by default May 7, 2020
@valdar
Copy link
Member

valdar commented May 8, 2020

@fvaleri can you please rebase this PR on master and push -f on the PR so a Github Action run is triggered afresh and we can see if the flakey tests are fixed?

@fvaleri
Copy link
Author

fvaleri commented May 9, 2020

@valdar done, but I still see random build failures:

[ERROR] org.apache.camel.kafkaconnector.CamelSourceTaskTest.testUrlPrecedenceOnComponentProperty  Time elapsed: 0.026 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <2> but was: <1>
	at org.apache.camel.kafkaconnector.CamelSourceTaskTest.testUrlPrecedenceOnComponentProperty(CamelSourceTaskTest.java:230)```

@valdar
Copy link
Member

valdar commented May 9, 2020

Yep, I will look into it, prepare to more rebases :D

@fvaleri
Copy link
Author

fvaleri commented May 9, 2020

Yeah no problem, I'm using the following simple script to test and in addition to testUrlPrecedenceOnComponentProperty there is also testSourcePolling that remains flaky. We must get rid of all those sleeps, I will also have a look later.

#!/bin/sh
for (( i = 1; ; i++ ))
do
  echo "Attempt $i"
  mvn test -pl core -am
  exitcode=$?
  if [ $exitcode -ne 0 ]
  then
    echo "Error at attempt $i"
    exit
  fi
done

@valdar
Copy link
Member

valdar commented May 9, 2020

I fixed testUrlPrecedenceOnComponentProperty since the purpose of that test wasn't to count messages in a given time frame. Regarding testSourcePolling it is a little bit more complicated since the purpose of the test is to ensure that ~2 messages are received in the given unit of time... we can be a little bit more permissive there, by increasing the number of messages and account for a +/-1 error... I am open to suggestions though.

@fvaleri
Copy link
Author

fvaleri commented May 9, 2020

Sent my proposal on a dedicated PR, hope it's useful.

@fvaleri fvaleri changed the title [CAMEL-15018] Do not log ConnectRecord content by default Do not log ConnectRecord content by default May 10, 2020
@valdar
Copy link
Member

valdar commented May 12, 2020

@fvaleri can you rebase this on master (again 😞 ) so we (finally 🥳 ) get it merged?

@fvaleri
Copy link
Author

fvaleri commented May 12, 2020

If we want to use the logging level instead of the boolean parameter, then I would need to create an utility class with a switch-case method to not hard-wire knowledge of what logging system is behind the slf4j facade. In that case we could set it to OFF by default.

Sure let me do it. I'm quoting myself here with a different approach, but I would need to explore it. What do you think?

@valdar
Copy link
Member

valdar commented May 12, 2020

@fvaleri if you want to look into use the log level instead of a boolean you are welcome to do so; before writing your own utility class though, take a look at what @davsclaus suggested: https://github.com/apache/camel/blob/master/core/camel-api/src/main/java/org/apache/camel/spi/CamelLogger.java it might have all the pieces you need.

@fvaleri
Copy link
Author

fvaleri commented May 12, 2020

@valdar I think it's a better approach but I need to find some time to play with it. Bear with me, I will update this PR.

@fvaleri fvaleri requested review from valdar and oscerd May 16, 2020 17:12
@fvaleri fvaleri changed the title Do not log ConnectRecord content by default Add contentLogLevel task property May 16, 2020
Copy link
Member

@valdar valdar left a comment

Choose a reason for hiding this comment

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

In the end have you decided to not use CamelLogger? I am not implying is wrong, I am just asking.

@fvaleri fvaleri requested a review from valdar May 20, 2020 19:45
Copy link
Member

@valdar valdar left a comment

Choose a reason for hiding this comment

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

LGTM

@valdar valdar merged commit 569cc3e into apache:master May 20, 2020
@valdar
Copy link
Member

valdar commented May 20, 2020

Thanks for the contribution @fvaleri !

@fvaleri fvaleri deleted the log-payload branch May 22, 2020 06:43
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.

4 participants