@hot-updater/plugin-insights 1.2.0-rc.56 → 1.2.0-rc.58
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.
- package/dist/server/adminReads.cjs +5 -4
- package/dist/server/adminReads.mjs +5 -4
- package/dist/server/backfill.cjs +93 -0
- package/dist/server/backfill.d.cts +9 -0
- package/dist/server/backfill.d.mts +9 -0
- package/dist/server/backfill.mjs +93 -0
- package/dist/server/contract.cjs +18 -14
- package/dist/server/contract.mjs +18 -14
- package/dist/server/domain.d.cts +20 -2
- package/dist/server/domain.d.mts +20 -2
- package/dist/server/index.cjs +12 -1
- package/dist/server/index.d.cts +24 -2
- package/dist/server/index.d.mts +24 -2
- package/dist/server/index.mjs +13 -3
- package/dist/server/model.cjs +1 -0
- package/dist/server/model.mjs +1 -0
- package/dist/server/modelTypes.d.cts +32 -13
- package/dist/server/modelTypes.d.mts +32 -13
- package/dist/server/provider.cjs +24 -35
- package/dist/server/provider.mjs +24 -35
- package/dist/server/queryInput.cjs +4 -4
- package/dist/server/queryInput.mjs +4 -4
- package/dist/server/reads.cjs +41 -44
- package/dist/server/reads.mjs +42 -46
- package/dist/server/recordEvent.cjs +8 -44
- package/dist/server/recordEvent.mjs +10 -44
- package/dist/server/routes.cjs +2 -1
- package/dist/server/routes.mjs +2 -1
- package/dist/server/schema.cjs +30 -9
- package/dist/server/schema.mjs +30 -10
- package/dist/server/types.d.cts +2 -1
- package/dist/server/types.d.mts +2 -1
- package/dist/server/wire.cjs +34 -0
- package/dist/server/wire.d.cts +13 -0
- package/dist/server/wire.d.mts +13 -0
- package/dist/server/wire.mjs +32 -0
- package/package.json +4 -4
package/dist/server/reads.cjs
CHANGED
|
@@ -199,31 +199,48 @@ const countEventSeries = async (db, input) => {
|
|
|
199
199
|
events: count
|
|
200
200
|
}));
|
|
201
201
|
};
|
|
202
|
-
/**
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
return
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
226
|
-
|
|
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
|
-
|
|
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
|
|
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 }) => ({
|
|
@@ -733,6 +729,7 @@ exports.UPDATE_FAILURES_RANGE_MS = UPDATE_FAILURES_RANGE_MS;
|
|
|
733
729
|
exports.countEventSeries = countEventSeries;
|
|
734
730
|
exports.countEvents = countEvents;
|
|
735
731
|
exports.countLatestEvents = countLatestEvents;
|
|
732
|
+
exports.countReleaseInstallations = countReleaseInstallations;
|
|
736
733
|
exports.findLatestEvents = findLatestEvents;
|
|
737
734
|
exports.getAppUsage = getAppUsage;
|
|
738
735
|
exports.getReleaseActivity = getReleaseActivity;
|
package/dist/server/reads.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DAILY_EVENTS, DAY_MS, HOUR_MS, bundleRefOfFilter } from "./schema.mjs";
|
|
2
2
|
import "./provider.mjs";
|
|
3
|
-
import {
|
|
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
|
-
/**
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
return
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
226
|
-
|
|
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
|
-
|
|
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
|
|
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 }) => ({
|
|
@@ -729,4 +725,4 @@ const getUpdateFailures = async (db, input, now, retention) => {
|
|
|
729
725
|
};
|
|
730
726
|
};
|
|
731
727
|
//#endregion
|
|
732
|
-
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
|
|
39
|
-
*
|
|
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,
|
|
140
|
-
*
|
|
141
|
-
*
|
|
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
|
|
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { DAILY_EVENTS, DAY_MS, HOUR_MS, isLaunch, outcomeRefsOf } from "./schema.mjs";
|
|
1
2
|
import { runningBuiltinBundleId } from "./eventRow.mjs";
|
|
2
|
-
import { DAILY_EVENTS, DAY_MS, HOUR_MS, bundleRefOfFilter, bundleRefsOf, isLaunch } from "./schema.mjs";
|
|
3
3
|
import { assertBundleEventRow } from "./contract.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { insightsOverviewDeltas, insightsOverviewId } from "./overview.mjs";
|
|
5
5
|
import { addDistinct, compareUtf8, extractTimestampFromUUIDv7, isUUIDv7 } from "@hot-updater/plugin-core";
|
|
6
6
|
//#region src/server/recordEvent.ts
|
|
7
7
|
const hourOf = (ms) => ms - ms % HOUR_MS;
|
|
@@ -26,17 +26,10 @@ const gaugeSlot = (head) => ({
|
|
|
26
26
|
builtinBundleId: 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) => 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
|
|
39
|
-
*
|
|
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,
|
|
140
|
-
*
|
|
141
|
-
*
|
|
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
|
|
118
|
+
for (const [type, bundleRef] of 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 bundleRefsOf(event)) hour(event.type, bundleRef);
|
|
155
|
-
if (event.metadata.implied_download === true) hour("UPDATE_DOWNLOADED", 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
|
...DAILY_EVENTS,
|
|
161
127
|
bucket_start_ms: dayOf(event.received_at_ms)
|
|
@@ -438,4 +404,4 @@ const recordEvent = (db, event) => {
|
|
|
438
404
|
});
|
|
439
405
|
};
|
|
440
406
|
//#endregion
|
|
441
|
-
export {
|
|
407
|
+
export { insightsIdentity, recordEvent };
|
package/dist/server/routes.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_errors = require("./errors.cjs");
|
|
2
2
|
const require_eventInput = require("./eventInput.cjs");
|
|
3
|
+
const require_wire = require("./wire.cjs");
|
|
3
4
|
const require_queryInput = require("./queryInput.cjs");
|
|
4
5
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
5
6
|
//#region src/server/routes.ts
|
|
@@ -79,7 +80,7 @@ const createInsightsRouteHandlers = (provider) => ({
|
|
|
79
80
|
await provider.appendBundleEvent(await require_eventInput.parseBundleEventRequest(request));
|
|
80
81
|
return new Response(null, { status: 204 });
|
|
81
82
|
}),
|
|
82
|
-
getReportingOverview: (_params, request) => query(() => provider.getReportingOverview(require_queryInput.parseReportingOverviewInput(request))),
|
|
83
|
+
getReportingOverview: (_params, request) => query(async () => require_wire.toWireOverview(await provider.getReportingOverview(require_queryInput.parseReportingOverviewInput(request)))),
|
|
83
84
|
getInstallation: (params) => run(async () => {
|
|
84
85
|
const installation = await provider.getInstallation({ installId: requireParam(params, "installId") });
|
|
85
86
|
return installation === null ? json({ error: "Installation not found" }, 404) : json(installation, 200);
|
package/dist/server/routes.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InsightsBadRequestError, InsightsPayloadTooLargeError } from "./errors.mjs";
|
|
2
2
|
import { parseBundleEventRequest } from "./eventInput.mjs";
|
|
3
|
+
import { toWireOverview } from "./wire.mjs";
|
|
3
4
|
import { parseEventPageInput, parseReportingOverviewInput, parseUserInstallationPageInput } from "./queryInput.mjs";
|
|
4
5
|
import { isDatabaseBusyError } from "@hot-updater/plugin-core";
|
|
5
6
|
//#region src/server/routes.ts
|
|
@@ -79,7 +80,7 @@ const createInsightsRouteHandlers = (provider) => ({
|
|
|
79
80
|
await provider.appendBundleEvent(await parseBundleEventRequest(request));
|
|
80
81
|
return new Response(null, { status: 204 });
|
|
81
82
|
}),
|
|
82
|
-
getReportingOverview: (_params, request) => query(() => provider.getReportingOverview(parseReportingOverviewInput(request))),
|
|
83
|
+
getReportingOverview: (_params, request) => query(async () => toWireOverview(await provider.getReportingOverview(parseReportingOverviewInput(request)))),
|
|
83
84
|
getInstallation: (params) => run(async () => {
|
|
84
85
|
const installation = await provider.getInstallation({ installId: requireParam(params, "installId") });
|
|
85
86
|
return installation === null ? json({ error: "Installation not found" }, 404) : json(installation, 200);
|
package/dist/server/schema.cjs
CHANGED
|
@@ -37,21 +37,29 @@ const isLaunch = (row) => {
|
|
|
37
37
|
const kinds = metadataOf(row).change?.kinds ?? [];
|
|
38
38
|
return kinds.includes("bundle") && !kinds.includes("first_seen") && row.to_release_id !== null;
|
|
39
39
|
};
|
|
40
|
+
const sideRef = (key, releaseId, bundleId) => key === "release" ? releaseId ?? bundleId : bundleId;
|
|
40
41
|
/**
|
|
41
42
|
* The bundle a stored row's bundle filter matches: `from:<bundle>` for a
|
|
42
43
|
* recovery; `to:<bundle>` for a download, an apply, and an update failure;
|
|
43
44
|
* `on:<bundle>` for an UNCHANGED row that launched a bundle (`isLaunch`), a
|
|
44
45
|
* key no other row uses. None for a failed check, which targets no bundle, a
|
|
45
|
-
* late row, or any other UNCHANGED row.
|
|
46
|
+
* late row, or any other UNCHANGED row. Each names its bundle by `key`.
|
|
46
47
|
*/
|
|
47
|
-
const bundleRefsOf = (row) => {
|
|
48
|
+
const bundleRefsOf = (row, key = "release") => {
|
|
48
49
|
if (isFailedCheck(row) || isLateEvent(row)) return [];
|
|
49
|
-
if (row.type === "RECOVERED") return [`from:${row.from_bundle_id}`];
|
|
50
|
-
if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${row.to_bundle_id}`] : [];
|
|
51
|
-
return [`to:${row.to_bundle_id}`];
|
|
50
|
+
if (row.type === "RECOVERED") return [`from:${sideRef(key, row.from_release_id, row.from_bundle_id)}`];
|
|
51
|
+
if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${sideRef(key, row.to_release_id, row.to_bundle_id)}`] : [];
|
|
52
|
+
return [`to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`];
|
|
52
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* The hourly outcome rows a stored row counts in, as `[type, bundle ref]`:
|
|
56
|
+
* its bundle filter's (`bundleRefsOf`), and a download that a launch or
|
|
57
|
+
* crash implied, in its bundle's download hour, so the download series
|
|
58
|
+
* covers what the release's downloads count.
|
|
59
|
+
*/
|
|
60
|
+
const outcomeRefsOf = (row, key = "release") => [...bundleRefsOf(row, key).map((ref) => [row.type, ref]), ...metadataOf(row).implied_download === true ? [["UPDATE_DOWNLOADED", row.type === "RECOVERED" ? `to:${sideRef(key, row.from_release_id, row.from_bundle_id)}` : `to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`]] : []];
|
|
53
61
|
/** The key a bundle filter reads, as `bundleRefsOf` writes it. */
|
|
54
|
-
const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.
|
|
62
|
+
const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.fromReleaseId}` : filter.type === "UNCHANGED" ? `on:${filter.toReleaseId}` : `to:${filter.toReleaseId}`;
|
|
55
63
|
/**
|
|
56
64
|
* Downloads, applies, recoveries, update failures, and the UNCHANGED
|
|
57
65
|
* reports that changed what their installation runs, whole. An UNCHANGED
|
|
@@ -116,7 +124,11 @@ const bundleEvents = (days) => (0, _hot_updater_plugin_core.defineTable)({
|
|
|
116
124
|
type: "string",
|
|
117
125
|
compute: (row) => MOVEMENTS.has(row.type) ? row.install_id : null
|
|
118
126
|
},
|
|
119
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* The bundle a bundle filter matches (`bundleRefsOf`), by release.
|
|
129
|
+
* Rows a 1.1 server wrote name the artifact until
|
|
130
|
+
* `backfillReleaseRefs` rewrites them.
|
|
131
|
+
*/
|
|
120
132
|
bundle_ref: {
|
|
121
133
|
type: "string",
|
|
122
134
|
multi: true,
|
|
@@ -435,7 +447,13 @@ const insightsBuiltinDistribution = (retention) => (0, _hot_updater_plugin_core.
|
|
|
435
447
|
},
|
|
436
448
|
retention
|
|
437
449
|
});
|
|
438
|
-
/**
|
|
450
|
+
/**
|
|
451
|
+
* Latest events by the artifact they came from or went to, bucketed like
|
|
452
|
+
* the distribution, as 1.1 servers wrote them. Nothing writes or reads it
|
|
453
|
+
* since a bundle's installations come from `insights_distribution`, which
|
|
454
|
+
* names the release; it stays declared so retention still empties the rows
|
|
455
|
+
* a 1.1 server wrote.
|
|
456
|
+
*/
|
|
439
457
|
const insightsLatestByBundle = (retention) => (0, _hot_updater_plugin_core.defineAggregate)({
|
|
440
458
|
platform: {
|
|
441
459
|
type: "string",
|
|
@@ -483,7 +501,9 @@ const insightsLatestByBundle = (retention) => (0, _hot_updater_plugin_core.defin
|
|
|
483
501
|
* Stored events by outcome and the bundle a bundle filter matches, a row an
|
|
484
502
|
* hour, which a failed check has none of; and every stored event, a row a UTC
|
|
485
503
|
* day (`DAILY_EVENTS`). Bundle counts sum the hourly rows, and event lists
|
|
486
|
-
* read either to skip days without events.
|
|
504
|
+
* read either to skip days without events. `bundle_ref` names the release
|
|
505
|
+
* (`outcomeRefsOf`); a 1.1 server's rows name the artifact until
|
|
506
|
+
* `backfillReleaseRefs` moves their counts.
|
|
487
507
|
*/
|
|
488
508
|
const insightsOutcomes = (retention) => (0, _hot_updater_plugin_core.defineAggregate)({
|
|
489
509
|
platform: {
|
|
@@ -573,3 +593,4 @@ exports.insightsSchema = insightsSchema;
|
|
|
573
593
|
exports.isFailedCheck = isFailedCheck;
|
|
574
594
|
exports.isLateEvent = isLateEvent;
|
|
575
595
|
exports.isLaunch = isLaunch;
|
|
596
|
+
exports.outcomeRefsOf = outcomeRefsOf;
|
package/dist/server/schema.mjs
CHANGED
|
@@ -37,21 +37,29 @@ const isLaunch = (row) => {
|
|
|
37
37
|
const kinds = metadataOf(row).change?.kinds ?? [];
|
|
38
38
|
return kinds.includes("bundle") && !kinds.includes("first_seen") && row.to_release_id !== null;
|
|
39
39
|
};
|
|
40
|
+
const sideRef = (key, releaseId, bundleId) => key === "release" ? releaseId ?? bundleId : bundleId;
|
|
40
41
|
/**
|
|
41
42
|
* The bundle a stored row's bundle filter matches: `from:<bundle>` for a
|
|
42
43
|
* recovery; `to:<bundle>` for a download, an apply, and an update failure;
|
|
43
44
|
* `on:<bundle>` for an UNCHANGED row that launched a bundle (`isLaunch`), a
|
|
44
45
|
* key no other row uses. None for a failed check, which targets no bundle, a
|
|
45
|
-
* late row, or any other UNCHANGED row.
|
|
46
|
+
* late row, or any other UNCHANGED row. Each names its bundle by `key`.
|
|
46
47
|
*/
|
|
47
|
-
const bundleRefsOf = (row) => {
|
|
48
|
+
const bundleRefsOf = (row, key = "release") => {
|
|
48
49
|
if (isFailedCheck(row) || isLateEvent(row)) return [];
|
|
49
|
-
if (row.type === "RECOVERED") return [`from:${row.from_bundle_id}`];
|
|
50
|
-
if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${row.to_bundle_id}`] : [];
|
|
51
|
-
return [`to:${row.to_bundle_id}`];
|
|
50
|
+
if (row.type === "RECOVERED") return [`from:${sideRef(key, row.from_release_id, row.from_bundle_id)}`];
|
|
51
|
+
if (row.type === "UNCHANGED") return isLaunch(row) ? [`on:${sideRef(key, row.to_release_id, row.to_bundle_id)}`] : [];
|
|
52
|
+
return [`to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`];
|
|
52
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* The hourly outcome rows a stored row counts in, as `[type, bundle ref]`:
|
|
56
|
+
* its bundle filter's (`bundleRefsOf`), and a download that a launch or
|
|
57
|
+
* crash implied, in its bundle's download hour, so the download series
|
|
58
|
+
* covers what the release's downloads count.
|
|
59
|
+
*/
|
|
60
|
+
const outcomeRefsOf = (row, key = "release") => [...bundleRefsOf(row, key).map((ref) => [row.type, ref]), ...metadataOf(row).implied_download === true ? [["UPDATE_DOWNLOADED", row.type === "RECOVERED" ? `to:${sideRef(key, row.from_release_id, row.from_bundle_id)}` : `to:${sideRef(key, row.to_release_id, row.to_bundle_id)}`]] : []];
|
|
53
61
|
/** The key a bundle filter reads, as `bundleRefsOf` writes it. */
|
|
54
|
-
const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.
|
|
62
|
+
const bundleRefOfFilter = (filter) => filter.type === "RECOVERED" ? `from:${filter.fromReleaseId}` : filter.type === "UNCHANGED" ? `on:${filter.toReleaseId}` : `to:${filter.toReleaseId}`;
|
|
55
63
|
/**
|
|
56
64
|
* Downloads, applies, recoveries, update failures, and the UNCHANGED
|
|
57
65
|
* reports that changed what their installation runs, whole. An UNCHANGED
|
|
@@ -116,7 +124,11 @@ const bundleEvents = (days) => defineTable({
|
|
|
116
124
|
type: "string",
|
|
117
125
|
compute: (row) => MOVEMENTS.has(row.type) ? row.install_id : null
|
|
118
126
|
},
|
|
119
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* The bundle a bundle filter matches (`bundleRefsOf`), by release.
|
|
129
|
+
* Rows a 1.1 server wrote name the artifact until
|
|
130
|
+
* `backfillReleaseRefs` rewrites them.
|
|
131
|
+
*/
|
|
120
132
|
bundle_ref: {
|
|
121
133
|
type: "string",
|
|
122
134
|
multi: true,
|
|
@@ -435,7 +447,13 @@ const insightsBuiltinDistribution = (retention) => defineAggregate({
|
|
|
435
447
|
},
|
|
436
448
|
retention
|
|
437
449
|
});
|
|
438
|
-
/**
|
|
450
|
+
/**
|
|
451
|
+
* Latest events by the artifact they came from or went to, bucketed like
|
|
452
|
+
* the distribution, as 1.1 servers wrote them. Nothing writes or reads it
|
|
453
|
+
* since a bundle's installations come from `insights_distribution`, which
|
|
454
|
+
* names the release; it stays declared so retention still empties the rows
|
|
455
|
+
* a 1.1 server wrote.
|
|
456
|
+
*/
|
|
439
457
|
const insightsLatestByBundle = (retention) => defineAggregate({
|
|
440
458
|
platform: {
|
|
441
459
|
type: "string",
|
|
@@ -483,7 +501,9 @@ const insightsLatestByBundle = (retention) => defineAggregate({
|
|
|
483
501
|
* Stored events by outcome and the bundle a bundle filter matches, a row an
|
|
484
502
|
* hour, which a failed check has none of; and every stored event, a row a UTC
|
|
485
503
|
* day (`DAILY_EVENTS`). Bundle counts sum the hourly rows, and event lists
|
|
486
|
-
* read either to skip days without events.
|
|
504
|
+
* read either to skip days without events. `bundle_ref` names the release
|
|
505
|
+
* (`outcomeRefsOf`); a 1.1 server's rows name the artifact until
|
|
506
|
+
* `backfillReleaseRefs` moves their counts.
|
|
487
507
|
*/
|
|
488
508
|
const insightsOutcomes = (retention) => defineAggregate({
|
|
489
509
|
platform: {
|
|
@@ -562,4 +582,4 @@ const createInsightsSchema = ({ rawDays, dailyDays } = DEFAULT_INSIGHTS_RETENTIO
|
|
|
562
582
|
};
|
|
563
583
|
const insightsSchema = createInsightsSchema();
|
|
564
584
|
//#endregion
|
|
565
|
-
export { DAILY_EVENTS, DAY_MS, DEFAULT_INSIGHTS_RETENTION, HOUR_MS, bundleRefOfFilter, bundleRefsOf, createInsightsSchema, insightsSchema, isFailedCheck, isLateEvent, isLaunch };
|
|
585
|
+
export { DAILY_EVENTS, DAY_MS, DEFAULT_INSIGHTS_RETENTION, HOUR_MS, bundleRefOfFilter, bundleRefsOf, createInsightsSchema, insightsSchema, isFailedCheck, isLateEvent, isLaunch, outcomeRefsOf };
|
package/dist/server/types.d.cts
CHANGED
|
@@ -26,7 +26,8 @@ type InsightsProvider = {
|
|
|
26
26
|
pageInstallationsByCurrentUserId(input: InsightsUserInstallationPageInput): Promise<CursorPage<InstallationRow>>;
|
|
27
27
|
getReportingOverview(input: InsightsScope & {
|
|
28
28
|
readonly window: ActiveInstallationWindow;
|
|
29
|
-
|
|
29
|
+
/** The bundle users see, by its release ID. */
|
|
30
|
+
readonly releaseId?: string;
|
|
30
31
|
}): Promise<ReportingOverview>;
|
|
31
32
|
};
|
|
32
33
|
//#endregion
|
package/dist/server/types.d.mts
CHANGED
|
@@ -26,7 +26,8 @@ type InsightsProvider = {
|
|
|
26
26
|
pageInstallationsByCurrentUserId(input: InsightsUserInstallationPageInput): Promise<CursorPage<InstallationRow>>;
|
|
27
27
|
getReportingOverview(input: InsightsScope & {
|
|
28
28
|
readonly window: ActiveInstallationWindow;
|
|
29
|
-
|
|
29
|
+
/** The bundle users see, by its release ID. */
|
|
30
|
+
readonly releaseId?: string;
|
|
30
31
|
}): Promise<ReportingOverview>;
|
|
31
32
|
};
|
|
32
33
|
//#endregion
|