From adb77dafac7d86bc5869db6ddb0e5c0ec9ce0f7b Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Fri, 18 Apr 2025 05:41:23 +0000 Subject: [PATCH] Changing archive_theos args in AnalyticsService --- src/lib/api/services/AnalyticsService.proto | 4 +-- .../analytics/AnalyticsServiceServer.cpp | 27 ++++++++++++------- .../sparkd/analytics/AnalyticsServiceServer.h | 5 ++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/lib/api/services/AnalyticsService.proto b/src/lib/api/services/AnalyticsService.proto index 1a4664d38..71d0095e4 100644 --- a/src/lib/api/services/AnalyticsService.proto +++ b/src/lib/api/services/AnalyticsService.proto @@ -49,7 +49,7 @@ message ArchivedSecurityTheo { } message ArchivedTheoList { - uint64 save_time = 10; + uint64 save_time = 10[ (bts.api.key) = true ]; // these are sec_tups that are part of this save repeated bts.api.SecurityTuple sec_tups = 20; repeated ArchivedSecurityTheo sec_theo = 30; @@ -198,7 +198,7 @@ service AnalyticsService { rpc clean_and_archive_theos(ArchivedTheoList) returns (bts.api.ResultMessage); // finds the archived_theo closest to this point rpc get_archived_theos(ArchivedTheoRetrieval) returns (ArchivedTheoList); - rpc archived_theos(bts.api.VoidMessage) returns (stream ArchivedSecurityTheo); + rpc archived_theos(bts.api.VoidMessage) returns (stream ArchivedTheoList); /// reports rpc get_new_report_id(bts.api.VoidMessage) diff --git a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp index 13615db12..33f44598c 100644 --- a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp +++ b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp @@ -133,6 +133,13 @@ struct AnalyticsServiceServer::PImpl { archived_theos_publisher(archived_theos_publisher_) {} }; +void AnalyticsServiceServer::_publish_archived_theos( + const api::analytics::ArchivedTheoList &l) { + // remove all rows + me->archived_theos_publisher.add_or_update(l); + me->archived_theos_publisher.flush(); +} + AnalyticsServiceServer::AnalyticsServiceServer( bts::api::ServiceContext &context) : AnalyticsServiceBase(context), @@ -215,23 +222,24 @@ AnalyticsServiceServer::AnalyticsServiceServer( // archived theos { size_t n = 0; + // ns_table is ns vs {key, val}[] auto ns_table = me->theos_store->retrieve_all(); + LOG(OrderMan, Info, + "AnalyticsServiceServer::cons loaded archived_theos n: {}", + ns_table.size()); bts_assert(ns_table.size() == 0 || ns_table.size() == 1); for (const auto &ns_vals : ns_table) { for (const auto &kvp : ns_vals.second) { ArchivedTheoList theo_list; utils::pb::from_string(kvp.second, &theo_list); - for (const auto &t : theo_list.sec_theo()) { - n++; - me->archived_theos_publisher.add_or_update(t); - } + _publish_archived_theos(theo_list); + n += theo_list.sec_theo().size(); } } LOG(Gen, Info, "AnalyticsServiceServer::AnalyticsServiceServer publishing theos n: " "{}", n); - me->archived_theos_publisher.flush(); } } @@ -492,14 +500,15 @@ void AnalyticsServiceServer::clean_and_archive_theos( fire_cb(resp, false, &err_msg); return; } - for (const auto &t : theo_list.sec_theo()) { - me->archived_theos_publisher.add_or_update(t); - } + // for (const auto &t : theo_list.sec_theo()) { + // me->archived_theos_publisher.add_or_update(t); + // } me->theos_store->remove_all(me->archived_theos_ns); const std::string &ns = me->archived_theos_ns; - const std::string key = std::to_string(theo_list.save_time()); + const std::string key = "dont care"; //std::to_string(theo_list.save_time()); std::string value = utils::pb::to_string(theo_list); me->theos_store->insert(ns, key, value); + _publish_archived_theos(theo_list); fire_cb(resp, true); } diff --git a/src/server/sparkd/analytics/AnalyticsServiceServer.h b/src/server/sparkd/analytics/AnalyticsServiceServer.h index 02b645859..e21988a21 100644 --- a/src/server/sparkd/analytics/AnalyticsServiceServer.h +++ b/src/server/sparkd/analytics/AnalyticsServiceServer.h @@ -1,5 +1,6 @@ #pragma once +#include "lib/api/services/AnalyticsService.pb.h" #include "lib/api/services/AnalyticsService.server.pb.h" namespace bts { @@ -17,6 +18,10 @@ class AnalyticsServiceServer struct PImpl; std::unique_ptr me; + private: + void _publish_archived_theos( + const api::analytics::ArchivedTheoList &total_state); + public: AnalyticsServiceServer(bts::api::ServiceContext &context);