Implement omit_empty_values for access log formatters#12801
Implement omit_empty_values for access log formatters#12801dio merged 15 commits intoenvoyproxy:masterfrom
Conversation
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
zuercher
left a comment
There was a problem hiding this comment.
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 <ppchelko@wikimedia.org>
|
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 <ppchelko@wikimedia.org>
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
zuercher
left a comment
There was a problem hiding this comment.
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 <ppchelko@wikimedia.org>
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
|
Addressed review comments, thank you @zuercher. Also added a few more tests and a few convenience utility functions. |
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
zuercher
left a comment
There was a problem hiding this comment.
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: |
zuercher
left a comment
There was a problem hiding this comment.
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 <ppchelko@wikimedia.org>
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
|
Here's the new benchmarks: https://gist.github.com/Pchelolo/704546cde3cf9fe9867eae00cfad8a9d The |
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
|
/lgtm api |
zuercher
left a comment
There was a problem hiding this comment.
Thanks! One last thing and I think we're good to go.
| } | ||
|
|
||
| const absl::optional<std::string> | ||
| const absl::optional<std::reference_wrapper<const std::string>> |
There was a problem hiding this comment.
Let's add a comment here explaining why this is a reference_wrapper.
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
| class SubstitutionFormatUtils { | ||
| public: | ||
| static FormatterPtr defaultSubstitutionFormatter(); | ||
| // Optional refences are not supported, but this method has large performance |
There was a problem hiding this comment.
Omg, sorry about that. Fixed.
Signed-off-by: Petr Pchelko ppchelko@wikimedia.org
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