Skip to content

Commit

Permalink
Options to control database writes from contrail-collector
Browse files Browse the repository at this point in the history
COMMIT 1:
Add database/cassandra options to contrail-collector

1. Add disable_all_writes, disable_statistics_writes,
   disable_messages_writes options under DATABASE section
   to control writes to database from collector.
2. Add introspect commands to disable/enable these options.
3. Add compaction_strategy option under CASSANDRA section
   to control the compaction strategy to be used for
   analytics tables created by the collector.

Closes-Bug: #1638088

COMMIT 2:
Fix build error with queue_task_test

Closes-Bug: 1596630
(cherry picked from commit d285623)

(cherry picked from commit c5da4cf)

COMMIT 3:
Fix cql_if_test

Add missing compaction_strategy arguments to Static/DynamicCfCreate
called from cql_if_test

Closes-Bug: #1641260
(cherry picked from commit 8d5498f)

COMMIT 4:
Disable message keyword writes

Add a DATABASE.enable_db_message_keyword_writes flag to control
message keyword table writes, which are now disabled by default

Closes-Bug: #1641261
(cherry picked from commit fc8a43f)

Conflicts:
	src/analytics/db_handler.cc
	src/analytics/db_handler.h
	src/analytics/generator.cc
	src/analytics/main.cc
	src/analytics/options.cc
	src/analytics/options.h
	src/analytics/protobuf_collector.cc
	src/analytics/test/db_handler_mock.h
	src/analytics/viz_collector.cc
	src/analytics/viz_collector.h

Conflicts:
	src/database/cassandra/cql/cql_if.cc

Conflicts:
	src/analytics/db_handler.cc
	src/analytics/db_handler.h
	src/analytics/viz_collector.cc

Change-Id: Ic9afa3935e0e87f5317fb4a015069cd669c0621f
(cherry picked from commit e1e4610)
  • Loading branch information
Megh Bhatt committed Nov 18, 2016
1 parent 3efbde0 commit 59e23f4
Show file tree
Hide file tree
Showing 20 changed files with 367 additions and 101 deletions.
62 changes: 55 additions & 7 deletions src/analytics/collector.cc
Expand Up @@ -519,10 +519,8 @@ void Collector::GetSmQueueWaterMarkInfo(
GetQueueWaterMarkInfo(QueueType::Sm, wm_info);
}


static void SendQueueParamsError(std::string estr, const std::string &context) {
// SandeshGenerator is required, send error
QueueParamsError *eresp(new QueueParamsError);
static void SendCollectorError(std::string estr, const std::string &context) {
CollectorError *eresp(new CollectorError);
eresp->set_context(context);
eresp->set_error(estr);
eresp->Response();
Expand All @@ -533,7 +531,7 @@ static Collector* ExtractCollectorFromRequest(SandeshContext *vscontext,
VizSandeshContext *vsc =
dynamic_cast<VizSandeshContext *>(vscontext);
if (!vsc) {
SendQueueParamsError("Sandesh client context NOT PRESENT",
SendCollectorError("Sandesh client context NOT PRESENT",
context);
return NULL;
}
Expand Down Expand Up @@ -562,7 +560,7 @@ static void SendQueueParamsResponse(Collector::QueueType::type type,

void DbQueueParamsSet::HandleRequest() const {
if (!(__isset.high && __isset.drop_level && __isset.queue_count)) {
SendQueueParamsError("Please specify all parameters", context());
SendCollectorError("Please specify all parameters", context());
return;
}
Collector *collector = ExtractCollectorFromRequest(client_context(),
Expand All @@ -578,7 +576,7 @@ void DbQueueParamsSet::HandleRequest() const {

void SmQueueParamsSet::HandleRequest() const {
if (!(__isset.high && __isset.drop_level && __isset.queue_count)) {
SendQueueParamsError("Please specify all parameters", context());
SendCollectorError("Please specify all parameters", context());
return;
}
Collector *collector = ExtractCollectorFromRequest(client_context(),
Expand Down Expand Up @@ -664,3 +662,53 @@ void FlowCollectionStatusRequest::HandleRequest() const {
// Send response
SendFlowCollectionStatusResponse(context());
}

static DbHandlerPtr ExtractDbHandlerFromRequest(SandeshContext *vscontext,
const std::string &context) {
VizSandeshContext *vsc =
dynamic_cast<VizSandeshContext *>(vscontext);
if (!vsc) {
SendCollectorError("Sandesh client context NOT PRESENT",
context);
return DbHandlerPtr();
}
return vsc->Analytics()->GetDbHandler();
}

static void SendDatabaseWritesStatusResponse(SandeshContext *vscontext, std::string context) {
DbHandlerPtr dbh(ExtractDbHandlerFromRequest(vscontext, context));
DatabaseWritesStatusResponse *dwsr(new DatabaseWritesStatusResponse);
dwsr->set_disable_all(dbh->IsAllWritesDisabled());
dwsr->set_disable_statistics(dbh->IsStatisticsWritesDisabled());
dwsr->set_disable_messages(dbh->IsMessagesWritesDisabled());
dwsr->set_disable_messages_keyword(dbh->IsMessagesKeywordWritesDisabled());
dwsr->set_disable_flows(Sandesh::IsFlowCollectionDisabled());
dwsr->set_context(context);
dwsr->Response();
}

void DisableDatabaseWritesRequest::HandleRequest() const {
DbHandlerPtr dbh(ExtractDbHandlerFromRequest(client_context(), context()));
if (__isset.disable_all) {
dbh->DisableAllWrites(get_disable_all());
}
if (__isset.disable_statistics) {
dbh->DisableStatisticsWrites(get_disable_statistics());
}
if (__isset.disable_messages) {
dbh->DisableMessagesWrites(get_disable_messages());
}
if (__isset.disable_messages_keyword) {
dbh->DisableMessagesKeywordWrites(get_disable_messages_keyword());
}
if (__isset.disable_flows) {
Sandesh::DisableFlowCollection(get_disable_flows());
}
// Send response
SendDatabaseWritesStatusResponse(client_context(), context());
}

void DatabaseWritesStatusRequest::HandleRequest() const {
// Send response
SendDatabaseWritesStatusResponse(client_context(), context());
}
27 changes: 23 additions & 4 deletions src/analytics/collector_uve.sandesh
Expand Up @@ -319,10 +319,6 @@ struct QueueParams {
3: string drop_level;
}

response sandesh QueueParamsError {
1: string error;
}

/**
* @description: sandesh response to return State Machine Queue params
*/
Expand Down Expand Up @@ -362,3 +358,26 @@ request sandesh FlowCollectionStatusRequest {
response sandesh FlowCollectionStatusResponse {
1: bool disable
}

response sandesh CollectorError {
1: string error
}

request sandesh DisableDatabaseWritesRequest {
1: optional bool disable_all
2: optional bool disable_statistics
3: optional bool disable_messages
4: optional bool disable_flows
5: optional bool disable_messages_keyword
}

request sandesh DatabaseWritesStatusRequest {
}

response sandesh DatabaseWritesStatusResponse {
1: bool disable_all
2: bool disable_statistics
3: bool disable_messages
4: bool disable_flows
5: bool disable_messages_keyword
}

0 comments on commit 59e23f4

Please sign in to comment.