-
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
tracing: general tracing support #16049
Closed
+1,024
−726
Closed
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d78258e
first commit
520cdc9
fix format
43cc47e
fix proto format
8740d85
fix http connection manager test
38a2e80
clang-tidy
53d0c58
add more test
b259a2a
Merge branch 'main' of https://github.com/envoyproxy/envoy into gener…
bde8346
fix some name etc.
f7d9ce9
rename TracingContext to TraceContext
dc57c3c
Merge branch 'main' of https://github.com/envoyproxy/envoy into gener…
38aba26
remove used api and update trace context interface
e8427f0
Merge branch 'main' of https://github.com/envoyproxy/envoy into gener…
f535c8e
Merge branch 'main' of https://github.com/envoyproxy/envoy into gener…
5f0c81a
move lower case string to common and add new interface to trace conte…
d4d6910
update context key
6341150
fix format
1c5d1e0
make lower case string validator pluggable
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "common/common/assert.h" | ||
|
||
#include "absl/strings/ascii.h" | ||
#include "absl/strings/string_view.h" | ||
|
||
namespace Envoy { | ||
|
||
// Used by ASSERTs to validate internal consistency. E.g. valid HTTP header keys/values should | ||
// never contain embedded NULLs. | ||
static inline bool validHeaderString(absl::string_view s) { | ||
// If you modify this list of illegal embedded characters you will probably | ||
// want to change header_map_fuzz_impl_test at the same time. | ||
for (const char c : s) { | ||
switch (c) { | ||
case '\0': | ||
FALLTHRU; | ||
case '\r': | ||
FALLTHRU; | ||
case '\n': | ||
return false; | ||
default: | ||
continue; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Wrapper for a lower case string used in header operations to generally avoid needless case | ||
* insensitive compares. | ||
*/ | ||
class LowerCaseString { | ||
public: | ||
LowerCaseString(LowerCaseString&& rhs) noexcept : string_(std::move(rhs.string_)) { | ||
ASSERT(valid()); | ||
} | ||
LowerCaseString& operator=(LowerCaseString&& rhs) noexcept { | ||
string_ = std::move(rhs.string_); | ||
ASSERT(valid()); | ||
return *this; | ||
} | ||
|
||
LowerCaseString(const LowerCaseString& rhs) : string_(rhs.string_) { ASSERT(valid()); } | ||
LowerCaseString& operator=(const LowerCaseString& rhs) { | ||
string_ = std::move(rhs.string_); | ||
ASSERT(valid()); | ||
return *this; | ||
} | ||
|
||
explicit LowerCaseString(const absl::string_view new_string) : string_(new_string) { | ||
ASSERT(valid()); | ||
lower(); | ||
} | ||
|
||
const std::string& get() const { return string_; } | ||
bool operator==(const LowerCaseString& rhs) const { return string_ == rhs.string_; } | ||
bool operator!=(const LowerCaseString& rhs) const { return string_ != rhs.string_; } | ||
bool operator<(const LowerCaseString& rhs) const { return string_.compare(rhs.string_) < 0; } | ||
|
||
friend std::ostream& operator<<(std::ostream& os, const LowerCaseString& lower_case_string) { | ||
return os << lower_case_string.string_; | ||
} | ||
|
||
private: | ||
void lower() { | ||
std::transform(string_.begin(), string_.end(), string_.begin(), absl::ascii_tolower); | ||
} | ||
bool valid() const { return validHeaderString(string_); } | ||
|
||
std::string string_; | ||
}; | ||
|
||
/** | ||
* Convenient type for a vector of lower case string and string pair. | ||
*/ | ||
using LowerCaseStrPairVector = std::vector<std::pair<const LowerCaseString, const std::string>>; | ||
|
||
} // namespace Envoy |
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
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
Oops, something went wrong.
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.
drive-by comment: This is HTTP-specific and I think should under an http/ directory rather than under common.
I think I see why you wanted to do this: you wanted to add similar support for tracing that is not dependent on http, but then I think you would want to make the validator be pluggable or something, maybe via a template?
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.😄 Yes, I want add some similar support for tracing. A simple function pointer may be a good choice. Templates or virtual functions will introduce some type conversion problems, which is completely unnecessary.
The validation logic of validHeaderString should be universal, that is, it does not contain newline characters and does not contain null. We can use it as the default validator.
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'm not understanding why templates would create type conversion problems. But if you are going to use a function pointer you should use a new-style lambda.
Also you probably want to avoid having include/envoy/common/... reference include/envoy/http/... -- at least in my mind that should be a directed graph.
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.
@jmarantz
Don't care, I should be wrong in my thinking.
🤔 I was thinking too. Perhaps we can simply treat validHeaderString as a general validator. It does not have any special HTTP-specific logic, just ensure that the string is an ordinary single-line string that does not contain nulls.
This part will be a new independent PR. When it's ready, I will @ you, thanks 😄 .
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.
It is based on http char-set, though, isn't it?
The use of a template, or for that matter, a function pointer, lambda, or pure virtual function call, is that you could put the generic impl into common/ and the http-specific variant in http/ and you have a clean separation.
Come to think of it, do you want to always lower-case names for non-http?
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.
@jmarantz Thank you very much for your patience and suggestions.
If I just want to get a general LowerCaseString implementation, your idea is undoubtedly correct. But this question is somewhat different.
Because using RequestHeaderMapImpl to implement the
setTraceContext(absl::string_view)
/getTraceContext(absl::string_view)
interface, additional overhead will be introduced. We need to convert absl::string_view to lower case and always use copy semantics. So I hope to design a general LowerCaseString and add two overloaded interfaces that use LowerCaseString to TraceContext. In this way, for existing Http Tracer users, the introduction of general tracing will not bring any additional overhead.If I use virtual functions or inheritance solutions, use the base class in the TraceContext interface, such as LowerCaseStringBase. Then when RequestHeaderMapImpl implements the TraceContext interface, it will involve the protocol conversion from LowerCaseStringBase to Http::LowerCaseString (I now have some new ideals to circumvent this problem).
If I use function pointers, then we must use validHeaderString as the default value, because now Http::LowerCaseString has been widely used, we need to reduce the impact on existing code. The problem of using templates is similar to that of function pointers. In other words, LowerCaseString will depend on validHeaderString.