@hot-updater/plugin-insights 1.2.0-rc.6 → 1.2.0-rc.60

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.
Files changed (39) hide show
  1. package/dist/server/adminReads.cjs +5 -4
  2. package/dist/server/adminReads.mjs +5 -4
  3. package/dist/server/backfill.cjs +117 -0
  4. package/dist/server/backfill.d.cts +9 -0
  5. package/dist/server/backfill.d.mts +9 -0
  6. package/dist/server/backfill.mjs +117 -0
  7. package/dist/server/contract.cjs +18 -14
  8. package/dist/server/contract.mjs +18 -14
  9. package/dist/server/domain.d.cts +20 -2
  10. package/dist/server/domain.d.mts +20 -2
  11. package/dist/server/index.cjs +12 -1
  12. package/dist/server/index.d.cts +24 -2
  13. package/dist/server/index.d.mts +24 -2
  14. package/dist/server/index.mjs +13 -3
  15. package/dist/server/model.cjs +1 -0
  16. package/dist/server/model.mjs +1 -0
  17. package/dist/server/modelTypes.d.cts +32 -13
  18. package/dist/server/modelTypes.d.mts +32 -13
  19. package/dist/server/provider.cjs +24 -35
  20. package/dist/server/provider.mjs +24 -35
  21. package/dist/server/queryInput.cjs +4 -4
  22. package/dist/server/queryInput.mjs +4 -4
  23. package/dist/server/reads.cjs +118 -61
  24. package/dist/server/reads.d.cts +7 -0
  25. package/dist/server/reads.d.mts +7 -0
  26. package/dist/server/reads.mjs +119 -63
  27. package/dist/server/recordEvent.cjs +8 -44
  28. package/dist/server/recordEvent.mjs +10 -44
  29. package/dist/server/routes.cjs +2 -1
  30. package/dist/server/routes.mjs +2 -1
  31. package/dist/server/schema.cjs +30 -9
  32. package/dist/server/schema.mjs +30 -10
  33. package/dist/server/types.d.cts +2 -1
  34. package/dist/server/types.d.mts +2 -1
  35. package/dist/server/wire.cjs +34 -0
  36. package/dist/server/wire.d.cts +13 -0
  37. package/dist/server/wire.d.mts +13 -0
  38. package/dist/server/wire.mjs +32 -0
  39. package/package.json +4 -10
@@ -199,31 +199,48 @@ const countEventSeries = async (db, input) => {
199
199
  events: count
200
200
  }));
201
201
  };
202
- /** A bundle filter's distinct (field, value, type) predicates. */
203
- const latestPredicates = (bundle) => {
204
- if (bundle === void 0) return void 0;
205
- return [...new Map(bundle.flatMap(({ field, value, types }) => types.map((type) => [JSON.stringify([
206
- field,
207
- value,
208
- type
209
- ]), {
210
- field,
211
- value,
212
- type
213
- }]))).values()];
202
+ /** The distribution rows at or after `start`, a UTC day's start. */
203
+ const distributionRows = (db, { platform, channel, sinceMs: start }) => {
204
+ if (start % 864e5 !== 0) throw new _hot_updater_plugin_core.DatabaseAdapterInputError("invalid-query");
205
+ return drain((page) => db.findAggregates("insights_distribution", {
206
+ index: "byScope",
207
+ where: {
208
+ channel,
209
+ platform
210
+ },
211
+ range: { gte: start },
212
+ limit: PAGE,
213
+ ...page
214
+ }));
214
215
  };
216
+ const installations = (count) => Math.max(0, count);
215
217
  /**
216
218
  * Latest events at or after `sinceMs`, a UTC day's start: the gauges count
217
219
  * each installation in the UTC day of its latest event, so they answer whole
218
220
  * days only, and a later start is rejected rather than rounded.
219
221
  */
220
- const countLatestEvents = async (db, input) => {
221
- const { platform, channel, sinceMs: start } = input;
222
- if (start % 864e5 !== 0) throw new _hot_updater_plugin_core.DatabaseAdapterInputError("invalid-query");
223
- const predicates = latestPredicates(input.bundle);
222
+ const countLatestEvents = async (db, input) => installations((await distributionRows(db, input)).reduce((sum, row) => sum + row.latest_installations, 0));
223
+ /**
224
+ * `countLatestEvents`, and of those the installations it leaves running
225
+ * `releaseId`, from the same distribution rows in one read: each names the
226
+ * release its installations run. An ID no row names as a release may be a
227
+ * built-in bundle's, which a report without a release names, as event
228
+ * counts match it: its installations outside any release are in the
229
+ * built-in rows, read only then. Release and bundle IDs never coincide.
230
+ */
231
+ const countReleaseInstallations = async (db, input) => {
232
+ const { platform, channel, sinceMs: start, releaseId } = input;
224
233
  let total = 0;
225
- if (predicates === void 0) {
226
- const rows = await drain((page) => db.findAggregates("insights_distribution", {
234
+ let release = 0;
235
+ let named = false;
236
+ for (const row of await distributionRows(db, input)) {
237
+ total += row.latest_installations;
238
+ if (row.release_id !== releaseId) continue;
239
+ named = true;
240
+ release += row.latest_installations;
241
+ }
242
+ if (!named) {
243
+ const builtin = await drain((page) => db.findAggregates("insights_builtin_distribution", {
227
244
  index: "byScope",
228
245
  where: {
229
246
  channel,
@@ -233,33 +250,12 @@ const countLatestEvents = async (db, input) => {
233
250
  limit: PAGE,
234
251
  ...page
235
252
  }));
236
- total += rows.reduce((sum, row) => sum + row.latest_installations, 0);
237
- } else {
238
- const gauge = async (bundleField, bundleId, type) => {
239
- return (await drain((page) => db.findAggregates("insights_latest_by_bundle", {
240
- index: "byBundle",
241
- where: {
242
- platform,
243
- channel,
244
- bundle_field: bundleField,
245
- bundle_id: bundleId,
246
- type
247
- },
248
- range: { gte: start },
249
- limit: PAGE,
250
- ...page
251
- }))).reduce((sum, row) => sum + row.installations, 0);
252
- };
253
- for (const { field, value, type } of predicates) total += await gauge(field, value, type);
254
- for (const from of predicates) {
255
- if (from.field !== "from_bundle_id") continue;
256
- for (const to of predicates) {
257
- if (to.field !== "to_bundle_id" || to.type !== from.type) continue;
258
- total -= await gauge(require_recordEvent.PAIR_FIELD, require_recordEvent.bundlePairKey(from.value, to.value), from.type);
259
- }
260
- }
253
+ for (const row of builtin) if (row.release_id === "" && row.builtin_bundle_id === releaseId) release += row.latest_installations;
261
254
  }
262
- return Math.max(0, total);
255
+ return {
256
+ installations: installations(total),
257
+ release: installations(release)
258
+ };
263
259
  };
264
260
  /** The oldest whole hour and UTC day that hourly and daily rows still hold. */
265
261
  const retained = (now, { rawDays, dailyDays }) => ({
@@ -559,13 +555,80 @@ const breakdownOf = (rows) => {
559
555
  });
560
556
  };
561
557
  /**
558
+ * The breakdown rows a failures read takes from one hour. An hour holds a
559
+ * row per release, stage, reason, and detail that failed in it, a handful in
560
+ * practice, and an incident across several releases and error codes still
561
+ * fits; but a client with the app's API key can report any number of
562
+ * details.
563
+ */
564
+ const FAILURE_ROWS_PER_HOUR = 20;
565
+ /**
566
+ * One query's stored rows: an hour's bound and one more row, on every shard,
567
+ * so an hour past its bound costs at most one query's worth of rows more.
568
+ */
569
+ const FAILURE_QUERY_LIMIT = Math.min(PAGE, 168);
570
+ /**
571
+ * A channel's breakdown rows over a range, newest first, up to
572
+ * {@link FAILURE_ROWS_PER_HOUR} an hour: 480 rows for a day, 14,400 for 30
573
+ * days, however many details clients report. An hour that holds more is read
574
+ * no further, and the read goes on from the hour before it with a new query;
575
+ * the hour is listed in `cappedHours`, since its failures count only in part.
576
+ * Every other hour counts every failure it holds.
577
+ */
578
+ const failureRowsByHour = async (db, platform, channel, timeRange) => {
579
+ const read = (end, cursor) => db.findAggregates("insights_failures", {
580
+ index: "byScope",
581
+ where: {
582
+ platform,
583
+ channel
584
+ },
585
+ range: {
586
+ gte: timeRange.start,
587
+ lt: end
588
+ },
589
+ order: "desc",
590
+ limit: FAILURE_QUERY_LIMIT,
591
+ ...cursor === void 0 ? {} : { cursor }
592
+ });
593
+ const rows = [];
594
+ const cappedHours = [];
595
+ const perHour = /* @__PURE__ */ new Map();
596
+ let end = timeRange.end;
597
+ let cursor;
598
+ while (end > timeRange.start) {
599
+ const page = await read(end, cursor);
600
+ let capped;
601
+ for (const row of page.rows) {
602
+ const hour = row.bucket_start_ms;
603
+ const count = (perHour.get(hour) ?? 0) + 1;
604
+ if (count > FAILURE_ROWS_PER_HOUR) {
605
+ capped = hour;
606
+ break;
607
+ }
608
+ perHour.set(hour, count);
609
+ rows.push(row);
610
+ }
611
+ if (capped !== void 0) {
612
+ cappedHours.unshift(capped);
613
+ end = capped;
614
+ cursor = void 0;
615
+ } else if (page.next === void 0) break;
616
+ else cursor = page.next;
617
+ }
618
+ return {
619
+ rows,
620
+ cappedHours
621
+ };
622
+ };
623
+ /**
562
624
  * A release's or a channel's update failures. Since a release's first
563
625
  * report: its lifetime counters and failed installations. Over a time range
564
626
  * of at most 30 days: failures, failed checks, and the breakdown by stage,
565
627
  * reason, and detail, all summed from the breakdown's hourly rows; downloads
566
628
  * from the counters; failed installations from their sketches. A release reads hourly rows, a
567
629
  * channel daily rows past 48 hours like its activity; the breakdown's rows
568
- * are hourly, so its coverage is the raw period's.
630
+ * are hourly, so its coverage is the raw period's, and partial when an hour
631
+ * held more breakdown rows than a read takes from it.
569
632
  */
570
633
  const getUpdateFailures = async (db, input, now, retention) => {
571
634
  const { platform, channel, releaseId, timeRange } = input;
@@ -627,7 +690,7 @@ const getUpdateFailures = async (db, input, now, retention) => {
627
690
  days,
628
691
  kept.hour
629
692
  ];
630
- const [counters, failures, checks, active, rows] = await Promise.all([
693
+ const [counters, failures, checks, active, { rows, cappedHours }] = await Promise.all([
631
694
  counterRows(db, parts, ...window),
632
695
  sketchRows(db, failure, ...window),
633
696
  days ? sketchRows(db, {
@@ -635,25 +698,17 @@ const getUpdateFailures = async (db, input, now, retention) => {
635
698
  scopeKind: "check"
636
699
  }, ...window) : [],
637
700
  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
- }))
701
+ failureRowsByHour(db, platform, channel, timeRange)
651
702
  ]);
652
703
  const total = (field) => counters.reduce((sum, row) => sum + row[field], 0);
653
704
  const scoped = rows.filter((row) => FAILURE_STAGES.has(row.stage) && (releaseId === void 0 || row.release_id === releaseId));
654
705
  const failuresAt = (counted) => scoped.reduce((sum, row) => sum + (counted(row.stage) ? Math.max(0, row.events) : 0), 0);
706
+ const coverage = coverageOf(timeRange.start, kept.hour);
655
707
  return {
656
- coverage: coverageOf(timeRange.start, kept.hour),
708
+ coverage: cappedHours.length === 0 ? coverage : {
709
+ kind: "partial",
710
+ sinceMs: coverage.sinceMs
711
+ },
657
712
  measuredAtMs: at,
658
713
  failedUpdates: failuresAt((stage) => stage !== "check"),
659
714
  failedInstallations: failed(failures),
@@ -665,7 +720,8 @@ const getUpdateFailures = async (db, input, now, retention) => {
665
720
  failedInstallations: failed(checks),
666
721
  activeInstallations: (0, _hot_updater_plugin_core.countDistinct)((0, _hot_updater_plugin_core.mergeDistinct)(active.map((row) => row.activity_users)))
667
722
  } } : {},
668
- breakdown: breakdownOf(scoped)
723
+ breakdown: breakdownOf(scoped),
724
+ ...cappedHours.length === 0 ? {} : { cappedHours }
669
725
  };
670
726
  };
671
727
  //#endregion
@@ -673,6 +729,7 @@ exports.UPDATE_FAILURES_RANGE_MS = UPDATE_FAILURES_RANGE_MS;
673
729
  exports.countEventSeries = countEventSeries;
674
730
  exports.countEvents = countEvents;
675
731
  exports.countLatestEvents = countLatestEvents;
732
+ exports.countReleaseInstallations = countReleaseInstallations;
676
733
  exports.findLatestEvents = findLatestEvents;
677
734
  exports.getAppUsage = getAppUsage;
678
735
  exports.getReleaseActivity = getReleaseActivity;
@@ -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 };
@@ -1,6 +1,6 @@
1
1
  import { DAILY_EVENTS, DAY_MS, HOUR_MS, bundleRefOfFilter } from "./schema.mjs";
2
2
  import "./provider.mjs";
3
- import { PAIR_FIELD, bundlePairKey, insightsIdentity } from "./recordEvent.mjs";
3
+ import { insightsIdentity } from "./recordEvent.mjs";
4
4
  import { DatabaseAdapterInputError, compareUtf8, countDistinct, mergeDistinct } from "@hot-updater/plugin-core";
5
5
  //#region src/server/reads.ts
6
6
  const PAGE = 500;
@@ -199,31 +199,48 @@ const countEventSeries = async (db, input) => {
199
199
  events: count
200
200
  }));
201
201
  };
202
- /** A bundle filter's distinct (field, value, type) predicates. */
203
- const latestPredicates = (bundle) => {
204
- if (bundle === void 0) return void 0;
205
- return [...new Map(bundle.flatMap(({ field, value, types }) => types.map((type) => [JSON.stringify([
206
- field,
207
- value,
208
- type
209
- ]), {
210
- field,
211
- value,
212
- type
213
- }]))).values()];
202
+ /** The distribution rows at or after `start`, a UTC day's start. */
203
+ const distributionRows = (db, { platform, channel, sinceMs: start }) => {
204
+ if (start % 864e5 !== 0) throw new DatabaseAdapterInputError("invalid-query");
205
+ return drain((page) => db.findAggregates("insights_distribution", {
206
+ index: "byScope",
207
+ where: {
208
+ channel,
209
+ platform
210
+ },
211
+ range: { gte: start },
212
+ limit: PAGE,
213
+ ...page
214
+ }));
214
215
  };
216
+ const installations = (count) => Math.max(0, count);
215
217
  /**
216
218
  * Latest events at or after `sinceMs`, a UTC day's start: the gauges count
217
219
  * each installation in the UTC day of its latest event, so they answer whole
218
220
  * days only, and a later start is rejected rather than rounded.
219
221
  */
220
- const countLatestEvents = async (db, input) => {
221
- const { platform, channel, sinceMs: start } = input;
222
- if (start % 864e5 !== 0) throw new DatabaseAdapterInputError("invalid-query");
223
- const predicates = latestPredicates(input.bundle);
222
+ const countLatestEvents = async (db, input) => installations((await distributionRows(db, input)).reduce((sum, row) => sum + row.latest_installations, 0));
223
+ /**
224
+ * `countLatestEvents`, and of those the installations it leaves running
225
+ * `releaseId`, from the same distribution rows in one read: each names the
226
+ * release its installations run. An ID no row names as a release may be a
227
+ * built-in bundle's, which a report without a release names, as event
228
+ * counts match it: its installations outside any release are in the
229
+ * built-in rows, read only then. Release and bundle IDs never coincide.
230
+ */
231
+ const countReleaseInstallations = async (db, input) => {
232
+ const { platform, channel, sinceMs: start, releaseId } = input;
224
233
  let total = 0;
225
- if (predicates === void 0) {
226
- const rows = await drain((page) => db.findAggregates("insights_distribution", {
234
+ let release = 0;
235
+ let named = false;
236
+ for (const row of await distributionRows(db, input)) {
237
+ total += row.latest_installations;
238
+ if (row.release_id !== releaseId) continue;
239
+ named = true;
240
+ release += row.latest_installations;
241
+ }
242
+ if (!named) {
243
+ const builtin = await drain((page) => db.findAggregates("insights_builtin_distribution", {
227
244
  index: "byScope",
228
245
  where: {
229
246
  channel,
@@ -233,33 +250,12 @@ const countLatestEvents = async (db, input) => {
233
250
  limit: PAGE,
234
251
  ...page
235
252
  }));
236
- total += rows.reduce((sum, row) => sum + row.latest_installations, 0);
237
- } else {
238
- const gauge = async (bundleField, bundleId, type) => {
239
- return (await drain((page) => db.findAggregates("insights_latest_by_bundle", {
240
- index: "byBundle",
241
- where: {
242
- platform,
243
- channel,
244
- bundle_field: bundleField,
245
- bundle_id: bundleId,
246
- type
247
- },
248
- range: { gte: start },
249
- limit: PAGE,
250
- ...page
251
- }))).reduce((sum, row) => sum + row.installations, 0);
252
- };
253
- for (const { field, value, type } of predicates) total += await gauge(field, value, type);
254
- for (const from of predicates) {
255
- if (from.field !== "from_bundle_id") continue;
256
- for (const to of predicates) {
257
- if (to.field !== "to_bundle_id" || to.type !== from.type) continue;
258
- total -= await gauge(PAIR_FIELD, bundlePairKey(from.value, to.value), from.type);
259
- }
260
- }
253
+ for (const row of builtin) if (row.release_id === "" && row.builtin_bundle_id === releaseId) release += row.latest_installations;
261
254
  }
262
- return Math.max(0, total);
255
+ return {
256
+ installations: installations(total),
257
+ release: installations(release)
258
+ };
263
259
  };
264
260
  /** The oldest whole hour and UTC day that hourly and daily rows still hold. */
265
261
  const retained = (now, { rawDays, dailyDays }) => ({
@@ -559,13 +555,80 @@ const breakdownOf = (rows) => {
559
555
  });
560
556
  };
561
557
  /**
558
+ * The breakdown rows a failures read takes from one hour. An hour holds a
559
+ * row per release, stage, reason, and detail that failed in it, a handful in
560
+ * practice, and an incident across several releases and error codes still
561
+ * fits; but a client with the app's API key can report any number of
562
+ * details.
563
+ */
564
+ const FAILURE_ROWS_PER_HOUR = 20;
565
+ /**
566
+ * One query's stored rows: an hour's bound and one more row, on every shard,
567
+ * so an hour past its bound costs at most one query's worth of rows more.
568
+ */
569
+ const FAILURE_QUERY_LIMIT = Math.min(PAGE, 168);
570
+ /**
571
+ * A channel's breakdown rows over a range, newest first, up to
572
+ * {@link FAILURE_ROWS_PER_HOUR} an hour: 480 rows for a day, 14,400 for 30
573
+ * days, however many details clients report. An hour that holds more is read
574
+ * no further, and the read goes on from the hour before it with a new query;
575
+ * the hour is listed in `cappedHours`, since its failures count only in part.
576
+ * Every other hour counts every failure it holds.
577
+ */
578
+ const failureRowsByHour = async (db, platform, channel, timeRange) => {
579
+ const read = (end, cursor) => db.findAggregates("insights_failures", {
580
+ index: "byScope",
581
+ where: {
582
+ platform,
583
+ channel
584
+ },
585
+ range: {
586
+ gte: timeRange.start,
587
+ lt: end
588
+ },
589
+ order: "desc",
590
+ limit: FAILURE_QUERY_LIMIT,
591
+ ...cursor === void 0 ? {} : { cursor }
592
+ });
593
+ const rows = [];
594
+ const cappedHours = [];
595
+ const perHour = /* @__PURE__ */ new Map();
596
+ let end = timeRange.end;
597
+ let cursor;
598
+ while (end > timeRange.start) {
599
+ const page = await read(end, cursor);
600
+ let capped;
601
+ for (const row of page.rows) {
602
+ const hour = row.bucket_start_ms;
603
+ const count = (perHour.get(hour) ?? 0) + 1;
604
+ if (count > FAILURE_ROWS_PER_HOUR) {
605
+ capped = hour;
606
+ break;
607
+ }
608
+ perHour.set(hour, count);
609
+ rows.push(row);
610
+ }
611
+ if (capped !== void 0) {
612
+ cappedHours.unshift(capped);
613
+ end = capped;
614
+ cursor = void 0;
615
+ } else if (page.next === void 0) break;
616
+ else cursor = page.next;
617
+ }
618
+ return {
619
+ rows,
620
+ cappedHours
621
+ };
622
+ };
623
+ /**
562
624
  * A release's or a channel's update failures. Since a release's first
563
625
  * report: its lifetime counters and failed installations. Over a time range
564
626
  * of at most 30 days: failures, failed checks, and the breakdown by stage,
565
627
  * reason, and detail, all summed from the breakdown's hourly rows; downloads
566
628
  * from the counters; failed installations from their sketches. A release reads hourly rows, a
567
629
  * channel daily rows past 48 hours like its activity; the breakdown's rows
568
- * are hourly, so its coverage is the raw period's.
630
+ * are hourly, so its coverage is the raw period's, and partial when an hour
631
+ * held more breakdown rows than a read takes from it.
569
632
  */
570
633
  const getUpdateFailures = async (db, input, now, retention) => {
571
634
  const { platform, channel, releaseId, timeRange } = input;
@@ -627,7 +690,7 @@ const getUpdateFailures = async (db, input, now, retention) => {
627
690
  days,
628
691
  kept.hour
629
692
  ];
630
- const [counters, failures, checks, active, rows] = await Promise.all([
693
+ const [counters, failures, checks, active, { rows, cappedHours }] = await Promise.all([
631
694
  counterRows(db, parts, ...window),
632
695
  sketchRows(db, failure, ...window),
633
696
  days ? sketchRows(db, {
@@ -635,25 +698,17 @@ const getUpdateFailures = async (db, input, now, retention) => {
635
698
  scopeKind: "check"
636
699
  }, ...window) : [],
637
700
  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
- }))
701
+ failureRowsByHour(db, platform, channel, timeRange)
651
702
  ]);
652
703
  const total = (field) => counters.reduce((sum, row) => sum + row[field], 0);
653
704
  const scoped = rows.filter((row) => FAILURE_STAGES.has(row.stage) && (releaseId === void 0 || row.release_id === releaseId));
654
705
  const failuresAt = (counted) => scoped.reduce((sum, row) => sum + (counted(row.stage) ? Math.max(0, row.events) : 0), 0);
706
+ const coverage = coverageOf(timeRange.start, kept.hour);
655
707
  return {
656
- coverage: coverageOf(timeRange.start, kept.hour),
708
+ coverage: cappedHours.length === 0 ? coverage : {
709
+ kind: "partial",
710
+ sinceMs: coverage.sinceMs
711
+ },
657
712
  measuredAtMs: at,
658
713
  failedUpdates: failuresAt((stage) => stage !== "check"),
659
714
  failedInstallations: failed(failures),
@@ -665,8 +720,9 @@ const getUpdateFailures = async (db, input, now, retention) => {
665
720
  failedInstallations: failed(checks),
666
721
  activeInstallations: countDistinct(mergeDistinct(active.map((row) => row.activity_users)))
667
722
  } } : {},
668
- breakdown: breakdownOf(scoped)
723
+ breakdown: breakdownOf(scoped),
724
+ ...cappedHours.length === 0 ? {} : { cappedHours }
669
725
  };
670
726
  };
671
727
  //#endregion
672
- export { UPDATE_FAILURES_RANGE_MS, countEventSeries, countEvents, countLatestEvents, findLatestEvents, getAppUsage, getReleaseActivity, getUpdateFailures, listEvents };
728
+ export { UPDATE_FAILURES_RANGE_MS, countEventSeries, countEvents, countLatestEvents, countReleaseInstallations, findLatestEvents, getAppUsage, getReleaseActivity, getUpdateFailures, listEvents };
@@ -1,5 +1,5 @@
1
- const require_eventRow = require("./eventRow.cjs");
2
1
  const require_schema = require("./schema.cjs");
2
+ const require_eventRow = require("./eventRow.cjs");
3
3
  const require_contract = require("./contract.cjs");
4
4
  const require_overview = require("./overview.cjs");
5
5
  let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
@@ -26,17 +26,10 @@ const gaugeSlot = (head) => ({
26
26
  builtinBundleId: require_eventRow.runningBuiltinBundleId(head)
27
27
  });
28
28
  /**
29
- * The `insights_latest_by_bundle` field of a head's (from, to) pair. A head
30
- * matches a `from` and a `to` predicate of one type at once only through its
31
- * pair, so this gauge is what a count subtracts to count it once.
32
- */
33
- const PAIR_FIELD = "from_to";
34
- /** The pair gauge's `bundle_id`: a hash of the two bundle ids, which fit no single 36-character column. */
35
- const bundlePairKey = (from, to) => require_overview.insightsKey(`${from.length}:${from}${to.length}:${to}`);
36
- /**
37
29
  * Moves a head's gauges: the distribution row, and the built-in one when it
38
- * runs its build's built-in bundle, one row per bundle it references, and
39
- * its pair; -1 takes back the head an event replaces.
30
+ * runs its build's built-in bundle; -1 takes back the head an event
31
+ * replaces. The distribution row names the release the head runs, so it is
32
+ * also each release's installation gauge.
40
33
  */
41
34
  const countHead = (tx, head, delta) => {
42
35
  const { bucket, releaseId, builtinBundleId } = gaugeSlot(head);
@@ -56,26 +49,6 @@ const countHead = (tx, head, delta) => {
56
49
  builtin_bundle_id: builtinBundleId,
57
50
  bucket_start_ms: bucket
58
51
  }, { latest_installations: delta }, { shardBy });
59
- for (const field of ["from_bundle_id", "to_bundle_id"]) {
60
- const bundleId = head[field];
61
- if (bundleId === null) continue;
62
- tx.aggregate("insights_latest_by_bundle", {
63
- platform: head.platform,
64
- channel: head.channel,
65
- bundle_field: field,
66
- bundle_id: bundleId,
67
- type: head.type,
68
- bucket_start_ms: bucket
69
- }, { installations: delta }, { shardBy });
70
- }
71
- if (head.from_bundle_id !== null) tx.aggregate("insights_latest_by_bundle", {
72
- platform: head.platform,
73
- channel: head.channel,
74
- bundle_field: PAIR_FIELD,
75
- bundle_id: bundlePairKey(head.from_bundle_id, head.to_bundle_id),
76
- type: head.type,
77
- bucket_start_ms: bucket
78
- }, { installations: delta }, { shardBy });
79
52
  };
80
53
  /**
81
54
  * Where each period's rows go, each with its retention: hours for 90 days,
@@ -136,26 +109,19 @@ const countEvent = (tx, event) => {
136
109
  }
137
110
  };
138
111
  /**
139
- * A stored event's outcome rows: its bundle filter's hour, when it has one
140
- * (`bundleRefsOf`), and every stored event's UTC day. A download that a
141
- * launch or crash implied counts in its bundle's download hour too, in the
142
- * hour of that launch or crash, so the download series covers what the
143
- * release's downloads count; the launch or crash is its row.
112
+ * A stored event's outcome rows: its bundle filter's hour, and the download
113
+ * hour of a download its launch or crash implied, each by release
114
+ * (`outcomeRefsOf`); and every stored event's UTC day.
144
115
  */
145
116
  const countOutcome = (tx, event) => {
146
117
  const shardBy = event.install_id;
147
- const hour = (type, bundleRef) => tx.aggregate("insights_outcomes", {
118
+ for (const [type, bundleRef] of require_schema.outcomeRefsOf(event)) tx.aggregate("insights_outcomes", {
148
119
  platform: event.platform,
149
120
  channel: event.channel,
150
121
  type,
151
122
  bundle_ref: bundleRef,
152
123
  bucket_start_ms: hourOf(event.received_at_ms)
153
124
  }, { events: 1 }, { shardBy });
154
- for (const bundleRef of require_schema.bundleRefsOf(event)) hour(event.type, bundleRef);
155
- if (event.metadata.implied_download === true) hour("UPDATE_DOWNLOADED", require_schema.bundleRefOfFilter({
156
- type: "UPDATE_DOWNLOADED",
157
- toBundleId: event.type === "RECOVERED" ? event.from_bundle_id : event.to_bundle_id
158
- }));
159
125
  tx.aggregate("insights_outcomes", {
160
126
  ...require_schema.DAILY_EVENTS,
161
127
  bucket_start_ms: dayOf(event.received_at_ms)
@@ -438,7 +404,5 @@ const recordEvent = (db, event) => {
438
404
  });
439
405
  };
440
406
  //#endregion
441
- exports.PAIR_FIELD = PAIR_FIELD;
442
- exports.bundlePairKey = bundlePairKey;
443
407
  exports.insightsIdentity = insightsIdentity;
444
408
  exports.recordEvent = recordEvent;