|
| 1 | +#include<chimbuko/modules/performance_analysis/provdb/ProvDBprune.hpp> |
| 2 | +#include<chimbuko/modules/performance_analysis/provdb/ProvDBmoduleSetup.hpp> |
| 3 | +#include<chimbuko/core/pserver/PSshardProvenanceDBclient.hpp> |
| 4 | +#include<chimbuko/core/pserver/PSglobalProvenanceDBclient.hpp> |
| 5 | + |
| 6 | +#include "gtest/gtest.h" |
| 7 | +#include "../../../unit_test_common.hpp" |
| 8 | +#include "ProvDBtester.hpp" |
| 9 | + |
| 10 | +using namespace chimbuko; |
| 11 | +using namespace chimbuko::modules::performance_analysis; |
| 12 | + |
| 13 | +TEST(TestProvDBprune, works){ |
| 14 | + int nshards = 2; |
| 15 | + ProvDBmoduleSetup setup; |
| 16 | + ProvDBtester pdb(nshards, setup); |
| 17 | + |
| 18 | + { |
| 19 | + std::ofstream of("/tmp/provider.address.0"); |
| 20 | + of << pdb.getAddr(); |
| 21 | + } |
| 22 | + std::vector<std::unique_ptr<PSshardProvenanceDBclient> > shard_clients(nshards); |
| 23 | + for(int i=0;i<nshards;i++){ |
| 24 | + shard_clients[i].reset(new PSshardProvenanceDBclient(setup.getMainDBcollections())); |
| 25 | + shard_clients[i]->connectShard("/tmp",i,nshards,1); |
| 26 | + } |
| 27 | + |
| 28 | + PSglobalProvenanceDBclient glob_client(setup.getGlobalDBcollections()); |
| 29 | + glob_client.connectServer(pdb.getAddr()); |
| 30 | + |
| 31 | + //Put some anomaly data on the shards. Use both shards to check aggregation |
| 32 | + nlohmann::json anom, norm; |
| 33 | + |
| 34 | + //event that should be removed |
| 35 | + norm["runtime_exclusive"] = 100; |
| 36 | + norm["fid"] = 1234; |
| 37 | + norm["blah"] = "norm"; |
| 38 | + |
| 39 | + shard_clients[0]->sendData(norm, "anomalies"); |
| 40 | + |
| 41 | + //event that should be kept |
| 42 | + anom["runtime_exclusive"] = 1000; |
| 43 | + anom["fid"] = 1234; |
| 44 | + anom["blah"] = "real_anom1"; |
| 45 | + anom["entry"] = 33; //need this info to gather anomaly metrics on kept anomalies |
| 46 | + anom["exit"] = 1033; |
| 47 | + anom["io_step"] = 13; |
| 48 | + anom["outlier_severity"] = 1000; |
| 49 | + anom["rid"] = 88; |
| 50 | + |
| 51 | + shard_clients[0]->sendData(anom, "anomalies"); |
| 52 | + |
| 53 | + //event that should be removed |
| 54 | + norm["runtime_exclusive"] = 103; |
| 55 | + norm["fid"] = 1234; |
| 56 | + norm["blah"] = "norm2"; |
| 57 | + |
| 58 | + shard_clients[1]->sendData(norm, "anomalies"); |
| 59 | + |
| 60 | + //event that should be kept |
| 61 | + anom["runtime_exclusive"] = 1200; |
| 62 | + anom["fid"] = 1234; |
| 63 | + anom["blah"] = "real_anom2"; |
| 64 | + anom["entry"] = 44; |
| 65 | + anom["exit"] = 1244; |
| 66 | + anom["io_step"] = 17; |
| 67 | + anom["outlier_severity"] = 1200; |
| 68 | + anom["rid"] = 88; |
| 69 | + |
| 70 | + shard_clients[1]->sendData(anom, "anomalies"); |
| 71 | + |
| 72 | + //populate the global database |
| 73 | + nlohmann::json fstats; |
| 74 | + fstats["fid"] = 1234; |
| 75 | + glob_client.sendData(fstats, "func_stats"); |
| 76 | + |
| 77 | + double mean = 100; |
| 78 | + double stddev = 10; |
| 79 | + int count = 1000; |
| 80 | + |
| 81 | + SstdParam param; |
| 82 | + param[1234].set_eta(mean); |
| 83 | + param[1234].set_rho(pow(stddev,2) * (count-1) ); |
| 84 | + param[1234].set_count(count); |
| 85 | + ADOutlier::AlgoParams ap; ap.sstd_sigma = 5; |
| 86 | + |
| 87 | + //Do the business |
| 88 | + ProvDBprune pruner("sstd", ap, param.serialize()); |
| 89 | + for(int i=0;i<nshards;i++) pruner.prune(shard_clients[i]->getDatabase()); |
| 90 | + pruner.finalize(glob_client.getDatabase()); |
| 91 | + |
| 92 | + //check the shards |
| 93 | + { |
| 94 | + auto sdata = shard_clients[0]->retrieveAllData("anomalies"); |
| 95 | + EXPECT_EQ(sdata.size(),1); |
| 96 | + auto s = nlohmann::json::parse(sdata[0]); |
| 97 | + EXPECT_NEAR(s["outlier_score"].template get<double>(), 90, 1e-5); |
| 98 | + } |
| 99 | + { |
| 100 | + auto sdata = shard_clients[1]->retrieveAllData("anomalies"); |
| 101 | + EXPECT_EQ(sdata.size(),1); |
| 102 | + auto s = nlohmann::json::parse(sdata[0]); |
| 103 | + EXPECT_NEAR(s["outlier_score"].template get<double>(), 110, 1e-5); |
| 104 | + } |
| 105 | + |
| 106 | + //check the global database |
| 107 | + auto glob_data = glob_client.retrieveAllData("func_stats"); |
| 108 | + EXPECT_EQ(glob_data.size(), 1); |
| 109 | + for(auto const &e : glob_data){ |
| 110 | + nlohmann::json je = nlohmann::json::parse(e); |
| 111 | + std::cout << je.dump(4); |
| 112 | + |
| 113 | + EXPECT_EQ(je["anomaly_metrics"]["first_io_step"].template get<int>(), 13); |
| 114 | + EXPECT_EQ(je["anomaly_metrics"]["last_io_step"].template get<int>(), 17); |
| 115 | + EXPECT_EQ(je["anomaly_metrics"]["min_timestamp"].template get<unsigned long>(), 33); |
| 116 | + EXPECT_EQ(je["anomaly_metrics"]["max_timestamp"].template get<unsigned long>(), 1244); |
| 117 | + EXPECT_EQ(je["anomaly_metrics"]["score"]["count"].template get<int>(), 2); |
| 118 | + EXPECT_EQ(je["anomaly_metrics"]["severity"]["count"].template get<int>(), 2); |
| 119 | + EXPECT_EQ(je["anomaly_metrics"]["severity"]["accumulate"].template get<unsigned long>(), 2200); |
| 120 | + EXPECT_EQ(je["anomaly_metrics"]["anomaly_count"]["count"].template get<int>(), 2); //2 different timesteps |
| 121 | + EXPECT_EQ(je["anomaly_metrics"]["anomaly_count"]["accumulate"].template get<unsigned long>(), 2); |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | + |
0 commit comments