Skip to content

Commit

Permalink
Merge "Option to disable flow collection in contrail-collector" into …
Browse files Browse the repository at this point in the history
…R2.20
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Feb 9, 2016
2 parents ff61157 + 15b64c6 commit b709340
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/analytics/collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,23 @@ void DiscoveryClientPublisherStatsReq::HandleRequest() const {
resp->set_more(false);
resp->Response();
}

static void SendFlowCollectionStatusResponse(std::string context) {
FlowCollectionStatusResponse *fcsr(new FlowCollectionStatusResponse);
fcsr->set_disable(Sandesh::IsFlowCollectionDisabled());
fcsr->set_context(context);
fcsr->Response();
}

void DisableFlowCollectionRequest::HandleRequest() const {
if (__isset.disable) {
Sandesh::DisableFlowCollection(get_disable());
}
// Send response
SendFlowCollectionStatusResponse(context());
}

void FlowCollectionStatusRequest::HandleRequest() const {
// Send response
SendFlowCollectionStatusResponse(context());
}
10 changes: 10 additions & 0 deletions src/analytics/collector_uve.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,13 @@ uve sandesh SandeshMessageTrace {
1: SandeshMessageStat data
}

request sandesh DisableFlowCollectionRequest {
1: optional bool disable
}

request sandesh FlowCollectionStatusRequest {
}

response sandesh FlowCollectionStatusResponse {
1: bool disable
}
1 change: 1 addition & 0 deletions src/analytics/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ int main(int argc, char *argv[])
exit(1);
}

Sandesh::DisableFlowCollection(options.disable_flow_collection());
Sandesh::SetLoggingParams(options.log_local(), options.log_category(),
options.log_level());

Expand Down
3 changes: 3 additions & 0 deletions src/analytics/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ void Options::Initialize(EventManager &evm,
"ipfix listener UDP port (< 0 will disable ipfix Collector)")
("DEFAULT.test_mode", opt::bool_switch(&test_mode_),
"Enable collector to run in test-mode")
("DEFAULT.disable_flow_collection",
opt::bool_switch(&disable_flow_collection_),
"Disable flow message collection")

("DISCOVERY.port", opt::value<uint16_t>()->default_value(
default_discovery_port),
Expand Down
2 changes: 2 additions & 0 deletions src/analytics/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Options {
const int sflow_port() const { return sflow_port_; }
const int ipfix_port() const { return ipfix_port_; }
const bool test_mode() const { return test_mode_; }
const bool disable_flow_collection() const { return disable_flow_collection_; }

private:
template <typename ValueType>
Expand Down Expand Up @@ -119,6 +120,7 @@ class Options {
std::vector<std::string> cassandra_server_list_;
std::vector<std::string> kafka_broker_list_;
uint16_t partitions_;
bool disable_flow_collection_;

boost::program_options::options_description config_file_options_;
};
10 changes: 9 additions & 1 deletion src/analytics/test/options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ TEST_F(OptionsTest, NoArguments) {
EXPECT_EQ(options_.syslog_port(), -1);
EXPECT_EQ(options_.dup(), false);
EXPECT_EQ(options_.test_mode(), false);
EXPECT_EQ(options_.disable_flow_collection(), false);
uint16_t protobuf_port(0);
EXPECT_FALSE(options_.collector_protobuf_port(&protobuf_port));
}
Expand Down Expand Up @@ -122,6 +123,7 @@ TEST_F(OptionsTest, DefaultConfFile) {
EXPECT_EQ(options_.syslog_port(), -1);
EXPECT_EQ(options_.dup(), false);
EXPECT_EQ(options_.test_mode(), false);
EXPECT_EQ(options_.disable_flow_collection(), false);
uint16_t protobuf_port(0);
EXPECT_FALSE(options_.collector_protobuf_port(&protobuf_port));
}
Expand Down Expand Up @@ -165,19 +167,22 @@ TEST_F(OptionsTest, OverrideStringFromCommandLine) {
EXPECT_EQ(options_.syslog_port(), -1);
EXPECT_EQ(options_.dup(), false);
EXPECT_EQ(options_.test_mode(), false);
EXPECT_EQ(options_.disable_flow_collection(), false);
uint16_t protobuf_port(0);
EXPECT_FALSE(options_.collector_protobuf_port(&protobuf_port));
}

TEST_F(OptionsTest, OverrideBooleanFromCommandLine) {
int argc = 3;
int argc = 4;
char *argv[argc];
char argv_0[] = "options_test";
char argv_1[] = "--conf_file=controller/src/analytics/contrail-collector.conf";
char argv_2[] = "--DEFAULT.test_mode";
char argv_3[] = "--DEFAULT.disable_flow_collection";
argv[0] = argv_0;
argv[1] = argv_1;
argv[2] = argv_2;
argv[3] = argv_3;

options_.Parse(evm_, argc, argv);

Expand Down Expand Up @@ -208,6 +213,7 @@ TEST_F(OptionsTest, OverrideBooleanFromCommandLine) {
EXPECT_EQ(options_.syslog_port(), -1);
EXPECT_EQ(options_.dup(), false);
EXPECT_EQ(options_.test_mode(), true); // Overridden from command line.
EXPECT_EQ(options_.disable_flow_collection(), true); // Overridden from command line.
uint16_t protobuf_port(0);
EXPECT_FALSE(options_.collector_protobuf_port(&protobuf_port));
}
Expand All @@ -231,6 +237,7 @@ TEST_F(OptionsTest, CustomConfigFile) {
"log_local=1\n"
"test_mode=1\n"
"syslog_port=101\n"
"disable_flow_collection=1\n"
"\n"
"[COLLECTOR]\n"
"port=100\n"
Expand Down Expand Up @@ -292,6 +299,7 @@ TEST_F(OptionsTest, CustomConfigFile) {
EXPECT_EQ(options_.syslog_port(), 101);
EXPECT_EQ(options_.dup(), true);
EXPECT_EQ(options_.test_mode(), true);
EXPECT_EQ(options_.disable_flow_collection(), true);
uint16_t protobuf_port(0);
EXPECT_TRUE(options_.collector_protobuf_port(&protobuf_port));
EXPECT_EQ(protobuf_port, 3333);
Expand Down

0 comments on commit b709340

Please sign in to comment.