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 support for nested JSON format in json logging mode #12602

Merged
merged 7 commits into from
Aug 21, 2020

Conversation

Pchelolo
Copy link
Contributor

@Pchelolo Pchelolo commented Aug 12, 2020

This adds support for nesting in JSON logging mode. There is another opportunity for improvement - support static non-string values, but I guess we can do this separately.

Commit Message: Add support for nested JSON format in JSON logging mode.
Risk Level: Low, feature only used if nested objects are configured, thus opt-in.
Testing: unit tests
Docs Changes: yes
Release Notes: added to current.rst
Fixes #12582

Signed-off-by: Petr Pchelko ppchelko@wikimedia.org

Petr Pchelko added 3 commits August 10, 2020 21:15
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Thanks!

Have you run the substitution_formatter_speed_test before/after this change? It doesn't seem like it should change the performance for flat json formats, but I'd like to confirm.

source/common/formatter/substitution_formatter.cc Outdated Show resolved Hide resolved
source/common/formatter/substitution_formatter.h Outdated Show resolved Hide resolved
Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
@Pchelolo
Copy link
Contributor Author

@zuercher thank you for the review, updated according to your comments.

@aa-stripe
Copy link
Contributor

🎉

happy to see this going through so quickly!

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
@zuercher
Copy link
Member

Can you run the speed test noted above and confirm there’s no significant degradation? Thanks.

@Pchelolo
Copy link
Contributor Author

Pchelolo commented Aug 14, 2020

Oh, sorry @zuercher, I've totally missed your comment about the speed test!

master

-------------------------------------------------------------------------
Benchmark                               Time             CPU   Iterations
-------------------------------------------------------------------------
BM_AccessLogFormatter               12882 ns        12795 ns        55076
BM_JsonAccessLogFormatter          280000 ns       278318 ns         2459
BM_TypedJsonAccessLogFormatter     260001 ns       258375 ns         2635

feature branch

-------------------------------------------------------------------------
Benchmark                               Time             CPU   Iterations
-------------------------------------------------------------------------
BM_AccessLogFormatter               10059 ns        10038 ns        71441
BM_JsonAccessLogFormatter          284222 ns       283625 ns         2468
BM_TypedJsonAccessLogFormatter     277584 ns       277049 ns         2535

The numbers seem comparable.

zuercher
zuercher previously approved these changes Aug 17, 2020
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Thanks!

cc @dio for a second pass

Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Thanks, very well done! Few comments:

@@ -129,37 +124,61 @@ std::string JsonFormatterImpl::format(const Http::RequestHeaderMap& request_head
return absl::StrCat(log_line, "\n");
}

JsonFormatterImpl::JsonFormatMap
JsonFormatterImpl::toFormatMap(const ProtobufWkt::Struct& json_format) const {
auto output = std::make_unique<std::map<std::string, JsonFormatterImpl::JsonFormatMapValue>>();
Copy link
Member

@dio dio Aug 20, 2020

Choose a reason for hiding this comment

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

I assume we want to preserve order here? Do you mind adding comments here so we understand why we choose std::map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Given that I've made aliases per the other comment, the explanation comment is now in the header file where the type's defined.

using JsonFormatMapValue =
absl::variant<const std::vector<FormatterProviderPtr>, const JsonFormatMap>;
struct JsonFormatMap {
std::unique_ptr<std::map<std::string, JsonFormatMapValue>> value_;
Copy link
Member

Choose a reason for hiding this comment

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

We usually have a typedef for this. But I don't feel strongly about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some aliases. Looks more readable indeed now.

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
using JsonFormatMapValue =
absl::variant<const std::vector<FormatterProviderPtr>, const JsonFormatMapWrapper>;
// Although not required for JSON, it is nice to have the order of properties
// preserved between the format and the log entry, thus std::map
Copy link
Member

@dio dio Aug 20, 2020

Choose a reason for hiding this comment

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

Since you need to fix format anyway, please end this with full-stop. Thanks.

// preserved between the format and the log entry, thus std::map
using JsonFormatMap = std::map<std::string, JsonFormatMapValue>;
using JsonFormatMapPtr = std::unique_ptr<JsonFormatMap>;
struct JsonFormatMapWrapper{
Copy link
Member

Choose a reason for hiding this comment

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

Here. Missing space between JsonFormatMapWrapper and {.

Signed-off-by: Petr Pchelko <ppchelko@wikimedia.org>
@dio
Copy link
Member

dio commented Aug 20, 2020

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines, to retry CircleCI checks, use /retest-circle.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #12602 (comment) was created by @dio.

see: more, trace.

Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Thank you!

@zuercher zuercher merged commit 04ce876 into envoyproxy:master Aug 21, 2020
lavignes added a commit to lavignes/envoy that referenced this pull request Aug 24, 2020
* envoy/master: (90 commits)
  cleanup: use structured binding (envoyproxy#12791)
  docs: fix header name for retries in gRPC services (envoyproxy#12790)
  docs: clarify meaning of HeaderValueOption.append (envoyproxy#12792)
  doc: clarify handling of duplicate xDS resource names (envoyproxy#12756)
  Dependencies: build updates. (envoyproxy#12786)
  Ratelimit: Add optional descriptor key to generic_key action (envoyproxy#12734)
  test: refactor header inclusion to speed up building (for test/mocks/upstream:upstream_mocks)  (envoyproxy#12407)
  docs: Fix omitted word (envoyproxy#12782)
  ci: avoid uploading dwp as separate artifact (envoyproxy#12777)
  doc: Fix small typos (envoyproxy#12769)
  fix cache factory category (envoyproxy#12765)
  docs: fix typo v1.15.0.rst (envoyproxy#12680)
  Add clang-cl RBE toolchain for Windows (envoyproxy#12776)
  fuzz: add router fuzz proto (envoyproxy#12727)
  header: New HeaderMatcher and StringMatcher type - Contains (envoyproxy#12623)
  tcp_proxy: use dynamicMetadata() from StreamInfo for load balancing (envoyproxy#12595)
  network: add io handle recv function for http inspector (envoyproxy#12736)
  jwt_authn: supports jwt payload without "iss" field (envoyproxy#12744)
  Add support for nested JSON format in json logging mode (envoyproxy#12602)
  http: fixing a fuzz flake by setting details on connection teardown (envoyproxy#12737)
  ...

Signed-off-by: Scott LaVigne <lavignes@amazon.com>
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.

Proposal: Support nested structures JSON formatted in access_log
4 participants