2023-10-16 20:16:00 +08:00
|
|
|
// Copyright 2023 Memgraph Ltd.
|
2021-10-26 14:53:56 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2018-06-20 19:46:54 +08:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
2023-10-16 20:16:00 +08:00
|
|
|
#include "dbms/dbms_handler.hpp"
|
|
|
|
#include "glue/auth_checker.hpp"
|
|
|
|
#include "glue/auth_handler.hpp"
|
2018-07-06 15:28:05 +08:00
|
|
|
#include "requests/requests.hpp"
|
2023-10-16 20:16:00 +08:00
|
|
|
#include "storage/v2/config.hpp"
|
2018-06-20 19:46:54 +08:00
|
|
|
#include "telemetry/telemetry.hpp"
|
2022-11-04 22:23:43 +08:00
|
|
|
#include "utils/system_info.hpp"
|
|
|
|
#include "utils/uuid.hpp"
|
2018-06-20 19:46:54 +08:00
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
DEFINE_string(endpoint, "http://127.0.0.1:9000/", "Endpoint that should be used for the test.");
|
2018-06-20 19:46:54 +08:00
|
|
|
DEFINE_int64(interval, 1, "Interval used for reporting telemetry in seconds.");
|
|
|
|
DEFINE_int64(duration, 10, "Duration of the test in seconds.");
|
2021-02-18 22:32:43 +08:00
|
|
|
DEFINE_string(storage_directory, "", "Path to the storage directory where to save telemetry data.");
|
2023-10-16 20:16:00 +08:00
|
|
|
DEFINE_string(root_directory, "", "Path to the database durability root dir.");
|
2018-06-20 19:46:54 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
gflags::SetVersionString("telemetry");
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
2023-10-16 20:16:00 +08:00
|
|
|
// Memgraph backend
|
|
|
|
std::filesystem::path data_directory{std::filesystem::temp_directory_path() / "MG_telemetry_integration_test"};
|
|
|
|
memgraph::utils::Synchronized<memgraph::auth::Auth, memgraph::utils::WritePrioritizedRWLock> auth_{data_directory /
|
|
|
|
"auth"};
|
|
|
|
memgraph::glue::AuthQueryHandler auth_handler(&auth_, "");
|
|
|
|
memgraph::glue::AuthChecker auth_checker(&auth_);
|
|
|
|
|
|
|
|
memgraph::storage::Config db_config;
|
|
|
|
memgraph::storage::UpdatePaths(db_config, data_directory);
|
2023-11-06 19:50:49 +08:00
|
|
|
memgraph::replication::ReplicationState repl_state(ReplicationStateRootPath(db_config));
|
2023-10-16 20:16:00 +08:00
|
|
|
|
2023-11-23 18:02:35 +08:00
|
|
|
memgraph::dbms::DbmsHandler dbms_handler(db_config
|
2023-10-16 20:16:00 +08:00
|
|
|
#ifdef MG_ENTERPRISE
|
2023-11-06 19:50:49 +08:00
|
|
|
,
|
|
|
|
&auth_, false, false
|
2023-10-16 20:16:00 +08:00
|
|
|
#endif
|
2023-11-06 19:50:49 +08:00
|
|
|
);
|
|
|
|
memgraph::query::InterpreterContext interpreter_context_({}, &dbms_handler, &repl_state, &auth_handler,
|
|
|
|
&auth_checker);
|
2023-10-16 20:16:00 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::requests::Init();
|
2022-11-04 22:23:43 +08:00
|
|
|
memgraph::telemetry::Telemetry telemetry(FLAGS_endpoint, FLAGS_storage_directory, memgraph::utils::GenerateUUID(),
|
2023-10-16 20:16:00 +08:00
|
|
|
memgraph::utils::GetMachineId(), false, FLAGS_root_directory,
|
|
|
|
std::chrono::seconds(FLAGS_interval), 1);
|
2018-06-20 19:46:54 +08:00
|
|
|
|
2023-10-16 20:16:00 +08:00
|
|
|
// User defined collector
|
2018-06-20 19:46:54 +08:00
|
|
|
uint64_t counter = 0;
|
2023-10-16 20:16:00 +08:00
|
|
|
telemetry.AddCollector("test", [&counter]() -> nlohmann::json {
|
2018-06-20 19:46:54 +08:00
|
|
|
++counter;
|
|
|
|
return {{"vertices", counter}, {"edges", counter}};
|
|
|
|
});
|
|
|
|
|
2023-10-16 20:16:00 +08:00
|
|
|
// Memgraph specific collectors
|
|
|
|
telemetry.AddStorageCollector(dbms_handler, auth_);
|
2023-11-06 19:50:49 +08:00
|
|
|
#ifdef MG_ENTERPRISE
|
2023-10-16 20:16:00 +08:00
|
|
|
telemetry.AddDatabaseCollector(dbms_handler);
|
|
|
|
#else
|
|
|
|
telemetry.AddDatabaseCollector();
|
|
|
|
#endif
|
|
|
|
telemetry.AddClientCollector();
|
|
|
|
telemetry.AddEventsCollector();
|
|
|
|
telemetry.AddQueryModuleCollector();
|
|
|
|
telemetry.AddExceptionCollector();
|
|
|
|
telemetry.AddReplicationCollector();
|
|
|
|
|
2018-06-20 19:46:54 +08:00
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(FLAGS_duration));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|