-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
formatter: use the new json lib to relace protobuf json #36530
Merged
wbpcode
merged 2 commits into
envoyproxy:main
from
wbpcode:dev-improve-serialize-of-value
Oct 16, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include "source/common/common/random_generator.h" | ||
#include "source/common/config/metadata.h" | ||
#include "source/common/http/utility.h" | ||
#include "source/common/json/json_utility.h" | ||
#include "source/common/runtime/runtime_features.h" | ||
#include "source/common/stream_info/utility.h" | ||
|
||
|
@@ -61,20 +62,11 @@ MetadataFormatter::formatMetadata(const envoy::config::core::v3::Metadata& metad | |
} | ||
|
||
std::string str; | ||
str.reserve(256); | ||
if (value.kind_case() == ProtobufWkt::Value::kStringValue) { | ||
str = value.string_value(); | ||
} else { | ||
#ifdef ENVOY_ENABLE_YAML | ||
absl::StatusOr<std::string> json_or_error = | ||
MessageUtil::getJsonStringFromMessage(value, false, true); | ||
if (json_or_error.ok()) { | ||
str = json_or_error.value(); | ||
} else { | ||
str = json_or_error.status().message(); | ||
} | ||
#else | ||
IS_ENVOY_BUG("Json support compiled out"); | ||
#endif | ||
Json::Utility::appendValueToString(value, str); | ||
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 do love having one less non-YAML special case, thanks :-) |
||
} | ||
SubstitutionFormatUtils::truncate(str, max_length_); | ||
return str; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be runtime guarded?
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.
I am not sure. Because, this behavior change means:
For a NaN value, the output of the command will be changed from
google.protobuf.Value cannot encode double values for nan, because it would be parsed as a string
tonull
.For a Infinity value, the output of the command will be changed from
google.protobuf.Value cannot encode double values for infinity, because it would be parsed as a string
toInf
.I doubt no one will depend on original behavior. So, not sure if it deserve a runtime flag.
Defer this to you to determine should we need to add a runtime flag for this. Anyway decision is fine to me. :)