Converting mongo proxy to v2 api#1952
Conversation
htuch
left a comment
There was a problem hiding this comment.
Looks good! Thanks for taking on this task, it was one of the last mile things we need for v2 completeness.
source/common/config/filter_json.cc
Outdated
| delay->set_type(envoy::api::v2::filter::FaultDelay::FaultDelayType::FIXED); | ||
| delay->set_percent(static_cast<uint32_t>(json_fault->getInteger("percent"))); | ||
| delay->mutable_fixed_delay()->CopyFrom( | ||
| Protobuf::util::TimeUtil::MillisecondsToDuration(json_fault->getInteger("duration_ms"))); |
There was a problem hiding this comment.
JSON_UTIL_SET_DURATION, we probably need a variant where the old/new field names are different as well.
| // NamedNetworkFilterConfigFactory | ||
| NetworkFilterFactoryCb createFilterFactory(const Json::Object& config, | ||
| FactoryContext& context) override; | ||
| NetworkFilterFactoryCb createFilterFactoryFromProto(const Protobuf::Message& config, |
There was a problem hiding this comment.
You will also need to provider the factory https://github.com/envoyproxy/envoy/blob/master/include/envoy/server/filter_config.h#L173.
There was a problem hiding this comment.
Can we make sure we have tests that cover both the legacy and factory config flows also when you fix this. Thank you!
There was a problem hiding this comment.
I have not touched any existing tests other than fixing up the class names. And the existing tests use JSON config for testing. i.e. they exercise the conversion and tests pass.
There was a problem hiding this comment.
Right my point is can you please make sure that the native proto loading path for v2 config is covered, and not just the conversion path. You may need to add new tests. I think this is important as we add the rest of the filters.
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
|
Added tests for protos. PTAL. |
mattklein123
left a comment
There was a problem hiding this comment.
looks great. thank for doing this work. Some small comments/nits.
source/common/config/filter_json.h
Outdated
|
|
||
| /** | ||
| * Translate a v1 JSON Mongo proxy object to v2 | ||
| * envoy::api::v2::filter::network::MongoProxy. |
source/server/config/network/BUILD
Outdated
| "//include/envoy/server:filter_config_interface", | ||
| "//source/common/config:well_known_names", | ||
| "//source/common/json:config_schemas_lib", | ||
| "//source/common/json:json_loader_lib", |
| const envoy::api::v2::filter::network::MongoProxy& mongo_proxy, FactoryContext& context) { | ||
|
|
||
| if (mongo_proxy.stat_prefix().empty()) { | ||
| throw MissingFieldException("stat_prefix", mongo_proxy); |
There was a problem hiding this comment.
@htuch should we include this since this would be covered by validators? My thinking is to remove this check and possibly just have an ASSERT.
There was a problem hiding this comment.
We can't run some negative tests without these. Thats the reason for adding these.
There was a problem hiding this comment.
But if it's code we don't need why would we add it? I would just put in an assert and remove the tests?
| if (mongo_proxy.has_delay()) { | ||
| auto delay = mongo_proxy.delay(); | ||
| if (!delay.has_fixed_delay()) { | ||
| throw MissingFieldException("delay.fixed_delay", mongo_proxy); |
| * Config registration for the mongo proxy filter. @see NamedNetworkFilterConfigFactory. | ||
| */ | ||
| class MongoProxyFilterConfigFactory : public NamedNetworkFilterConfigFactory { | ||
| NetworkFilterFactoryCb |
There was a problem hiding this comment.
if this is meant to be private, should go in private section below public section.
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
|
|
||
| #include "common/json/config_schemas.h" | ||
| #include "common/config/filter_json.h" | ||
| #include "common/json/json_loader.h" |
There was a problem hiding this comment.
nit: do we need this include now? (I think you just need interface JSON include). If so please fix BUILD file also.
| * Config registration for the mongo proxy filter. @see NamedNetworkFilterConfigFactory. | ||
| */ | ||
| class MongoProxyFilterConfigFactory : public NamedNetworkFilterConfigFactory { | ||
|
|
|
|
||
| // Set a google.protobuf.Duration field in a protobuf message with the specified field's | ||
| // milliseconds value from a JSON object if the field is set in the JSON object. | ||
| #define JSON_UTIL_SET_DURATION_FROM_FIELD(json, message, dst_field, src_field) \ |
There was a problem hiding this comment.
Nit: probably should define JSON_UTIL_SET_DURATION in terms of this macro now.
There was a problem hiding this comment.
can I do this in next PR for redis?
There was a problem hiding this comment.
Yes that's fine. Please do in the next PR.
| cb(connection); | ||
| } | ||
|
|
||
| TEST(MongoFilterConfigTest, CorrectProtoConfigurationNoFaults) { |
There was a problem hiding this comment.
Nit: I would rename "correct" to "valid".
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
No description provided.