-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Implement omit_empty_values for access log formatters #12801
Conversation
Signed-off-by: Petr Pchelko <[email protected]>
Signed-off-by: Petr Pchelko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of changing this around so that Formatter::format
returns absl::optional<std::string>
? That makes it so that we don't have to re-implement the return empty string vs "-" logic in each formatter and can make the decision in FormatterImpl.
Yeah... When I've started I didn't realize how many places would need updating, changing the return type would prob be better. |
Signed-off-by: Petr Pchelko <[email protected]>
Changed the FormatterProvider interface to return an optional since it's reponsible for fetching a single value from the operator. Formatter::format returns a combination of multiple providers, so it doesn't really make sense to return an optional from it. |
Signed-off-by: Petr Pchelko <[email protected]>
Signed-off-by: Petr Pchelko <[email protected]>
Signed-off-by: Petr Pchelko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think this will be better in the long run. Some mostly style related stuff around use of optional but otherwise looks good.
Signed-off-by: Petr Pchelko <[email protected]>
Signed-off-by: Petr Pchelko <[email protected]>
Addressed review comments, thank you @zuercher. Also added a few more tests and a few convenience utility functions. |
Signed-off-by: Petr Pchelko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Can you run the substitution_formatter_speed_test before/after and make sure there's no performance regression?
Also needs @envoyproxy/api-shepherds approval. |
Thank you @zuercher Master:
Feature branch:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be about 10% slower, which is somewhat concerning. Are those results stable across runs?
My previous experience with this code tells me that the perf changes are normally due to extra string copies, but it doesn't seem like this introduces any except for protocol where before we were able to return a const std::string&
from the utility class, but is now copying the string into an absl::optional<std::string>
.
Actually, I wonder if value_or is the problem. It returns T
, not T&
so maybe that's actually inducing a string copy. Assuming the slowdown wasn't a side-effect of something else happening on your dev box, could you experiment with not using value_or? It's definitely easier to read with that syntax but I'd rather not slow the loggers down. If you do end up removing value_or please add a comment explaining why.
Signed-off-by: Petr Pchelko <[email protected]>
Signed-off-by: Petr Pchelko <[email protected]>
Here's the new benchmarks: https://gist.github.com/Pchelolo/704546cde3cf9fe9867eae00cfad8a9d The |
Signed-off-by: Petr Pchelko <[email protected]>
Signed-off-by: Petr Pchelko <[email protected]>
/lgtm api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! One last thing and I think we're good to go.
@@ -65,15 +65,15 @@ FormatterPtr SubstitutionFormatUtils::defaultSubstitutionFormatter() { | |||
return FormatterPtr{new FormatterImpl(DEFAULT_FORMAT, false)}; | |||
} | |||
|
|||
const absl::optional<std::string> | |||
const absl::optional<std::reference_wrapper<const std::string>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment here explaining why this is a reference_wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Signed-off-by: Petr Pchelko <[email protected]>
@@ -73,6 +73,8 @@ class SubstitutionFormatParser { | |||
class SubstitutionFormatUtils { | |||
public: | |||
static FormatterPtr defaultSubstitutionFormatter(); | |||
// Optional refences are not supported, but this method has large performance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg, sorry about that. Fixed.
Signed-off-by: Petr Pchelko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Signed-off-by: Petr Pchelko [email protected]
Commit Message: Introduce an option to entirely omit null values from access log
Additional Description:
Risk Level: Low
Testing: unit/integration tests
Docs Changes: new option documented in proto file
Release Notes: updated
Fixes #12735