Skip to content

Commit f005fe5

Browse files
committed
Telemetry: Switch to ingest api v2
Changes the endpoint, payload structure and payload members (no longer including an empty optional member). Includes a slight change to where quotes are escaped from the json payload, so the verbose printed version is valid json itself Closes #1285
1 parent 8b68331 commit f005fe5

5 files changed

Lines changed: 27 additions & 28 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ Support for academic software is dependant on evidence of impact. Without eviden
331331

332332
Information is collected when a simulation, ensemble or test suite run have completed.
333333

334-
The [TelemetryDeck](https://telemetrydeck.com/) service is used to store telemetry data.
335-
All data is sent to their API endpoint of https://nom.telemetrydeck.com/v1/ via https. For more details please review the [TelmetryDeck privacy policy](https://telemetrydeck.com/privacy/).
334+
The [TelemetryDeck](https://telemetrydeck.com/) service is used to store telemetry data.
335+
All data is sent to their [Ingest API v2](https://telemetrydeck.com/docs/ingest/v2) endpoint of https://nom.telemetrydeck.com/v2/. For more details please review the [TelmetryDeck privacy policy](https://telemetrydeck.com/privacy/).
336336

337337
We do not collect any personal data such as usernames, email addresses or hardware identifiers but we do generate a random user identifier. This identifier is salted and hashed by Telemetry deck.
338338

include/flamegpu/io/Telemetry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void suppressNotice();
5252
/*
5353
* The remote endpoint which telemetry is pushed to.
5454
*/
55-
constexpr static char TELEMETRY_ENDPOINT[] = "https://nom.telemetrydeck.com/v1/";
55+
constexpr static char TELEMETRY_ENDPOINT[] = "https://nom.telemetrydeck.com/v2/";
5656

5757
/**
5858
* Generates the telemetry data packet as a string.

src/flamegpu/io/Telemetry.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -208,35 +208,32 @@ std::string Telemetry::generateData(std::string event_name, std::map<std::string
208208
payload_items["Visualisation"] = "false";
209209
#endif
210210

211-
// create the payload
212-
std::string payload = "";
213-
bool first = true;
214-
// iterate payload to generate the payload array
211+
// create the payload dictionary by iterating items.
212+
std::string payload = "{";
215213
for (const auto& [key, value] : payload_items) {
216-
std::string item_str;
217-
if (!first)
218-
item_str = ",\"" + key + ":" + value + "\"";
219-
else
220-
item_str = "\"" + key + ":" + value + "\"";
214+
std::string item_str = "\"" + key + "\":\"" + value + "\",";
221215
payload.append(item_str);
222-
first = false;
223216
}
217+
// Remove the trailing comma
218+
payload.pop_back();
219+
// Close the json object
220+
payload.append("}");
224221

225222
// create the telemetry json package
226223
std::string telemetry_data = R"json(
227224
[{
228-
"isTestMode": "$TEST_MODE",
229225
"appID": "$APP_ID",
230226
"clientUser": "$TELEMETRY_RANDOM_ID",
231-
"sessionID": "",
232227
"type" : "$EVENT_TYPE",
233-
"payload" : [$PAYLOAD]
228+
"isTestMode": "$TEST_MODE",
229+
"payload" : $PAYLOAD
234230
}])json";
231+
// "sessionID" is not set, and optional in v2
235232
// update the placeholders
236-
telemetry_data.replace(telemetry_data.find(var_testmode), var_testmode.length(), testmode);
237233
telemetry_data.replace(telemetry_data.find(var_appID), var_appID.length(), appID);
238234
telemetry_data.replace(telemetry_data.find(var_telemetryRandomID), var_telemetryRandomID.length(), telemetryRandomID);
239235
telemetry_data.replace(telemetry_data.find(var_eventName), var_eventName.length(), event_name);
236+
telemetry_data.replace(telemetry_data.find(var_testmode), var_testmode.length(), testmode);
240237
telemetry_data.replace(telemetry_data.find(var_payload), var_payload.length(), payload);
241238
// Remove newlines and replace with space
242239
telemetry_data.erase(std::remove(telemetry_data.begin(), telemetry_data.end(), '\n'), telemetry_data.end());
@@ -246,12 +243,6 @@ std::string Telemetry::generateData(std::string event_name, std::map<std::string
246243
telemetry_data.erase(std::remove_if(telemetry_data.begin(), telemetry_data.end(), [](char c) {
247244
return std::isspace(static_cast<unsigned char>(c));
248245
}), telemetry_data.end());
249-
// Use escape characters
250-
size_t pos = 0;
251-
while ((pos = telemetry_data.find("\"", pos)) != std::string::npos) {
252-
telemetry_data.replace(pos, 1, "\\\"");
253-
pos += 2;
254-
}
255246
return telemetry_data;
256247
}
257248

@@ -270,15 +261,23 @@ bool Telemetry::sendData(std::string telemetry_data) {
270261
#else
271262
null = "/dev/null";
272263
#endif
264+
265+
// Escape quotes, which surround the data payload when passed to curl.
266+
size_t pos = 0;
267+
while ((pos = telemetry_data.find("\"", pos)) != std::string::npos) {
268+
telemetry_data.replace(pos, 1, "\\\"");
269+
pos += 2;
270+
}
271+
273272
std::stringstream curl_command;
274273
curl_command << "curl";
275274
curl_command << " -s";
276275
curl_command << " -o " << null;
277276
curl_command << " --connect-timeout " << std::to_string(CURL_CONNECT_TIMEOUT);
278277
curl_command << " --max-time " << std::to_string(CURL_MAX_TIME);
279-
curl_command << " -X POST \"" << std::string(TELEMETRY_ENDPOINT) << "\"";
280-
curl_command << " -H \"Content-Type: application/json; charset=utf-8\"";
281-
curl_command << " --data-raw \"" << telemetry_data + "\"";
278+
curl_command << " -X POST '" << std::string(TELEMETRY_ENDPOINT) << "'";
279+
curl_command << " -H 'Content-Type: application/json; charset=utf-8'";
280+
curl_command << " --data-raw \"" << telemetry_data << "\"";
282281
curl_command << " > " << null << " 2>&1";
283282
// capture the return value
284283
if (std::system(curl_command.str().c_str()) != EXIT_SUCCESS) {

src/flamegpu/simulation/CUDAEnsemble.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ unsigned int CUDAEnsemble::simulate(const RunPlanVector& plans) {
463463
if (telemetrySuccess) {
464464
fprintf(stdout, "Telemetry packet sent to '%s' json was: %s\n", flamegpu::io::Telemetry::TELEMETRY_ENDPOINT, telemetry_data.c_str());
465465
} else {
466-
fprintf(stderr, "Warning: Usage statistics for CUDAEnsemble failed to send.\n");
466+
fprintf(stderr, "Warning: Usage statistics for CUDAEnsemble failed to send with json: %s\n", telemetry_data.c_str());
467467
}
468468
}
469469
} else {

src/flamegpu/simulation/CUDASimulation.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ void CUDASimulation::simulate() {
12951295
if (telemetrySuccess) {
12961296
fprintf(stdout, "Telemetry packet sent to '%s' json was: %s\n", flamegpu::io::Telemetry::TELEMETRY_ENDPOINT, telemetry_data.c_str());
12971297
} else {
1298-
fprintf(stderr, "Warning: Usage statistics for CUDASimulation failed to send.\n");
1298+
fprintf(stderr, "Warning: Usage statistics for CUDASimulation failed to send with json: %s\n", telemetry_data.c_str());
12991299
}
13001300
}
13011301
} else {

0 commit comments

Comments
 (0)