Parcourir la source

feat(stats): report loaded db client library version and commit

fszontagh il y a 1 mois
Parent
commit
0a74c637a7
2 fichiers modifiés avec 15 ajouts et 0 suppressions
  1. 4 0
      src/handlers/stats.cpp
  2. 11 0
      tests/test_api_integration.cpp

+ 4 - 0
src/handlers/stats.cpp

@@ -43,6 +43,10 @@ void registerStatsRoutes(ApiServer& s) {
             {"cache_hit_ratio", total > 0 ? cs.hits / total : 0.0},
             {"cache_bytes",     cs.bytes}
         };
+        // What the dynamic linker actually bound, not what we compiled against:
+        // a stale .so under an unchanged soname is otherwise invisible.
+        out["db_client_version"] = smartbotic::database::clientLibraryVersion();
+        out["db_client_commit"]  = smartbotic::database::clientLibraryCommit();
         sendJson(res, 200, out);
     });
 }

+ 11 - 0
tests/test_api_integration.cpp

@@ -166,6 +166,17 @@ TEST_F(ApiFixture, ProjectStatsAndGlobalStats) {
     EXPECT_TRUE(gJson.contains("memory_pressure_level"));
 }
 
+TEST_F(ApiFixture, StatsReportsLoadedClientLibraryVersion) {
+    auto r = admin().Get("/api/v1/stats");
+    ASSERT_TRUE(r); ASSERT_EQ(r->status, 200);
+    auto body = nlohmann::json::parse(r->body);
+    ASSERT_TRUE(body.contains("db_client_version"));
+    ASSERT_TRUE(body.contains("db_client_commit"));
+    // Reports the LOADED library, so it must be non-empty and 2.x.
+    EXPECT_FALSE(body["db_client_version"].get<std::string>().empty());
+    EXPECT_EQ(body["db_client_version"].get<std::string>().rfind("2.", 0), 0u);
+}
+
 TEST_F(ApiFixture, OpenApiDescribesProjectRoutes) {
     auto r = noAuth().Get("/openapi.json");
     ASSERT_EQ(r->status, 200);