From d57b01dc160087a81bec795187c4544942a20a8e Mon Sep 17 00:00:00 2001 From: Raj Reddy Date: Tue, 22 Mar 2016 14:59:06 -0700 Subject: [PATCH] config messages were supposed to be written with configaudit_ttl, but they were still written w/ global_ttl [which messages data ttl]. Change-Id: Ib0e6db8e1f8e19afc7fe7a68f3f8c7fb56a89a71 Closes-Bug: #1558875 (cherry picked from commit efad385f9046f8ba95e8696da9d6d79488a14d97) (cherry picked from commit f2e08974f7bb9e55d143ebb476dd5ca6dd01cbd9) --- src/analytics/db_handler.cc | 7 +- src/analytics/test/db_handler_test.cc | 102 ++++++++++++++++++++------ src/gendb/gendb_if.h | 3 +- 3 files changed, 89 insertions(+), 23 deletions(-) diff --git a/src/analytics/db_handler.cc b/src/analytics/db_handler.cc index 97c7a55db8c..2bf2511f883 100644 --- a/src/analytics/db_handler.cc +++ b/src/analytics/db_handler.cc @@ -432,7 +432,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 col_list(new GenDb::ColList); col_list->cfname_ = g_viz_constants.COLLECTOR_GLOBAL_TABLE; // Rowkey diff --git a/src/analytics/test/db_handler_test.cc b/src/analytics/test/db_handler_test.cc index 6c8d976ef46..31737f201d8 100644 --- a/src/analytics/test/db_handler_test.cc +++ b/src/analytics/test/db_handler_test.cc @@ -140,7 +140,7 @@ TEST_F(DbHandlerTest, MessageTableOnlyInsertTest) { GenDb::DbDataValueVec rowkey; rowkey.push_back(unm); - int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second; + int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600; boost::ptr_vector msg_table_expected_vector = boost::assign::ptr_list_of (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl)) @@ -176,6 +176,64 @@ TEST_F(DbHandlerTest, MessageTableOnlyInsertTest) { 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 = "src/analytics/test/viz_collector_test.cc80sat2string101101101"; + + SandeshXMLMessageTest *msg = dynamic_cast( + builder_->Create( + reinterpret_cast(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 msg_table_expected_vector = + boost::assign::ptr_list_of + (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(hdr.get_Timestamp()), ttl)) + (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl)) + (GenDb::NewCol(g_viz_constants.LEVEL, + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl)) + (GenDb::NewCol(g_viz_constants.SEQUENCE_NUM, + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.VERSION, + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.SANDESH_TYPE, + static_cast(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, MessageIndexTableInsertTest) { SandeshHeader hdr; @@ -183,7 +241,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; DbDataValueVec *colname(new DbDataValueVec(1, (uint32_t)(hdr.get_Timestamp() & g_viz_constants.RowTimeInMask))); DbDataValueVec *colvalue(new DbDataValueVec(1, unm)); @@ -231,26 +289,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 msg_table_expected_vector = boost::assign::ptr_list_of - (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(hdr.get_Timestamp()), 0)) - (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), 0)) + static_cast(hdr.get_Timestamp()), ttl)) + (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl)) (GenDb::NewCol(g_viz_constants.LEVEL, - static_cast(0), 0)) - (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, 0)) + static_cast(0), ttl)) + (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl)) (GenDb::NewCol(g_viz_constants.SEQUENCE_NUM, - static_cast(0), 0)) + static_cast(0), ttl)) (GenDb::NewCol(g_viz_constants.VERSION, - static_cast(0), 0)) + static_cast(0), ttl)) (GenDb::NewCol(g_viz_constants.SANDESH_TYPE, - static_cast(SandeshType::SYSTEM), 0)) - (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, 0)); + static_cast(SandeshType::SYSTEM), ttl)) + (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl)); EXPECT_CALL(*dbif_mock(), Db_AddColumnProxy( @@ -267,7 +326,7 @@ TEST_F(DbHandlerTest, MessageTableInsertTest) { DbDataValueVec *colvalue(new DbDataValueVec(1, unm)); boost::ptr_vector idx_expected_vector = boost::assign::ptr_list_of - (GenDb::NewCol(colname, colvalue, 0)); + (GenDb::NewCol(colname, colvalue, ttl)); GenDb::DbDataValueVec src_idx_rowkey; src_idx_rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits)); @@ -373,6 +432,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); @@ -382,7 +442,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) { DbDataValueVec *colvalue(new DbDataValueVec(1, unm)); boost::ptr_vector expected_vector = boost::assign::ptr_list_of - (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)); @@ -406,7 +466,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) { "ObjectTableInsertTestRowkey")); boost::ptr_vector expected_vector = boost::assign::ptr_list_of - (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)); @@ -433,7 +493,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) { DbDataValueVec *colvalue(new DbDataValueVec(1,"")); boost::ptr_vector expected_vector = boost::assign::ptr_list_of - (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)); @@ -461,7 +521,7 @@ TEST_F(DbHandlerTest, ObjectTableInsertTest) { DbDataValueVec *colvalue(new DbDataValueVec(1,"")); boost::ptr_vector expected_vector = boost::assign::ptr_list_of - (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)); @@ -529,7 +589,7 @@ TEST_F(DbHandlerTest, FlowTableInsertTest) { ocolvalue.push_back((uint16_t)-24590); //dport ocolvalue.push_back(""); //json - int ttl = ttl_map.find(TtlType::FLOWDATA_TTL)->second; + int ttl = ttl_map.find(TtlType::FLOWDATA_TTL)->second*3600; { GenDb::DbDataValueVec *colname(new GenDb::DbDataValueVec); diff --git a/src/gendb/gendb_if.h b/src/gendb/gendb_if.h index 0af9d347680..5b239661111 100644 --- a/src/gendb/gendb_if.h +++ b/src/gendb/gendb_if.h @@ -110,7 +110,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;