Skip to content

Commit 7b843a5

Browse files
authored
Merge pull request #13 from adam-p/lite-diagnostics
Add a "lite" diagnostic dump for more frequent logging
2 parents 8e0441b + f0c4289 commit 7b843a5

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

psicash.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ Result<string> PsiCash::GetRewardedActivityData() const {
477477
return json_data;
478478
}
479479

480-
json PsiCash::GetDiagnosticInfo() const {
480+
json PsiCash::GetDiagnosticInfo(bool lite) const {
481481
// NOTE: Do not put personal identifiers in this package.
482482
// TODO: This is still enough info to uniquely identify the user (combined with the
483483
// PsiCash DB). So maybe avoiding direct PII does not achieve anything, and we should
@@ -492,7 +492,6 @@ json PsiCash::GetDiagnosticInfo() const {
492492
j["isAccount"] = IsAccount();
493493
j["balance"] = Balance();
494494
j["serverTimeDiff"] = user_data_->GetServerTimeDiff().count(); // in milliseconds
495-
j["purchasePrices"] = GetPurchasePrices();
496495

497496
// Include a sanitized version of the purchases
498497
j["purchases"] = json::array();
@@ -501,6 +500,12 @@ json PsiCash::GetDiagnosticInfo() const {
501500
{"distinguisher", p.distinguisher}});
502501
}
503502

503+
// The purchase prices are about 800 bytes of the 1000 bytes in a typical diangnostic
504+
// dump, and they're generally not useful.
505+
if (!lite) {
506+
j["purchasePrices"] = GetPurchasePrices();
507+
}
508+
504509
return j;
505510
}
506511

psicash.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,12 @@ class PsiCash {
287287
error::Result<std::string> GetRewardedActivityData() const;
288288

289289
// TODO: This return value might be a problem for direct C++ consumers (vs glue).
290+
/// If `lite` is true, the diagnostic info will be smaller -- on the order of 200 bytes.
291+
/// If `lite` false, the diagnostic info will be larger -- on the order of 1k bytes.
292+
/// The smaller package is suitable for more frequent logging.
290293
/// Returns a JSON object suitable for serializing that can be included in a
291294
/// feedback diagnostic data package.
292-
nlohmann::json GetDiagnosticInfo() const;
295+
nlohmann::json GetDiagnosticInfo(bool lite) const;
293296

294297
//
295298
// API Server Requests

psicash_test.cpp

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,19 @@ TEST_F(TestPsiCash, GetDiagnosticInfo) {
11011101
"test":false,
11021102
"validTokenTypes":[]
11031103
})|"_json;
1104-
auto j = pc.GetDiagnosticInfo();
1104+
auto j = pc.GetDiagnosticInfo(/*lite=*/false);
1105+
ASSERT_EQ(j, want);
1106+
1107+
want = R"|({
1108+
"balance":0,
1109+
"isAccount":false,
1110+
"isLoggedOutAccount":false,
1111+
"purchases":[],
1112+
"serverTimeDiff":0,
1113+
"test":false,
1114+
"validTokenTypes":[]
1115+
})|"_json;
1116+
j = pc.GetDiagnosticInfo(/*lite=*/true);
11051117
ASSERT_EQ(j, want);
11061118
}
11071119

@@ -1121,7 +1133,19 @@ TEST_F(TestPsiCash, GetDiagnosticInfo) {
11211133
"test":true,
11221134
"validTokenTypes":[]
11231135
})|"_json;
1124-
auto j = pc.GetDiagnosticInfo();
1136+
auto j = pc.GetDiagnosticInfo(/*lite=*/false);
1137+
ASSERT_EQ(j, want);
1138+
1139+
want = R"|({
1140+
"balance":0,
1141+
"isAccount":false,
1142+
"isLoggedOutAccount":false,
1143+
"purchases":[],
1144+
"serverTimeDiff":0,
1145+
"test":true,
1146+
"validTokenTypes":[]
1147+
})|"_json;
1148+
j = pc.GetDiagnosticInfo(/*lite=*/true);
11251149
ASSERT_EQ(j, want);
11261150

11271151
pc.user_data().SetBalance(12345);
@@ -1140,7 +1164,18 @@ TEST_F(TestPsiCash, GetDiagnosticInfo) {
11401164
"test":true,
11411165
"validTokenTypes":["a","b","c"]
11421166
})|"_json;
1143-
j = pc.GetDiagnosticInfo();
1167+
j = pc.GetDiagnosticInfo(/*lite=*/false);
1168+
ASSERT_EQ(j, want);
1169+
want = R"|({
1170+
"balance":12345,
1171+
"isAccount":true,
1172+
"isLoggedOutAccount":false,
1173+
"purchases":[{"class":"tc2","distinguisher":"d2"}],
1174+
"serverTimeDiff":0,
1175+
"test":true,
1176+
"validTokenTypes":["a","b","c"]
1177+
})|"_json;
1178+
j = pc.GetDiagnosticInfo(/*lite=*/true);
11441179
ASSERT_EQ(j, want);
11451180

11461181
pc.user_data().DeleteUserData(/*is_logged_out_account=*/true);
@@ -1154,7 +1189,18 @@ TEST_F(TestPsiCash, GetDiagnosticInfo) {
11541189
"test":true,
11551190
"validTokenTypes":[]
11561191
})|"_json;
1157-
j = pc.GetDiagnosticInfo();
1192+
j = pc.GetDiagnosticInfo(/*lite=*/false);
1193+
ASSERT_EQ(j, want);
1194+
want = R"|({
1195+
"balance":0,
1196+
"isAccount":true,
1197+
"isLoggedOutAccount":true,
1198+
"purchases":[],
1199+
"serverTimeDiff":0,
1200+
"test":true,
1201+
"validTokenTypes":[]
1202+
})|"_json;
1203+
j = pc.GetDiagnosticInfo(/*lite=*/true);
11581204
ASSERT_EQ(j, want);
11591205
}
11601206
}

0 commit comments

Comments
 (0)