Add some error analyzer functions
@@ -4,7 +4,7 @@ from firebase_admin import credentials
from firebase_admin import firestore
from pathlib import Path
-
+KNWON_ERRORS = ['existing_backup_folder', 'google_dns', 'cancelled', 'google_timeout', 'low_space', 'multiple_deletes']
async def main():
cred = credentials.Certificate(str(Path.home().joinpath("Documents/secrets/server-firestore-creds.json")))
firebase_admin.initialize_app(cred)
@@ -25,9 +25,7 @@ async def main():
print("Done")
if command == "":
# Do regular analysis
- print("Inspecting the last 24 hours of records...")
- for item in reports.stream():
- pass
+ await stats(db, reports)
if command.startswith("get "):
query = reports.where("report.client", "==", command[4:])
for report in query.get():
@@ -40,5 +38,58 @@ async def main():
for report in query.get():
print(report.to_dict())
+
+async def stats(db, reports):
+ print("Inspecting the last 24 hours of records...")
+ cursor = None
+ batch_size = 50
+ summary = {}
+ resolved = {}
+ total = 0
+ while True:
+ count = 0
+ if cursor is None:
+ stream = reports.limit(batch_size).stream()
+ else:
+ stream = reports.limit(batch_size).start_after(cursor).stream()
+ for report in stream:
+ cursor = report
+ data = report.to_dict()
+ count += 1
+ total += 1
+ if 'report' not in data:
+ continue
+ if 'error' not in data['report']:
+ resolved[data['client']] = data['report']['duration']
+ continue
+ if data['report']['error'] in summary:
+ summary[data['report']['error']].append(data)
+ else:
+ summary[data['report']['error']] = [data]
+ print("Processed " + str(count) + " records")
+ if count == 0:
+ break
+ for error in summary.keys():
+ print("")
+ distinct = set()
+ unresolved = {}
+ versions = set()
+ for report in summary[error]:
+ distinct.add(report['client'])
+ if report['client'] not in resolved:
+ unresolved[report['client']] = report
+ versions.add(report['version'])
+ print("Unresolved: " + str(len(unresolved)))
+ print("Count: " + str(len(summary[error])))
+ print("Distinct: " + str(len(distinct)))
+ print("Versions: " + str(versions))
+ print("Error: " + error)
+ if len(unresolved) > 0:
+ print("Unresolved: ")
+ for unres in unresolved.values():
+ print(" " + unres['report']['arch'] + " " + unres['client'])
+ print("Total records: " + str(total))
+
+
if __name__ == '__main__':
asyncio.run(main())
