Merge master (#554)
This commit is contained in:
parent
0876a8848d
commit
43e0520bc8
@ -462,6 +462,8 @@ struct SessionData {
|
||||
memgraph::utils::Synchronized<memgraph::auth::Auth, memgraph::utils::WritePrioritizedRWLock> *auth;
|
||||
|
||||
#endif
|
||||
// NOTE: run_id should be const but that complicates code a lot.
|
||||
std::optional<std::string> run_id;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
@ -482,7 +484,8 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
|
||||
#if MG_ENTERPRISE
|
||||
audit_log_(data->audit_log),
|
||||
#endif
|
||||
endpoint_(endpoint) {
|
||||
endpoint_(endpoint),
|
||||
run_id_(data->run_id) {
|
||||
}
|
||||
|
||||
using memgraph::communication::bolt::Session<memgraph::communication::v2::InputStream,
|
||||
@ -576,6 +579,14 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
|
||||
}
|
||||
decoded_summary.emplace(kv.first, std::move(*maybe_value));
|
||||
}
|
||||
// Add this memgraph instance run_id, received from telemetry
|
||||
// This is sent with every query, instead of only on bolt init inside
|
||||
// communication/bolt/v1/states/init.hpp because neo4jdriver does not
|
||||
// read the init message.
|
||||
if (auto run_id = run_id_; run_id) {
|
||||
decoded_summary.emplace("run_id", *run_id);
|
||||
}
|
||||
|
||||
return decoded_summary;
|
||||
} catch (const memgraph::query::QueryException &e) {
|
||||
// Wrap QueryException into ClientError, because we want to allow the
|
||||
@ -627,6 +638,8 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
|
||||
memgraph::audit::Log *audit_log_;
|
||||
#endif
|
||||
memgraph::communication::v2::ServerEndpoint endpoint_;
|
||||
// NOTE: run_id should be const but that complicates code a lot.
|
||||
std::optional<std::string> run_id_;
|
||||
};
|
||||
|
||||
using ServerT = memgraph::communication::v2::Server<BoltSession, SessionData>;
|
||||
@ -898,6 +911,7 @@ int main(int argc, char **argv) {
|
||||
if (FLAGS_telemetry_enabled) {
|
||||
telemetry.emplace("https://telemetry.memgraph.com/88b5e7e8-746a-11e8-9f85-538a9e9690cc/",
|
||||
data_directory / "telemetry", std::chrono::minutes(10));
|
||||
session_data.run_id = telemetry->GetRunId();
|
||||
telemetry->AddCollector("storage", [&db]() -> nlohmann::json {
|
||||
auto info = db.GetInfo();
|
||||
return {{"vertices", info.vertex_count}, {"edges", info.edge_count}};
|
||||
|
@ -59,6 +59,8 @@ void Telemetry::AddCollector(const std::string &name, const std::function<const
|
||||
collectors_.emplace_back(name, func);
|
||||
}
|
||||
|
||||
std::string Telemetry::GetRunId() const { return uuid_; }
|
||||
|
||||
Telemetry::~Telemetry() {
|
||||
scheduler_.Stop();
|
||||
CollectData("shutdown");
|
||||
|
@ -39,6 +39,9 @@ class Telemetry final {
|
||||
|
||||
void AddCollector(const std::string &name, const std::function<const nlohmann::json(void)> &func);
|
||||
|
||||
/// Required to expose run_id to Bolt server.
|
||||
std::string GetRunId() const;
|
||||
|
||||
~Telemetry();
|
||||
|
||||
Telemetry(const Telemetry &) = delete;
|
||||
|
29
tests/e2e/telemetry/README.md
Normal file
29
tests/e2e/telemetry/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
## Local test to check whether run_id is inside query metadata
|
||||
|
||||
In order to run this test, you should enable telemetry while running Memgraph,
|
||||
because telemetry generated the run_id of a Memgraph instance.
|
||||
|
||||
Before doing that, we need to restrict the communication with memgraph's
|
||||
telemetry server, so tests wouldn't give us garbage telemetry. To do that you
|
||||
should add:
|
||||
```
|
||||
127.0.0.1 telemetry.memgraph.com
|
||||
```
|
||||
to the beginning of `/etc/hosts`.
|
||||
|
||||
Now that you blocked telemetry from being sent, you should run memgraph with
|
||||
telemetry enabled:
|
||||
```
|
||||
memgraph --telemetry-enabled=True
|
||||
```
|
||||
Finally, to run the test:
|
||||
```
|
||||
npm install
|
||||
node get-run_id.js
|
||||
```
|
||||
|
||||
Output should be:
|
||||
```
|
||||
Query: MATCH (n) RETURN n LIMIT 1;
|
||||
run_id: <your-memgraph-run_id>
|
||||
```
|
42
tests/e2e/telemetry/get-run_id.js
Normal file
42
tests/e2e/telemetry/get-run_id.js
Normal file
@ -0,0 +1,42 @@
|
||||
const neo4j = require('neo4j-driver');
|
||||
|
||||
const runQuery = async (driver, query) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const session = driver.session();
|
||||
const activeSession = session.run(query);
|
||||
|
||||
activeSession._createSummary = async (metadata) => {
|
||||
return metadata;
|
||||
};
|
||||
|
||||
activeSession.subscribe({
|
||||
onCompleted: async (summary) => {
|
||||
await session.close();
|
||||
const result = summary;
|
||||
resolve(result);
|
||||
},
|
||||
onError: async (error) => {
|
||||
await session.close();
|
||||
reject(error);
|
||||
},
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
const driver = neo4j.driver('bolt://localhost:7687');
|
||||
|
||||
query = "MATCH (n) RETURN n LIMIT 1;"
|
||||
|
||||
console.log('Query:', query);
|
||||
const results = await runQuery(driver, query);
|
||||
if (results.hasOwnProperty("run_id")) {
|
||||
console.log("run_id:", results["run_id"]);
|
||||
} else {
|
||||
process.exit(1);
|
||||
}
|
||||
await driver.close();
|
||||
};
|
||||
|
||||
main(process.argv[2])
|
||||
.catch((error) => console.error(error));
|
15
tests/e2e/telemetry/package.json
Normal file
15
tests/e2e/telemetry/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "testing-neo4j-driver",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.21",
|
||||
"neo4j-driver": "^4.2.3"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user