-
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
ext_proc: send attributes #31090
Merged
yanavlasov
merged 49 commits into
envoyproxy:main
from
jbohanon:feature/ext_proc/request-response-attributes
Jan 24, 2024
Merged
ext_proc: send attributes #31090
Changes from 42 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
87cf9ba
extract attributes changes from #29069
jbohanon 45ec23d
fix ordering test constructor
jbohanon 0a9f228
don't do CEL stuff if no attributes are configured
jbohanon 6826a1c
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon 9857119
fix variable shadowing
jbohanon c26d44c
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon db599b9
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon a4454be
refactor matching utils out
jbohanon 34b8fbc
refactor matching utils out
jbohanon d5ce702
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon 3631683
fix pointer/references
jbohanon 47c2b46
where are my CEL objects going
jbohanon 86ae01f
fix lifetime issue and clean up
jbohanon 0d8f5d4
fix runtime feature format
jbohanon dc692e1
declare iter as reference
jbohanon 8a28f0d
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon 8d34e78
fix tests and clean up
jbohanon fd598b9
skip fuzzing request and response attributes on ASAN_FUZZER due to un…
jbohanon 2954fc7
use unique_ptr instead of absl::optional for struct, reference for ac…
jbohanon 520d511
use object to store pair of parsed, compiled expression
jbohanon 2778b97
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon f6bbcf7
inline CelExpression initialization into emplace call
jbohanon fbdbfb4
raw ptr working
jbohanon 5192143
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon 58faac1
update dep allowlist
jbohanon 19fdb00
use serverFactoryContext to get builder singleton
jbohanon 8948d0f
update dep allowlist
jbohanon fe68f15
PR comments
jbohanon d6cb932
kick CI
jbohanon ca13534
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon ae4258d
plumb through local info
jbohanon 8e02036
kick CI -- RBE cache error in iOS
jbohanon d4d94e6
add inludes for MockLocalInfo
jbohanon 906183f
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon ebd053c
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon 7019dd1
kick CI
jbohanon defdd94
kick CI
jbohanon c86a731
kick CI
jbohanon 0b3e715
kick CI
jbohanon 374770f
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon a3e689f
revert unwanted local build change
jbohanon 2c716b7
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon 9948c57
add skip_on_windows due to recent CEL bump
jbohanon 7d58055
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon fcaa5af
fix BUILD
jbohanon 5fac8a5
skip client build on windows
jbohanon 970fb4d
MORE SKIP ON WINDOWS
jbohanon a43136e
add filter to windows skip in bazel/repositories.bzl
jbohanon cfe7006
Merge branch 'main' into feature/ext_proc/request-response-attributes
jbohanon 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
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
102 changes: 102 additions & 0 deletions
102
source/extensions/filters/http/ext_proc/matching_utils.cc
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,102 @@ | ||
#include "source/extensions/filters/http/ext_proc/matching_utils.h" | ||
|
||
#include <memory> | ||
|
||
#if defined(USE_CEL_PARSER) | ||
#include "parser/parser.h" | ||
#endif | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace ExternalProcessing { | ||
|
||
absl::flat_hash_map<std::string, ExpressionManager::CelExpression> | ||
ExpressionManager::initExpressions(const Protobuf::RepeatedPtrField<std::string>& matchers) { | ||
absl::flat_hash_map<std::string, ExpressionManager::CelExpression> expressions; | ||
#if defined(USE_CEL_PARSER) | ||
for (const auto& matcher : matchers) { | ||
if (expressions.contains(matcher)) { | ||
continue; | ||
} | ||
auto parse_status = google::api::expr::parser::Parse(matcher); | ||
jbohanon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!parse_status.ok()) { | ||
throw EnvoyException("Unable to parse descriptor expression: " + | ||
parse_status.status().ToString()); | ||
} | ||
|
||
Filters::Common::Expr::ExpressionPtr expression = | ||
Extensions::Filters::Common::Expr::createExpression(builder_->builder(), | ||
parse_status.value().expr()); | ||
|
||
expressions.emplace( | ||
matcher, ExpressionManager::CelExpression{parse_status.value(), std::move(expression)}); | ||
} | ||
#else | ||
ENVOY_LOG(warn, "CEL expression parsing is not available for use in this environment." | ||
" Attempted to parse " + | ||
std::to_string(matchers.size()) + " expressions"); | ||
#endif | ||
return expressions; | ||
} | ||
|
||
ProtobufWkt::Struct | ||
ExpressionManager::evaluateAttributes(const Filters::Common::Expr::Activation& activation, | ||
const absl::flat_hash_map<std::string, CelExpression>& expr) { | ||
|
||
ProtobufWkt::Struct proto; | ||
|
||
if (expr.empty()) { | ||
return proto; | ||
} | ||
|
||
for (const auto& hash_entry : expr) { | ||
ProtobufWkt::Arena arena; | ||
const auto result = hash_entry.second.compiled_expr_->Evaluate(activation, &arena); | ||
if (!result.ok()) { | ||
// TODO: Stats? | ||
continue; | ||
} | ||
|
||
if (result.value().IsError()) { | ||
ENVOY_LOG(trace, "error parsing cel expression {}", hash_entry.first); | ||
continue; | ||
} | ||
|
||
ProtobufWkt::Value value; | ||
switch (result.value().type()) { | ||
case google::api::expr::runtime::CelValue::Type::kBool: | ||
value.set_bool_value(result.value().BoolOrDie()); | ||
break; | ||
case google::api::expr::runtime::CelValue::Type::kNullType: | ||
value.set_null_value(ProtobufWkt::NullValue{}); | ||
break; | ||
case google::api::expr::runtime::CelValue::Type::kDouble: | ||
value.set_number_value(result.value().DoubleOrDie()); | ||
break; | ||
default: | ||
value.set_string_value(Filters::Common::Expr::print(result.value())); | ||
} | ||
|
||
auto proto_mut_fields = proto.mutable_fields(); | ||
(*proto_mut_fields)[hash_entry.first] = value; | ||
} | ||
|
||
return proto; | ||
} | ||
|
||
std::vector<Matchers::StringMatcherPtr> | ||
initHeaderMatchers(const envoy::type::matcher::v3::ListStringMatcher& header_list) { | ||
std::vector<Matchers::StringMatcherPtr> header_matchers; | ||
for (const auto& matcher : header_list.patterns()) { | ||
header_matchers.push_back( | ||
std::make_unique<Matchers::StringMatcherImpl<envoy::type::matcher::v3::StringMatcher>>( | ||
matcher)); | ||
} | ||
return header_matchers; | ||
} | ||
|
||
} // namespace ExternalProcessing | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
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.
Should proto be passed by reference?
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.
We use
nullptr
to indicate that attributes are not configured. This is on Line 243