update flag for logging events to store (#1846)

* remove analytics logging to tsv file

* add event_type in db_key & add tests for db persistence

* add test for sparsely added event retrieval

* update flag name to log events to store
This commit is contained in:
Krunal Gandhi 2024-07-22 01:51:59 +00:00 committed by GitHub
parent 99a774d359
commit 3494155b7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 14 deletions

View File

@ -11,7 +11,7 @@
struct event_type_collection {
std::string event_type;
std::string collection;
bool log_to_file = false;
bool log_to_store = false;
std::string analytic_rule;
};
@ -23,21 +23,21 @@ struct event_t {
std::string doc_id;
std::string name;
std::vector<std::pair<std::string, std::string>> data;
bool log_to_file;
bool log_to_store;
event_t() = delete;
~event_t() = default;
event_t(const std::string& q, const std::string& type, uint64_t ts, const std::string& uid, const std::string& id,
const std::string& event_name, bool should_log_to_file, const std::vector<std::pair<std::string, std::string>> datavec) {
const std::string& event_name, bool should_log_to_store, const std::vector<std::pair<std::string, std::string>> datavec) {
query = q;
event_type = type;
timestamp = ts;
user_id = uid;
doc_id = id;
name = event_name;
log_to_file = should_log_to_file;
log_to_store = should_log_to_store;
data = datavec;
}

View File

@ -219,17 +219,17 @@ Option<bool> AnalyticsManager::create_index(nlohmann::json &payload, bool upsert
//store event name to their weights
//which can be used to keep counter events separate from non counter events
bool log_to_file = false;
if(event.contains("log_to_file")) {
log_to_file = event["log_to_file"].get<bool>();
bool log_to_store = false;
if(event.contains("log_to_store")) {
log_to_store = event["log_to_store"].get<bool>();
if(log_to_file && !analytics_store) {
if(log_to_store && !analytics_store) {
remove_index(suggestion_config_name);
return Option<bool>(400, "Event can't be logged when analytics-db is not defined.");
}
}
event_weight_map[event["name"]] = event["weight"];
event_type_collection ec{event["type"], suggestion_collection, log_to_file, suggestion_config_name};
event_type_collection ec{event["type"], suggestion_collection, log_to_store, suggestion_config_name};
event_collection_map.emplace(event["name"], ec);
}
counter_events.emplace(suggestion_collection, counter_event_t{counter_field, {}, event_weight_map});
@ -470,7 +470,7 @@ Option<bool> AnalyticsManager::add_event(const std::string& client_ip, const std
}
event_t event(query, event_type, now_ts_useconds, user_id, doc_id,
event_name, event_collection_map[event_name].log_to_file, custom_data);
event_name, event_collection_map[event_name].log_to_store, custom_data);
events_vec.emplace_back(event);
if (!counter_events.empty()) {
@ -658,7 +658,7 @@ void AnalyticsManager::persist_events(ReplicationState *raft_server, uint64_t pr
for (auto &events_collection_it: query_collection_events) {
const auto& collection = events_collection_it.first;
for (const auto &event: events_collection_it.second) {
if (event.log_to_file) {
if (event.log_to_store) {
nlohmann::json event_data;
event.to_json(event_data, collection);
payload.push_back(event_data);

View File

@ -910,7 +910,7 @@ TEST_F(AnalyticsManagerTest, PopularityScore) {
"source": {
"collections": ["products"],
"events": [{"type": "click", "weight": 1, "name": "CLK1"}, {"type": "conversion", "weight": 5, "name": "CNV1"} ],
"log_to_file": true
"log_to_store": true
},
"destination": {
"collection": "products",
@ -1209,7 +1209,7 @@ TEST_F(AnalyticsManagerTest, PopularityScoreValidation) {
"params": {
"source": {
"collections": ["books"],
"events": [{"type": "click", "name" : "CLK4"}, {"type": "conversion", "name": "CNV4", "log_to_file" : true} ]
"events": [{"type": "click", "name" : "CLK4"}, {"type": "conversion", "name": "CNV4", "log_to_store" : true} ]
},
"destination": {
"collection": "books",
@ -1228,7 +1228,7 @@ TEST_F(AnalyticsManagerTest, PopularityScoreValidation) {
"params": {
"source": {
"collections": ["books"],
"events": [{"type": "click", "weight": 1, "name" : "CLK4"}, {"type": "conversion", "weight": 5, "name": "CNV4", "log_to_file" : true} ]
"events": [{"type": "click", "weight": 1, "name" : "CLK4"}, {"type": "conversion", "weight": 5, "name": "CNV4", "log_to_store" : true} ]
},
"destination": {
"collection": "books",