-
Notifications
You must be signed in to change notification settings - Fork 5.2k
formatter: add query_params to log all params #42891
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,6 +304,56 @@ QueryParameterFormatter::formatValue(const Context& context, | |
| return ValueUtil::optionalStringValue(format(context, stream_info)); | ||
| } | ||
|
|
||
| absl::StatusOr<FormatterProviderPtr> QueryParametersFormatter::create(absl::string_view decoding, | ||
| absl::optional<size_t> max_length) { | ||
| bool decode_bool = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this logic into the constructor? It is better to parse the config at config time, than at runtime. E.g. save
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will align this with how the |
||
| if (decoding.empty()) { | ||
| decode_bool = false; | ||
| } else if (decoding == "ORIG") { | ||
| decode_bool = false; | ||
| } if (decoding == "DECODED") { | ||
| decode_bool = true; | ||
| } else { | ||
| return absl::InvalidArgumentError( | ||
| fmt::format("Invalid QUERY_PARAMS option: '{}', only 'ORIG'/'DECODED' are allowed", decoding)); | ||
| } | ||
|
|
||
| return std::make_unique<QueryParametersFormatter>(decode_bool, max_length); | ||
| } | ||
|
|
||
| // FormatterProvider | ||
| absl::optional<std::string> QueryParametersFormatter::format(const Context& context, | ||
| const StreamInfo::StreamInfo&) const { | ||
| const auto request_headers = context.requestHeaders(); | ||
| if (!request_headers.has_value()) { | ||
| return absl::nullopt; | ||
| } | ||
|
|
||
| // Gather query parameters substring from path | ||
| absl::string_view path_view = request_headers->getPathValue(); | ||
| auto query_offset = path_view.find('?'); | ||
| absl::optional<string_view> query_params; | ||
| if (query_offset != absl::string_view::npos) { | ||
| query_params = path_view.substr(query_offset+1); | ||
| } | ||
|
|
||
| // Apply query param percent decoding on the query params if requested | ||
| if (query_params.has_value() && decode_bool) { | ||
| query_params = Http::Utility::PercentEncoding::urlDecodeQueryParameter(query_params); | ||
| } | ||
|
|
||
| if (query_params.has_value() && max_length_.has_value()) { | ||
| SubstitutionFormatUtils::truncate(query_params.value(), max_length_.value()); | ||
| } | ||
| return query_params; | ||
| } | ||
|
|
||
| Protobuf::Value | ||
| QueryParametersFormatter::formatValue(const Context& context, | ||
| const StreamInfo::StreamInfo& stream_info) const { | ||
| return ValueUtil::optionalStringValue(format(context, stream_info)); | ||
| } | ||
|
|
||
| absl::optional<std::string> PathFormatter::format(const Context& context, | ||
| const StreamInfo::StreamInfo&) const { | ||
|
|
||
|
|
@@ -495,6 +545,11 @@ BuiltInHttpCommandParser::getKnownFormatters() { | |
| [](absl::string_view format, absl::optional<size_t> max_length) { | ||
| return std::make_unique<QueryParameterFormatter>(std::string(format), max_length); | ||
| }}}, | ||
| {"QUERY_PARAMS", | ||
| {CommandSyntaxChecker::PARAMS_OPTIONAL | CommandSyntaxChecker::LENGTH_ALLOWED, | ||
| [](absl::string_view decoding, absl::optional<size_t> max_length) { | ||
| return std::make_unique<QueryParametersFormatter>(std::string(decoding), max_length); | ||
| }}}, | ||
| {"PATH", | ||
| {CommandSyntaxChecker::PARAMS_OPTIONAL | CommandSyntaxChecker::LENGTH_ALLOWED, | ||
| [](absl::string_view format, absl::optional<size_t> max_length) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.