Skip to content

Converting mongo proxy to v2 api#1952

Merged
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
amalgam8:mongo_proxy_v2
Oct 30, 2017
Merged

Converting mongo proxy to v2 api#1952
mattklein123 merged 12 commits intoenvoyproxy:masterfrom
amalgam8:mongo_proxy_v2

Conversation

@rshriram
Copy link
Member

No description provided.

Shriram Rajagopalan added 3 commits October 26, 2017 16:51
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
nit
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for taking on this task, it was one of the last mile things we need for v2 completeness.

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")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure we have tests that cover both the legacy and factory config flows also when you fix this. Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@mattklein123 mattklein123 Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Shriram Rajagopalan added 2 commits October 27, 2017 10:51
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
@rshriram rshriram changed the title [wip] Converting mongo proxy to v2 api Converting mongo proxy to v2 api Oct 27, 2017
Shriram Rajagopalan added 2 commits October 27, 2017 15:03
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
@rshriram
Copy link
Member Author

Added tests for protos. PTAL.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great. thank for doing this work. Some small comments/nits.


/**
* Translate a v1 JSON Mongo proxy object to v2
* envoy::api::v2::filter::network::MongoProxy.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: flow to 100 col

"//include/envoy/server:filter_config_interface",
"//source/common/config:well_known_names",
"//source/common/json:config_schemas_lib",
"//source/common/json:json_loader_lib",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

del also?

const envoy::api::v2::filter::network::MongoProxy& mongo_proxy, FactoryContext& context) {

if (mongo_proxy.stat_prefix().empty()) {
throw MissingFieldException("stat_prefix", mongo_proxy);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't run some negative tests without these. Thats the reason for adding these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

* Config registration for the mongo proxy filter. @see NamedNetworkFilterConfigFactory.
*/
class MongoProxyFilterConfigFactory : public NamedNetworkFilterConfigFactory {
NetworkFilterFactoryCb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is meant to be private, should go in private section below public section.

Shriram Rajagopalan added 3 commits October 27, 2017 17:17
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>

#include "common/json/config_schemas.h"
#include "common/config/filter_json.h"
#include "common/json/json_loader.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: del newline

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo comments.


// 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) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: probably should define JSON_UTIL_SET_DURATION in terms of this macro now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I do this in next PR for redis?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's fine. Please do in the next PR.

cb(connection);
}

TEST(MongoFilterConfigTest, CorrectProtoConfigurationNoFaults) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would rename "correct" to "valid".

Shriram Rajagopalan added 2 commits October 29, 2017 19:38
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
Signed-off-by: Shriram Rajagopalan <shriram@us.ibm.com>
@mattklein123 mattklein123 merged commit d5260a5 into envoyproxy:master Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants