@hot-updater/plugin-insights 1.2.0-rc.5 → 1.2.0-rc.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -559,13 +559,80 @@ const breakdownOf = (rows) => {
559
559
  });
560
560
  };
561
561
  /**
562
+ * The breakdown rows a failures read takes from one hour. An hour holds a
563
+ * row per release, stage, reason, and detail that failed in it, a handful in
564
+ * practice, and an incident across several releases and error codes still
565
+ * fits; but a client with the app's API key can report any number of
566
+ * details.
567
+ */
568
+ const FAILURE_ROWS_PER_HOUR = 20;
569
+ /**
570
+ * One query's stored rows: an hour's bound and one more row, on every shard,
571
+ * so an hour past its bound costs at most one query's worth of rows more.
572
+ */
573
+ const FAILURE_QUERY_LIMIT = Math.min(PAGE, 168);
574
+ /**
575
+ * A channel's breakdown rows over a range, newest first, up to
576
+ * {@link FAILURE_ROWS_PER_HOUR} an hour: 480 rows for a day, 14,400 for 30
577
+ * days, however many details clients report. An hour that holds more is read
578
+ * no further, and the read goes on from the hour before it with a new query;
579
+ * the hour is listed in `cappedHours`, since its failures count only in part.
580
+ * Every other hour counts every failure it holds.
581
+ */
582
+ const failureRowsByHour = async (db, platform, channel, timeRange) => {
583
+ const read = (end, cursor) => db.findAggregates("insights_failures", {
584
+ index: "byScope",
585
+ where: {
586
+ platform,
587
+ channel
588
+ },
589
+ range: {
590
+ gte: timeRange.start,
591
+ lt: end
592
+ },
593
+ order: "desc",
594
+ limit: FAILURE_QUERY_LIMIT,
595
+ ...cursor === void 0 ? {} : { cursor }
596
+ });
597
+ const rows = [];
598
+ const cappedHours = [];
599
+ const perHour = /* @__PURE__ */ new Map();
600
+ let end = timeRange.end;
601
+ let cursor;
602
+ while (end > timeRange.start) {
603
+ const page = await read(end, cursor);
604
+ let capped;
605
+ for (const row of page.rows) {
606
+ const hour = row.bucket_start_ms;
607
+ const count = (perHour.get(hour) ?? 0) + 1;
608
+ if (count > FAILURE_ROWS_PER_HOUR) {
609
+ capped = hour;
610
+ break;
611
+ }
612
+ perHour.set(hour, count);
613
+ rows.push(row);
614
+ }
615
+ if (capped !== void 0) {
616
+ cappedHours.unshift(capped);
617
+ end = capped;
618
+ cursor = void 0;
619
+ } else if (page.next === void 0) break;
620
+ else cursor = page.next;
621
+ }
622
+ return {
623
+ rows,
624
+ cappedHours
625
+ };
626
+ };
627
+ /**
562
628
  * A release's or a channel's update failures. Since a release's first
563
629
  * report: its lifetime counters and failed installations. Over a time range
564
630
  * of at most 30 days: failures, failed checks, and the breakdown by stage,
565
631
  * reason, and detail, all summed from the breakdown's hourly rows; downloads
566
632
  * from the counters; failed installations from their sketches. A release reads hourly rows, a
567
633
  * channel daily rows past 48 hours like its activity; the breakdown's rows
568
- * are hourly, so its coverage is the raw period's.
634
+ * are hourly, so its coverage is the raw period's, and partial when an hour
635
+ * held more breakdown rows than a read takes from it.
569
636
  */
570
637
  const getUpdateFailures = async (db, input, now, retention) => {
571
638
  const { platform, channel, releaseId, timeRange } = input;
@@ -627,7 +694,7 @@ const getUpdateFailures = async (db, input, now, retention) => {
627
694
  days,
628
695
  kept.hour
629
696
  ];
630
- const [counters, failures, checks, active, rows] = await Promise.all([
697
+ const [counters, failures, checks, active, { rows, cappedHours }] = await Promise.all([
631
698
  counterRows(db, parts, ...window),
632
699
  sketchRows(db, failure, ...window),
633
700
  days ? sketchRows(db, {
@@ -635,25 +702,17 @@ const getUpdateFailures = async (db, input, now, retention) => {
635
702
  scopeKind: "check"
636
703
  }, ...window) : [],
637
704
  days ? sketchRows(db, usageParts(channel, platform), ...window) : [],
638
- drain((page) => db.findAggregates("insights_failures", {
639
- index: "byScope",
640
- where: {
641
- platform,
642
- channel
643
- },
644
- range: {
645
- gte: timeRange.start,
646
- lt: timeRange.end
647
- },
648
- limit: PAGE,
649
- ...page
650
- }))
705
+ failureRowsByHour(db, platform, channel, timeRange)
651
706
  ]);
652
707
  const total = (field) => counters.reduce((sum, row) => sum + row[field], 0);
653
708
  const scoped = rows.filter((row) => FAILURE_STAGES.has(row.stage) && (releaseId === void 0 || row.release_id === releaseId));
654
709
  const failuresAt = (counted) => scoped.reduce((sum, row) => sum + (counted(row.stage) ? Math.max(0, row.events) : 0), 0);
710
+ const coverage = coverageOf(timeRange.start, kept.hour);
655
711
  return {
656
- coverage: coverageOf(timeRange.start, kept.hour),
712
+ coverage: cappedHours.length === 0 ? coverage : {
713
+ kind: "partial",
714
+ sinceMs: coverage.sinceMs
715
+ },
657
716
  measuredAtMs: at,
658
717
  failedUpdates: failuresAt((stage) => stage !== "check"),
659
718
  failedInstallations: failed(failures),
@@ -665,7 +724,8 @@ const getUpdateFailures = async (db, input, now, retention) => {
665
724
  failedInstallations: failed(checks),
666
725
  activeInstallations: (0, _hot_updater_plugin_core.countDistinct)((0, _hot_updater_plugin_core.mergeDistinct)(active.map((row) => row.activity_users)))
667
726
  } } : {},
668
- breakdown: breakdownOf(scoped)
727
+ breakdown: breakdownOf(scoped),
728
+ ...cappedHours.length === 0 ? {} : { cappedHours }
669
729
  };
670
730
  };
671
731
  //#endregion
@@ -44,6 +44,13 @@ interface InsightsUpdateFailures {
44
44
  };
45
45
  /** Over a time range: failures by stage and reason, most first. */
46
46
  readonly breakdown?: readonly InsightsFailureBreakdown[];
47
+ /**
48
+ * Over a time range: the hours, oldest first, that held more breakdown rows
49
+ * than a read takes from an hour. Their failures count only in part, so the
50
+ * failure counts and the breakdown are at least what they say, and the
51
+ * coverage is partial. Downloads and installations count in full.
52
+ */
53
+ readonly cappedHours?: readonly number[];
47
54
  }
48
55
  //#endregion
49
56
  export { InsightsFailureBreakdown, InsightsUpdateFailures, InsightsUpdateFailuresInput };
@@ -44,6 +44,13 @@ interface InsightsUpdateFailures {
44
44
  };
45
45
  /** Over a time range: failures by stage and reason, most first. */
46
46
  readonly breakdown?: readonly InsightsFailureBreakdown[];
47
+ /**
48
+ * Over a time range: the hours, oldest first, that held more breakdown rows
49
+ * than a read takes from an hour. Their failures count only in part, so the
50
+ * failure counts and the breakdown are at least what they say, and the
51
+ * coverage is partial. Downloads and installations count in full.
52
+ */
53
+ readonly cappedHours?: readonly number[];
47
54
  }
48
55
  //#endregion
49
56
  export { InsightsFailureBreakdown, InsightsUpdateFailures, InsightsUpdateFailuresInput };
@@ -559,13 +559,80 @@ const breakdownOf = (rows) => {
559
559
  });
560
560
  };
561
561
  /**
562
+ * The breakdown rows a failures read takes from one hour. An hour holds a
563
+ * row per release, stage, reason, and detail that failed in it, a handful in
564
+ * practice, and an incident across several releases and error codes still
565
+ * fits; but a client with the app's API key can report any number of
566
+ * details.
567
+ */
568
+ const FAILURE_ROWS_PER_HOUR = 20;
569
+ /**
570
+ * One query's stored rows: an hour's bound and one more row, on every shard,
571
+ * so an hour past its bound costs at most one query's worth of rows more.
572
+ */
573
+ const FAILURE_QUERY_LIMIT = Math.min(PAGE, 168);
574
+ /**
575
+ * A channel's breakdown rows over a range, newest first, up to
576
+ * {@link FAILURE_ROWS_PER_HOUR} an hour: 480 rows for a day, 14,400 for 30
577
+ * days, however many details clients report. An hour that holds more is read
578
+ * no further, and the read goes on from the hour before it with a new query;
579
+ * the hour is listed in `cappedHours`, since its failures count only in part.
580
+ * Every other hour counts every failure it holds.
581
+ */
582
+ const failureRowsByHour = async (db, platform, channel, timeRange) => {
583
+ const read = (end, cursor) => db.findAggregates("insights_failures", {
584
+ index: "byScope",
585
+ where: {
586
+ platform,
587
+ channel
588
+ },
589
+ range: {
590
+ gte: timeRange.start,
591
+ lt: end
592
+ },
593
+ order: "desc",
594
+ limit: FAILURE_QUERY_LIMIT,
595
+ ...cursor === void 0 ? {} : { cursor }
596
+ });
597
+ const rows = [];
598
+ const cappedHours = [];
599
+ const perHour = /* @__PURE__ */ new Map();
600
+ let end = timeRange.end;
601
+ let cursor;
602
+ while (end > timeRange.start) {
603
+ const page = await read(end, cursor);
604
+ let capped;
605
+ for (const row of page.rows) {
606
+ const hour = row.bucket_start_ms;
607
+ const count = (perHour.get(hour) ?? 0) + 1;
608
+ if (count > FAILURE_ROWS_PER_HOUR) {
609
+ capped = hour;
610
+ break;
611
+ }
612
+ perHour.set(hour, count);
613
+ rows.push(row);
614
+ }
615
+ if (capped !== void 0) {
616
+ cappedHours.unshift(capped);
617
+ end = capped;
618
+ cursor = void 0;
619
+ } else if (page.next === void 0) break;
620
+ else cursor = page.next;
621
+ }
622
+ return {
623
+ rows,
624
+ cappedHours
625
+ };
626
+ };
627
+ /**
562
628
  * A release's or a channel's update failures. Since a release's first
563
629
  * report: its lifetime counters and failed installations. Over a time range
564
630
  * of at most 30 days: failures, failed checks, and the breakdown by stage,
565
631
  * reason, and detail, all summed from the breakdown's hourly rows; downloads
566
632
  * from the counters; failed installations from their sketches. A release reads hourly rows, a
567
633
  * channel daily rows past 48 hours like its activity; the breakdown's rows
568
- * are hourly, so its coverage is the raw period's.
634
+ * are hourly, so its coverage is the raw period's, and partial when an hour
635
+ * held more breakdown rows than a read takes from it.
569
636
  */
570
637
  const getUpdateFailures = async (db, input, now, retention) => {
571
638
  const { platform, channel, releaseId, timeRange } = input;
@@ -627,7 +694,7 @@ const getUpdateFailures = async (db, input, now, retention) => {
627
694
  days,
628
695
  kept.hour
629
696
  ];
630
- const [counters, failures, checks, active, rows] = await Promise.all([
697
+ const [counters, failures, checks, active, { rows, cappedHours }] = await Promise.all([
631
698
  counterRows(db, parts, ...window),
632
699
  sketchRows(db, failure, ...window),
633
700
  days ? sketchRows(db, {
@@ -635,25 +702,17 @@ const getUpdateFailures = async (db, input, now, retention) => {
635
702
  scopeKind: "check"
636
703
  }, ...window) : [],
637
704
  days ? sketchRows(db, usageParts(channel, platform), ...window) : [],
638
- drain((page) => db.findAggregates("insights_failures", {
639
- index: "byScope",
640
- where: {
641
- platform,
642
- channel
643
- },
644
- range: {
645
- gte: timeRange.start,
646
- lt: timeRange.end
647
- },
648
- limit: PAGE,
649
- ...page
650
- }))
705
+ failureRowsByHour(db, platform, channel, timeRange)
651
706
  ]);
652
707
  const total = (field) => counters.reduce((sum, row) => sum + row[field], 0);
653
708
  const scoped = rows.filter((row) => FAILURE_STAGES.has(row.stage) && (releaseId === void 0 || row.release_id === releaseId));
654
709
  const failuresAt = (counted) => scoped.reduce((sum, row) => sum + (counted(row.stage) ? Math.max(0, row.events) : 0), 0);
710
+ const coverage = coverageOf(timeRange.start, kept.hour);
655
711
  return {
656
- coverage: coverageOf(timeRange.start, kept.hour),
712
+ coverage: cappedHours.length === 0 ? coverage : {
713
+ kind: "partial",
714
+ sinceMs: coverage.sinceMs
715
+ },
657
716
  measuredAtMs: at,
658
717
  failedUpdates: failuresAt((stage) => stage !== "check"),
659
718
  failedInstallations: failed(failures),
@@ -665,7 +724,8 @@ const getUpdateFailures = async (db, input, now, retention) => {
665
724
  failedInstallations: failed(checks),
666
725
  activeInstallations: countDistinct(mergeDistinct(active.map((row) => row.activity_users)))
667
726
  } } : {},
668
- breakdown: breakdownOf(scoped)
727
+ breakdown: breakdownOf(scoped),
728
+ ...cappedHours.length === 0 ? {} : { cappedHours }
669
729
  };
670
730
  };
671
731
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/plugin-insights",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.5",
4
+ "version": "1.2.0-rc.50",
5
5
  "description": "Hot Updater's Insights plugin: launch, download, and update failure events, for the server and the React Native app",
6
6
  "exports": {
7
7
  "./client": {
@@ -33,10 +33,10 @@
33
33
  "package.json"
34
34
  ],
35
35
  "dependencies": {
36
- "@hot-updater/protocol": "1.2.0-rc.5"
36
+ "@hot-updater/protocol": "1.2.0-rc.50"
37
37
  },
38
38
  "peerDependencies": {
39
- "@hot-updater/plugin-core": "^1.2.0-rc.5"
39
+ "@hot-updater/plugin-core": "^1.2.0-rc.50"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@hot-updater/plugin-core": {
@@ -46,13 +46,7 @@
46
46
  "devDependencies": {
47
47
  "@types/node": "^20",
48
48
  "vitest": "4.1.4",
49
- "@hot-updater/plugin-core": "1.2.0-rc.5",
50
- "@hot-updater/test-utils": "1.2.0-rc.5"
51
- },
52
- "nx": {
53
- "implicitDependencies": [
54
- "!@hot-updater/test-utils"
55
- ]
49
+ "@hot-updater/plugin-core": "1.2.0-rc.50"
56
50
  },
57
51
  "scripts": {
58
52
  "build": "tsdown",