Skip to content

Commit

Permalink
config messages were supposed to be written with configaudit_ttl, but
Browse files Browse the repository at this point in the history
they were still written w/ global_ttl [which messages data ttl].

Change-Id: Ifc9b847061b5ed785b43e24ca669d9e3eaffea0f
Closes-Bug: #1558875
  • Loading branch information
Raj Reddy committed Mar 22, 2016
1 parent 133100e commit 3357a5b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
7 changes: 6 additions & 1 deletion src/analytics/db_handler.cc
Expand Up @@ -561,7 +561,12 @@ void DbHandler::MessageTableOnlyInsert(const VizMsg *vmsgp) {
uint32_t temp_u32;
std::string temp_str;

int ttl = GetTtl(TtlType::GLOBAL_TTL);
int ttl;
if (message_type == "VncApiConfigLog") {
ttl = GetTtl(TtlType::CONFIGAUDIT_TTL);
} else {
ttl = GetTtl(TtlType::GLOBAL_TTL);
}
std::auto_ptr<GenDb::ColList> col_list(new GenDb::ColList);
col_list->cfname_ = g_viz_constants.COLLECTOR_GLOBAL_TABLE;
// Rowkey
Expand Down
101 changes: 80 additions & 21 deletions src/analytics/test/db_handler_test.cc
Expand Up @@ -155,13 +155,71 @@ TEST_F(DbHandlerTest, MessageTableOnlyInsertTest) {
xmlmessage.size()));
msg->SetHeader(hdr);
boost::uuids::uuid unm(rgen_());
VizMsg vmsgp(msg, unm);
VizMsg vmsgp(msg, unm);

GenDb::DbDataValueVec rowkey;
rowkey.push_back(unm);

int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second;
boost::ptr_vector<GenDb::NewCol> msg_table_expected_vector =
int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;
boost::ptr_vector<GenDb::NewCol> msg_table_expected_vector =
boost::assign::ptr_list_of<GenDb::NewCol>
(GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl))
(GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl))
(GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), ttl))
(GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), ttl))
(GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), ttl))
(GenDb::NewCol(g_viz_constants.TIMESTAMP,
static_cast<uint64_t>(hdr.get_Timestamp()), ttl))
(GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl))
(GenDb::NewCol(g_viz_constants.LEVEL,
static_cast<uint32_t>(0), ttl))
(GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl))
(GenDb::NewCol(g_viz_constants.SEQUENCE_NUM,
static_cast<uint32_t>(0), ttl))
(GenDb::NewCol(g_viz_constants.VERSION,
static_cast<uint32_t>(0), ttl))
(GenDb::NewCol(g_viz_constants.SANDESH_TYPE,
static_cast<uint8_t>(0), ttl))
(GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl));

EXPECT_CALL(*dbif_mock(),
Db_AddColumnProxy(
Pointee(
AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.COLLECTOR_GLOBAL_TABLE),
Field(&GenDb::ColList::rowkey_, rowkey),
Field(&GenDb::ColList::columns_, msg_table_expected_vector)))))
.Times(1)
.WillOnce(Return(true));

db_handler()->MessageTableOnlyInsert(&vmsgp);
vmsgp.msg = NULL;
delete msg;
}

TEST_F(DbHandlerTest, MessageTableOnlyInsertConfigAuditTest) {
SandeshHeader hdr;

hdr.set_Source("127.0.0.1");
hdr.set_Module("VizdTest");
hdr.set_InstanceId("Test");
hdr.set_NodeType("Test");
hdr.set_Timestamp(UTCTimestampUsec());
std::string messagetype("VncApiConfigLog");
std::string xmlmessage = "<VncApiConfigLog type=\"sandesh\"><file type=\"string\" identifier=\"-32768\">src/analytics/test/viz_collector_test.cc</file><line type=\"i32\" identifier=\"-32767\">80</line><f1 type=\"struct\" identifier=\"1\"><SAT2_struct><f1 type=\"string\" identifier=\"1\">sat2string101</f1><f2 type=\"i32\" identifier=\"2\">101</f2></SAT2_struct></f1><f2 type=\"i32\" identifier=\"2\">101</f2></VncApiConfigLog>";

SandeshXMLMessageTest *msg = dynamic_cast<SandeshXMLMessageTest *>(
builder_->Create(
reinterpret_cast<const uint8_t *>(xmlmessage.c_str()),
xmlmessage.size()));
msg->SetHeader(hdr);
boost::uuids::uuid unm(rgen_());
VizMsg vmsgp(msg, unm);

GenDb::DbDataValueVec rowkey;
rowkey.push_back(unm);

int ttl = ttl_map.find(TtlType::CONFIGAUDIT_TTL)->second*3600;
boost::ptr_vector<GenDb::NewCol> msg_table_expected_vector =
boost::assign::ptr_list_of<GenDb::NewCol>
(GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl))
(GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl))
Expand Down Expand Up @@ -203,7 +261,7 @@ TEST_F(DbHandlerTest, MessageIndexTableInsertTest) {
hdr.set_Timestamp(UTCTimestampUsec());
boost::uuids::uuid unm(rgen_());

int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second;
int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;

#ifdef USE_CASSANDRA_CQL
DbDataValueVec *colname(new DbDataValueVec());
Expand Down Expand Up @@ -420,26 +478,27 @@ TEST_F(DbHandlerTest, MessageTableInsertTest) {
GenDb::DbDataValueVec rowkey;
rowkey.push_back(unm);

int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;
boost::ptr_vector<GenDb::NewCol> msg_table_expected_vector =
boost::assign::ptr_list_of<GenDb::NewCol>
(GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), 0))
(GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), 0))
(GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), 0))
(GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), 0))
(GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), 0))
(GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl))
(GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl))
(GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), ttl))
(GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), ttl))
(GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), ttl))
(GenDb::NewCol(g_viz_constants.TIMESTAMP,
static_cast<uint64_t>(hdr.get_Timestamp()), 0))
(GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), 0))
static_cast<uint64_t>(hdr.get_Timestamp()), ttl))
(GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl))
(GenDb::NewCol(g_viz_constants.LEVEL,
static_cast<uint32_t>(0), 0))
(GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, 0))
static_cast<uint32_t>(0), ttl))
(GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl))
(GenDb::NewCol(g_viz_constants.SEQUENCE_NUM,
static_cast<uint32_t>(0), 0))
static_cast<uint32_t>(0), ttl))
(GenDb::NewCol(g_viz_constants.VERSION,
static_cast<uint32_t>(0), 0))
static_cast<uint32_t>(0), ttl))
(GenDb::NewCol(g_viz_constants.SANDESH_TYPE,
static_cast<uint8_t>(SandeshType::SYSTEM), 0))
(GenDb::NewCol(g_viz_constants.DATA, xmlmessage, 0));
static_cast<uint8_t>(SandeshType::SYSTEM), ttl))
(GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl));

EXPECT_CALL(*dbif_mock(),
Db_AddColumnProxy(
Expand All @@ -452,7 +511,6 @@ TEST_F(DbHandlerTest, MessageTableInsertTest) {
.Times(1)
.WillOnce(Return(true));

int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second;
DbDataValueVec *colname(new DbDataValueVec());
colname->reserve(3);
colname->push_back(hdr.get_Source());
Expand Down Expand Up @@ -606,6 +664,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) {
msg->SetHeader(hdr);
VizMsg vmsgp(msg, unm);

int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;
{
DbDataValueVec *colname(new DbDataValueVec());
colname->reserve(2);
Expand All @@ -615,7 +674,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) {
DbDataValueVec *colvalue(new DbDataValueVec(1, unm));
boost::ptr_vector<GenDb::NewCol> expected_vector =
boost::assign::ptr_list_of<GenDb::NewCol>
(GenDb::NewCol(colname, colvalue, 0));
(GenDb::NewCol(colname, colvalue, ttl));

GenDb::DbDataValueVec rowkey;
rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));
Expand All @@ -639,7 +698,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) {
"ObjectTableInsertTestRowkey"));
boost::ptr_vector<GenDb::NewCol> expected_vector =
boost::assign::ptr_list_of<GenDb::NewCol>
(GenDb::NewCol(colname, colvalue, 0));
(GenDb::NewCol(colname, colvalue, ttl));

GenDb::DbDataValueVec rowkey;
rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));
Expand Down Expand Up @@ -878,7 +937,7 @@ TEST_F(DbHandlerTest, FlowTableInsertTest) {
.WillOnce(Return(true));
}

int ttl = ttl_map.find(TtlType::FLOWDATA_TTL)->second;
int ttl = ttl_map.find(TtlType::FLOWDATA_TTL)->second*3600;
GenDb::DbDataValueVec ocolvalue;
#ifdef USE_CASSANDRA_CQL
std::ostringstream cv_ss;
Expand Down
3 changes: 2 additions & 1 deletion src/database/gendb_if.h
Expand Up @@ -134,7 +134,8 @@ struct NewCol {

bool operator==(const NewCol &rhs) const {
return (*rhs.name == *name &&
*rhs.value == *value);
*rhs.value == *value &&
rhs.ttl == ttl);
}

size_t GetSize() const;
Expand Down

0 comments on commit 3357a5b

Please sign in to comment.