@hot-updater/plugin-insights 1.0.0-rc.20
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/LICENSE +33 -0
- package/README.md +24 -0
- package/client/package.json +7 -0
- package/dist/client/eventId.cjs +181 -0
- package/dist/client/eventId.mjs +179 -0
- package/dist/client/index.cjs +234 -0
- package/dist/client/index.d.cts +42 -0
- package/dist/client/index.d.mts +42 -0
- package/dist/client/index.mjs +233 -0
- package/dist/client/sender.cjs +103 -0
- package/dist/client/sender.mjs +103 -0
- package/dist/client/state.cjs +121 -0
- package/dist/client/state.mjs +119 -0
- package/dist/internal.cjs +9 -0
- package/dist/internal.d.cts +5 -0
- package/dist/internal.d.mts +5 -0
- package/dist/internal.mjs +5 -0
- package/dist/server/contract.cjs +193 -0
- package/dist/server/contract.mjs +189 -0
- package/dist/server/domain.d.cts +149 -0
- package/dist/server/domain.d.mts +149 -0
- package/dist/server/errors.cjs +15 -0
- package/dist/server/errors.d.cts +6 -0
- package/dist/server/errors.d.mts +6 -0
- package/dist/server/errors.mjs +14 -0
- package/dist/server/eventInput.cjs +284 -0
- package/dist/server/eventInput.d.cts +6 -0
- package/dist/server/eventInput.d.mts +6 -0
- package/dist/server/eventInput.mjs +282 -0
- package/dist/server/eventRow.cjs +49 -0
- package/dist/server/eventRow.d.cts +64 -0
- package/dist/server/eventRow.d.mts +64 -0
- package/dist/server/eventRow.mjs +47 -0
- package/dist/server/index.cjs +128 -0
- package/dist/server/index.d.cts +394 -0
- package/dist/server/index.d.mts +394 -0
- package/dist/server/index.mjs +121 -0
- package/dist/server/model.cjs +17 -0
- package/dist/server/model.d.cts +10 -0
- package/dist/server/model.d.mts +10 -0
- package/dist/server/model.mjs +17 -0
- package/dist/server/modelTypes.d.cts +176 -0
- package/dist/server/modelTypes.d.mts +176 -0
- package/dist/server/overview.cjs +109 -0
- package/dist/server/overview.d.cts +15 -0
- package/dist/server/overview.d.mts +15 -0
- package/dist/server/overview.mjs +107 -0
- package/dist/server/provider.cjs +375 -0
- package/dist/server/provider.d.cts +6 -0
- package/dist/server/provider.d.mts +6 -0
- package/dist/server/provider.mjs +374 -0
- package/dist/server/queryInput.cjs +93 -0
- package/dist/server/queryInput.mjs +91 -0
- package/dist/server/reads.cjs +681 -0
- package/dist/server/reads.d.cts +60 -0
- package/dist/server/reads.d.mts +60 -0
- package/dist/server/reads.mjs +674 -0
- package/dist/server/recordEvent.cjs +319 -0
- package/dist/server/recordEvent.d.cts +17 -0
- package/dist/server/recordEvent.d.mts +17 -0
- package/dist/server/recordEvent.mjs +316 -0
- package/dist/server/routes.cjs +96 -0
- package/dist/server/routes.d.cts +36 -0
- package/dist/server/routes.d.mts +36 -0
- package/dist/server/routes.mjs +95 -0
- package/dist/server/schema.cjs +489 -0
- package/dist/server/schema.d.cts +706 -0
- package/dist/server/schema.d.mts +706 -0
- package/dist/server/schema.mjs +483 -0
- package/dist/server/testing/eventRow.d.mts +64 -0
- package/dist/server/testing/expectInsightsIndex.mjs +18 -0
- package/dist/server/testing/fixtures.d.mts +8 -0
- package/dist/server/testing/fixtures.mjs +25 -0
- package/dist/server/testing/index.d.mts +24 -0
- package/dist/server/testing/index.mjs +25 -0
- package/dist/server/testing/insightsModelTests.mjs +714 -0
- package/dist/server/testing/modelTypes.d.mts +176 -0
- package/dist/server/testing/setupInsightsHttpTestSuite.d.mts +11 -0
- package/dist/server/testing/setupInsightsHttpTestSuite.mjs +107 -0
- package/dist/server/testing/setupInsightsModelTestSuite.d.mts +11 -0
- package/dist/server/testing/setupInsightsModelTestSuite.mjs +31 -0
- package/dist/server/testing/types.d.mts +26 -0
- package/dist/server/types.d.cts +33 -0
- package/dist/server/types.d.mts +33 -0
- package/package.json +68 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import { defineAggregate, defineTable } from "@hot-updater/plugin-core/server-plugin";
|
|
2
|
+
//#region src/server/schema.ts
|
|
3
|
+
const HOUR_MS = 36e5;
|
|
4
|
+
const DAY_MS = 864e5;
|
|
5
|
+
const DEFAULT_INSIGHTS_RETENTION = {
|
|
6
|
+
rawDays: 90,
|
|
7
|
+
dailyDays: 400
|
|
8
|
+
};
|
|
9
|
+
const bucketRetention = (days) => ({
|
|
10
|
+
field: "bucket_start_ms",
|
|
11
|
+
days
|
|
12
|
+
});
|
|
13
|
+
const MOVEMENTS = /* @__PURE__ */ new Set([
|
|
14
|
+
"UPDATE_DOWNLOADED",
|
|
15
|
+
"UPDATE_APPLIED",
|
|
16
|
+
"RECOVERED",
|
|
17
|
+
"UPDATE_FAILED"
|
|
18
|
+
]);
|
|
19
|
+
/** A failed update check: it names no target bundle, so no bundle list shows it. */
|
|
20
|
+
const isFailedCheck = (row) => row.type === "UPDATE_FAILED" && row.metadata?.failure?.stage === "check";
|
|
21
|
+
/**
|
|
22
|
+
* Downloads, applies, recoveries, and update failures, whole. An UNCHANGED
|
|
23
|
+
* report counts as a launch and moves its installation's head, but no list
|
|
24
|
+
* shows it, so no row keeps it.
|
|
25
|
+
*/
|
|
26
|
+
const bundleEvents = (days) => defineTable({
|
|
27
|
+
id: {
|
|
28
|
+
type: "string",
|
|
29
|
+
maxLength: 36
|
|
30
|
+
},
|
|
31
|
+
type: {
|
|
32
|
+
type: "string",
|
|
33
|
+
maxLength: 32
|
|
34
|
+
},
|
|
35
|
+
install_id: {
|
|
36
|
+
type: "string",
|
|
37
|
+
maxLength: 255
|
|
38
|
+
},
|
|
39
|
+
user_id: {
|
|
40
|
+
type: "string",
|
|
41
|
+
maxLength: 255,
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
from_release_id: {
|
|
45
|
+
type: "string",
|
|
46
|
+
maxLength: 36,
|
|
47
|
+
required: false
|
|
48
|
+
},
|
|
49
|
+
from_bundle_id: {
|
|
50
|
+
type: "string",
|
|
51
|
+
maxLength: 36,
|
|
52
|
+
required: false
|
|
53
|
+
},
|
|
54
|
+
to_release_id: {
|
|
55
|
+
type: "string",
|
|
56
|
+
maxLength: 36,
|
|
57
|
+
required: false
|
|
58
|
+
},
|
|
59
|
+
to_bundle_id: {
|
|
60
|
+
type: "string",
|
|
61
|
+
maxLength: 36
|
|
62
|
+
},
|
|
63
|
+
platform: {
|
|
64
|
+
type: "string",
|
|
65
|
+
maxLength: 16
|
|
66
|
+
},
|
|
67
|
+
app_version: { type: "string" },
|
|
68
|
+
channel: { type: "string" },
|
|
69
|
+
metadata: { type: "json" },
|
|
70
|
+
received_at_ms: { type: "integer" }
|
|
71
|
+
}, {
|
|
72
|
+
key: ["id"],
|
|
73
|
+
derived: {
|
|
74
|
+
/** The UTC day the event was received in. */
|
|
75
|
+
day: {
|
|
76
|
+
type: "integer",
|
|
77
|
+
compute: (row) => row.received_at_ms - row.received_at_ms % DAY_MS
|
|
78
|
+
},
|
|
79
|
+
/** Set only for events that belong in installation history. */
|
|
80
|
+
movement_install_id: {
|
|
81
|
+
type: "string",
|
|
82
|
+
compute: (row) => MOVEMENTS.has(row.type) ? row.install_id : null
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* The bundle a bundle filter matches: `from:<bundle>` for RECOVERED,
|
|
86
|
+
* none for a failed check, else `to:<bundle>`.
|
|
87
|
+
*/
|
|
88
|
+
bundle_ref: {
|
|
89
|
+
type: "string",
|
|
90
|
+
multi: true,
|
|
91
|
+
compute: (row) => isFailedCheck(row) ? [] : [row.type === "RECOVERED" && row.from_bundle_id !== null ? `from:${row.from_bundle_id}` : `to:${row.to_bundle_id}`]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
indexes: {
|
|
95
|
+
recent: {
|
|
96
|
+
eq: [
|
|
97
|
+
"channel",
|
|
98
|
+
"platform",
|
|
99
|
+
"day"
|
|
100
|
+
],
|
|
101
|
+
sort: ["received_at_ms"]
|
|
102
|
+
},
|
|
103
|
+
movementsByInstall: {
|
|
104
|
+
eq: ["movement_install_id"],
|
|
105
|
+
sort: ["received_at_ms"]
|
|
106
|
+
},
|
|
107
|
+
byBundle: {
|
|
108
|
+
eq: [
|
|
109
|
+
"platform",
|
|
110
|
+
"channel",
|
|
111
|
+
"type",
|
|
112
|
+
"bundle_ref",
|
|
113
|
+
"day"
|
|
114
|
+
],
|
|
115
|
+
sort: ["received_at_ms"]
|
|
116
|
+
},
|
|
117
|
+
/** Events of every scope by day, for the console's unfiltered event list. */
|
|
118
|
+
byDay: {
|
|
119
|
+
eq: ["day"],
|
|
120
|
+
sort: ["received_at_ms"]
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
retention: {
|
|
124
|
+
field: "day",
|
|
125
|
+
days
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
/**
|
|
129
|
+
* Each installation's latest event, whole, so reading it is one point read.
|
|
130
|
+
* Its gauges count it in the UTC day of that event. An update failure moves
|
|
131
|
+
* nothing, so no head holds one.
|
|
132
|
+
*/
|
|
133
|
+
const bundleEventHeads = (days) => defineTable({
|
|
134
|
+
install_id: {
|
|
135
|
+
type: "string",
|
|
136
|
+
maxLength: 255
|
|
137
|
+
},
|
|
138
|
+
id: {
|
|
139
|
+
type: "string",
|
|
140
|
+
maxLength: 36
|
|
141
|
+
},
|
|
142
|
+
type: {
|
|
143
|
+
type: "string",
|
|
144
|
+
maxLength: 32
|
|
145
|
+
},
|
|
146
|
+
user_id: {
|
|
147
|
+
type: "string",
|
|
148
|
+
maxLength: 255,
|
|
149
|
+
required: false
|
|
150
|
+
},
|
|
151
|
+
from_release_id: {
|
|
152
|
+
type: "string",
|
|
153
|
+
maxLength: 36,
|
|
154
|
+
required: false
|
|
155
|
+
},
|
|
156
|
+
from_bundle_id: {
|
|
157
|
+
type: "string",
|
|
158
|
+
maxLength: 36,
|
|
159
|
+
required: false
|
|
160
|
+
},
|
|
161
|
+
to_release_id: {
|
|
162
|
+
type: "string",
|
|
163
|
+
maxLength: 36,
|
|
164
|
+
required: false
|
|
165
|
+
},
|
|
166
|
+
to_bundle_id: {
|
|
167
|
+
type: "string",
|
|
168
|
+
maxLength: 36
|
|
169
|
+
},
|
|
170
|
+
platform: {
|
|
171
|
+
type: "string",
|
|
172
|
+
maxLength: 16
|
|
173
|
+
},
|
|
174
|
+
app_version: { type: "string" },
|
|
175
|
+
channel: { type: "string" },
|
|
176
|
+
metadata: { type: "json" },
|
|
177
|
+
received_at_ms: { type: "integer" }
|
|
178
|
+
}, {
|
|
179
|
+
key: ["install_id"],
|
|
180
|
+
indexes: { byUser: {
|
|
181
|
+
eq: ["user_id"],
|
|
182
|
+
sort: ["install_id"]
|
|
183
|
+
} },
|
|
184
|
+
retention: {
|
|
185
|
+
field: "received_at_ms",
|
|
186
|
+
days
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
/**
|
|
190
|
+
* Shards are keyed by install id. Counters are blind increments and never
|
|
191
|
+
* conflict, so they keep 8. Gauges and sketches are read, merged, and written
|
|
192
|
+
* back. B3's rollout gate on PostgreSQL retried 2.4% of transactions at 8
|
|
193
|
+
* shards and 1.3% at 16. DynamoDB's transactions take longer, so D8's gate
|
|
194
|
+
* on DynamoDB Local retried 2–24% at 16, almost all on gauge rows, and 1–5%
|
|
195
|
+
* with gauges at 32. Sketches stay at 16: each shard row carries 2 KB of
|
|
196
|
+
* registers that every read merges.
|
|
197
|
+
*
|
|
198
|
+
* Every Insights aggregate is `batched`: on DynamoDB and Firestore, which
|
|
199
|
+
* bill each write, an event's changes apply after it commits, merged with
|
|
200
|
+
* other events' into one write per row, on one shard per writer.
|
|
201
|
+
*/
|
|
202
|
+
const COUNTER_SHARDS = 8;
|
|
203
|
+
const GAUGE_SHARDS = 32;
|
|
204
|
+
const SKETCH_SHARDS = 16;
|
|
205
|
+
/** Rows keyed by a hashed identity (scope and period) and a bucket. */
|
|
206
|
+
const identityFields = {
|
|
207
|
+
identity: {
|
|
208
|
+
type: "string",
|
|
209
|
+
maxLength: 32
|
|
210
|
+
},
|
|
211
|
+
bucket_start_ms: { type: "integer" }
|
|
212
|
+
};
|
|
213
|
+
const window = {
|
|
214
|
+
eq: ["identity"],
|
|
215
|
+
sort: ["bucket_start_ms"]
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Counters of one period kind: hourly, daily, or lifetime at bucket 0. A
|
|
219
|
+
* release or channel row counts downloads, launches, and failed launches,
|
|
220
|
+
* and downloads a patch delivered and those that fell back from one. A
|
|
221
|
+
* release's lifetime row counts its failed updates (`failed_updates`), since
|
|
222
|
+
* no breakdown row outlives the raw period; windowed reads sum
|
|
223
|
+
* `insights_failures` instead.
|
|
224
|
+
*/
|
|
225
|
+
const counters = (retention) => defineAggregate(identityFields, {
|
|
226
|
+
key: ["identity", "bucket_start_ms"],
|
|
227
|
+
counters: [
|
|
228
|
+
"downloads",
|
|
229
|
+
"launches",
|
|
230
|
+
"failed_launches",
|
|
231
|
+
"failed_updates",
|
|
232
|
+
"patch_downloads",
|
|
233
|
+
"patch_fallbacks"
|
|
234
|
+
],
|
|
235
|
+
shards: COUNTER_SHARDS,
|
|
236
|
+
batched: true,
|
|
237
|
+
indexes: { window },
|
|
238
|
+
...retention === void 0 ? {} : { retention }
|
|
239
|
+
});
|
|
240
|
+
/**
|
|
241
|
+
* Unique-installation sketches of one period kind. Rows of a failure
|
|
242
|
+
* identity (`failure` and `check` scopes) keep only `failed_users`, so a
|
|
243
|
+
* release's launch rows never grow by a failure's registers.
|
|
244
|
+
*/
|
|
245
|
+
const sketches = (retention) => defineAggregate(identityFields, {
|
|
246
|
+
key: ["identity", "bucket_start_ms"],
|
|
247
|
+
distinct: [
|
|
248
|
+
"launch_users",
|
|
249
|
+
"activity_users",
|
|
250
|
+
"failed_users"
|
|
251
|
+
],
|
|
252
|
+
shards: SKETCH_SHARDS,
|
|
253
|
+
batched: true,
|
|
254
|
+
indexes: { window },
|
|
255
|
+
retention
|
|
256
|
+
});
|
|
257
|
+
/** Installations whose update to a release failed, since its first failure: kept, at bucket 0. */
|
|
258
|
+
const lifetimeSketches = () => defineAggregate(identityFields, {
|
|
259
|
+
key: ["identity", "bucket_start_ms"],
|
|
260
|
+
distinct: ["failed_users"],
|
|
261
|
+
shards: SKETCH_SHARDS,
|
|
262
|
+
batched: true,
|
|
263
|
+
indexes: { window }
|
|
264
|
+
});
|
|
265
|
+
/**
|
|
266
|
+
* Update failures by what failed, and recoveries by why the crashed process
|
|
267
|
+
* exited, a row an hour. `release_id` is the failed update's target release,
|
|
268
|
+
* or empty for a failed check or an unknown target, and the recovered
|
|
269
|
+
* release for a recovery. A failure's `stage` and `reason` say where and why
|
|
270
|
+
* it failed, and `detail` what else the client knew, as the JSON array
|
|
271
|
+
* `[resource, httpStatus, originCode, transport]`. A recovery's stage is
|
|
272
|
+
* `launch` and its reason the exit reason, with an empty detail. Every index
|
|
273
|
+
* is in key order, so its counters stay blind increments.
|
|
274
|
+
*/
|
|
275
|
+
const insightsFailures = (retention) => defineAggregate({
|
|
276
|
+
platform: {
|
|
277
|
+
type: "string",
|
|
278
|
+
maxLength: 16
|
|
279
|
+
},
|
|
280
|
+
channel: { type: "string" },
|
|
281
|
+
bucket_start_ms: { type: "integer" },
|
|
282
|
+
release_id: {
|
|
283
|
+
type: "string",
|
|
284
|
+
maxLength: 36
|
|
285
|
+
},
|
|
286
|
+
stage: {
|
|
287
|
+
type: "string",
|
|
288
|
+
maxLength: 16
|
|
289
|
+
},
|
|
290
|
+
reason: {
|
|
291
|
+
type: "string",
|
|
292
|
+
maxLength: 64
|
|
293
|
+
},
|
|
294
|
+
detail: {
|
|
295
|
+
type: "string",
|
|
296
|
+
maxLength: 160
|
|
297
|
+
}
|
|
298
|
+
}, {
|
|
299
|
+
key: [
|
|
300
|
+
"platform",
|
|
301
|
+
"channel",
|
|
302
|
+
"bucket_start_ms",
|
|
303
|
+
"release_id",
|
|
304
|
+
"stage",
|
|
305
|
+
"reason",
|
|
306
|
+
"detail"
|
|
307
|
+
],
|
|
308
|
+
counters: ["events"],
|
|
309
|
+
shards: COUNTER_SHARDS,
|
|
310
|
+
batched: true,
|
|
311
|
+
indexes: { byScope: {
|
|
312
|
+
eq: ["platform", "channel"],
|
|
313
|
+
sort: ["bucket_start_ms"]
|
|
314
|
+
} },
|
|
315
|
+
retention
|
|
316
|
+
});
|
|
317
|
+
/** Installations counted in the UTC day of their latest event, so reads sum whole UTC days. */
|
|
318
|
+
const insightsDistribution = (retention) => defineAggregate({
|
|
319
|
+
channel: { type: "string" },
|
|
320
|
+
platform: {
|
|
321
|
+
type: "string",
|
|
322
|
+
maxLength: 16
|
|
323
|
+
},
|
|
324
|
+
app_version: { type: "string" },
|
|
325
|
+
release_id: {
|
|
326
|
+
type: "string",
|
|
327
|
+
maxLength: 36
|
|
328
|
+
},
|
|
329
|
+
bucket_start_ms: { type: "integer" }
|
|
330
|
+
}, {
|
|
331
|
+
key: [
|
|
332
|
+
"channel",
|
|
333
|
+
"platform",
|
|
334
|
+
"app_version",
|
|
335
|
+
"release_id",
|
|
336
|
+
"bucket_start_ms"
|
|
337
|
+
],
|
|
338
|
+
gauges: ["latest_installations"],
|
|
339
|
+
shards: GAUGE_SHARDS,
|
|
340
|
+
batched: true,
|
|
341
|
+
indexes: {
|
|
342
|
+
byScope: {
|
|
343
|
+
eq: ["channel", "platform"],
|
|
344
|
+
sort: ["bucket_start_ms"]
|
|
345
|
+
},
|
|
346
|
+
byVersion: {
|
|
347
|
+
eq: [
|
|
348
|
+
"channel",
|
|
349
|
+
"platform",
|
|
350
|
+
"app_version"
|
|
351
|
+
],
|
|
352
|
+
sort: ["bucket_start_ms"]
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
retention
|
|
356
|
+
});
|
|
357
|
+
/** Latest events by the bundle they came from or went to, bucketed like the distribution. */
|
|
358
|
+
const insightsLatestByBundle = (retention) => defineAggregate({
|
|
359
|
+
platform: {
|
|
360
|
+
type: "string",
|
|
361
|
+
maxLength: 16
|
|
362
|
+
},
|
|
363
|
+
channel: { type: "string" },
|
|
364
|
+
bundle_field: {
|
|
365
|
+
type: "string",
|
|
366
|
+
maxLength: 16
|
|
367
|
+
},
|
|
368
|
+
bundle_id: {
|
|
369
|
+
type: "string",
|
|
370
|
+
maxLength: 36
|
|
371
|
+
},
|
|
372
|
+
type: {
|
|
373
|
+
type: "string",
|
|
374
|
+
maxLength: 32
|
|
375
|
+
},
|
|
376
|
+
bucket_start_ms: { type: "integer" }
|
|
377
|
+
}, {
|
|
378
|
+
key: [
|
|
379
|
+
"platform",
|
|
380
|
+
"channel",
|
|
381
|
+
"bundle_field",
|
|
382
|
+
"bundle_id",
|
|
383
|
+
"type",
|
|
384
|
+
"bucket_start_ms"
|
|
385
|
+
],
|
|
386
|
+
gauges: ["installations"],
|
|
387
|
+
shards: GAUGE_SHARDS,
|
|
388
|
+
batched: true,
|
|
389
|
+
indexes: { byBundle: {
|
|
390
|
+
eq: [
|
|
391
|
+
"platform",
|
|
392
|
+
"channel",
|
|
393
|
+
"bundle_field",
|
|
394
|
+
"bundle_id",
|
|
395
|
+
"type"
|
|
396
|
+
],
|
|
397
|
+
sort: ["bucket_start_ms"]
|
|
398
|
+
} },
|
|
399
|
+
retention
|
|
400
|
+
});
|
|
401
|
+
/**
|
|
402
|
+
* Stored events by outcome and the bundle a bundle filter matches, a row an
|
|
403
|
+
* hour, which a failed check has none of; and every stored event, a row a UTC
|
|
404
|
+
* day (`DAILY_EVENTS`). Bundle counts sum the hourly rows, and event lists
|
|
405
|
+
* read either to skip days without events.
|
|
406
|
+
*/
|
|
407
|
+
const insightsOutcomes = (retention) => defineAggregate({
|
|
408
|
+
platform: {
|
|
409
|
+
type: "string",
|
|
410
|
+
maxLength: 16
|
|
411
|
+
},
|
|
412
|
+
channel: { type: "string" },
|
|
413
|
+
type: {
|
|
414
|
+
type: "string",
|
|
415
|
+
maxLength: 32
|
|
416
|
+
},
|
|
417
|
+
bundle_ref: {
|
|
418
|
+
type: "string",
|
|
419
|
+
maxLength: 41
|
|
420
|
+
},
|
|
421
|
+
bucket_start_ms: { type: "integer" }
|
|
422
|
+
}, {
|
|
423
|
+
key: [
|
|
424
|
+
"platform",
|
|
425
|
+
"channel",
|
|
426
|
+
"type",
|
|
427
|
+
"bundle_ref",
|
|
428
|
+
"bucket_start_ms"
|
|
429
|
+
],
|
|
430
|
+
counters: ["events"],
|
|
431
|
+
shards: COUNTER_SHARDS,
|
|
432
|
+
batched: true,
|
|
433
|
+
indexes: { byRef: {
|
|
434
|
+
eq: [
|
|
435
|
+
"platform",
|
|
436
|
+
"channel",
|
|
437
|
+
"type",
|
|
438
|
+
"bundle_ref"
|
|
439
|
+
],
|
|
440
|
+
sort: ["bucket_start_ms"]
|
|
441
|
+
} },
|
|
442
|
+
retention
|
|
443
|
+
});
|
|
444
|
+
/**
|
|
445
|
+
* The `insights_outcomes` identity that counts every stored event, for the
|
|
446
|
+
* global event list. Its bucket is a UTC day, not an hour. Every event's
|
|
447
|
+
* platform is ios or android, so no outcome row of a bundle filter shares it.
|
|
448
|
+
*/
|
|
449
|
+
const DAILY_EVENTS = {
|
|
450
|
+
platform: "*",
|
|
451
|
+
channel: "",
|
|
452
|
+
type: "",
|
|
453
|
+
bundle_ref: ""
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Insights' tables, each expiring after its period. The periods are values
|
|
457
|
+
* the engine applies at runtime; the tables and indexes are the same for
|
|
458
|
+
* any periods.
|
|
459
|
+
*/
|
|
460
|
+
const createInsightsSchema = ({ rawDays, dailyDays } = DEFAULT_INSIGHTS_RETENTION) => {
|
|
461
|
+
const hourly = bucketRetention(rawDays);
|
|
462
|
+
const daily = bucketRetention(dailyDays);
|
|
463
|
+
return {
|
|
464
|
+
bundle_events: bundleEvents(rawDays),
|
|
465
|
+
bundle_event_heads: bundleEventHeads(dailyDays),
|
|
466
|
+
/** Hourly counters and sketches: the raw period. */
|
|
467
|
+
insights_overview: counters(hourly),
|
|
468
|
+
insights_sketches: sketches(hourly),
|
|
469
|
+
/** Daily counters and sketches: the daily period. */
|
|
470
|
+
insights_overview_daily: counters(daily),
|
|
471
|
+
insights_sketches_daily: sketches(daily),
|
|
472
|
+
/** A release's counters since its first event, and its failed installations: kept. */
|
|
473
|
+
insights_overview_lifetime: counters(),
|
|
474
|
+
insights_sketches_lifetime: lifetimeSketches(),
|
|
475
|
+
insights_distribution: insightsDistribution(daily),
|
|
476
|
+
insights_latest_by_bundle: insightsLatestByBundle(daily),
|
|
477
|
+
insights_outcomes: insightsOutcomes(hourly),
|
|
478
|
+
insights_failures: insightsFailures(hourly)
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
const insightsSchema = createInsightsSchema();
|
|
482
|
+
//#endregion
|
|
483
|
+
export { DAILY_EVENTS, DAY_MS, DEFAULT_INSIGHTS_RETENTION, HOUR_MS, createInsightsSchema, insightsSchema, isFailedCheck };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DatabaseJsonObject, Platform } from "@hot-updater/plugin-core";
|
|
2
|
+
//#region src/server/eventRow.d.ts
|
|
3
|
+
/** Where an update failed, and what failed; open sets, `unknown` for any other value. */
|
|
4
|
+
type BundleEventFailureStage = "check" | "download" | "install" | "unknown";
|
|
5
|
+
type BundleEventFailureReason = "network" | "http" | "invalid_response" | "hash_mismatch" | "signature" | "patch" | "extract" | "storage" | "unknown";
|
|
6
|
+
/** An `UPDATE_FAILED` report's failure, as stored. */
|
|
7
|
+
type BundleEventFailure = DatabaseJsonObject & {
|
|
8
|
+
readonly stage: BundleEventFailureStage;
|
|
9
|
+
readonly reason: BundleEventFailureReason;
|
|
10
|
+
/** What the client was fetching or writing. */
|
|
11
|
+
readonly resource?: "catalog" | "artifact" | "manifest" | "file" | "patch" | "archive" | "unknown";
|
|
12
|
+
readonly http_status?: number;
|
|
13
|
+
/** How the connection failed, when it did. */
|
|
14
|
+
readonly transport?: "timeout" | "dns" | "tls" | "connection" | "offline" | "cancelled" | "unknown";
|
|
15
|
+
/** The storage origin's error code, such as `ExpiredToken`. */
|
|
16
|
+
readonly origin_code?: string;
|
|
17
|
+
/** Android's `ApplicationExitInfo` reason for the process before this one. */
|
|
18
|
+
readonly previous_process_exit?: string;
|
|
19
|
+
};
|
|
20
|
+
/** Ancillary report data; queryable identity and lifecycle fields stay on the row. */
|
|
21
|
+
type DatabaseBundleEventMetadata = DatabaseJsonObject & {
|
|
22
|
+
readonly cohort: string;
|
|
23
|
+
readonly update_strategy: "fingerprint" | "appVersion" | null;
|
|
24
|
+
readonly fingerprint_hash: string | null;
|
|
25
|
+
readonly sdk_version: string | null;
|
|
26
|
+
/** `UPDATE_FAILED`: what failed. */
|
|
27
|
+
readonly failure?: BundleEventFailure;
|
|
28
|
+
/** `UPDATE_DOWNLOADED`: how the bundle arrived. */
|
|
29
|
+
readonly delivery?: "patch" | "manifest" | "archive" | "unknown";
|
|
30
|
+
/** `UPDATE_DOWNLOADED`: a patch failed and the full files came instead. */
|
|
31
|
+
readonly patch_fallback?: boolean;
|
|
32
|
+
/** `RECOVERED`: Android's `ApplicationExitInfo` reason for the crashed process. */
|
|
33
|
+
readonly previous_process_exit?: string;
|
|
34
|
+
};
|
|
35
|
+
type BundleEventRowBase = {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly install_id: string;
|
|
38
|
+
readonly user_id: string | null;
|
|
39
|
+
readonly from_release_id: string | null;
|
|
40
|
+
readonly to_release_id: string | null;
|
|
41
|
+
readonly to_bundle_id: string;
|
|
42
|
+
readonly platform: Platform;
|
|
43
|
+
readonly app_version: string;
|
|
44
|
+
readonly channel: string;
|
|
45
|
+
readonly metadata: DatabaseBundleEventMetadata;
|
|
46
|
+
readonly received_at_ms: number;
|
|
47
|
+
};
|
|
48
|
+
type BundleEventRow = BundleEventRowBase & ({
|
|
49
|
+
readonly type: "UPDATE_DOWNLOADED";
|
|
50
|
+
readonly from_bundle_id: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "UPDATE_APPLIED" | "RECOVERED";
|
|
53
|
+
readonly from_bundle_id: string;
|
|
54
|
+
} |
|
|
55
|
+
/** An update that failed: `from` is the running bundle, `to` the target (for a check, the running bundle). */
|
|
56
|
+
{
|
|
57
|
+
readonly type: "UPDATE_FAILED";
|
|
58
|
+
readonly from_bundle_id: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: "UNCHANGED";
|
|
61
|
+
readonly from_bundle_id: null;
|
|
62
|
+
});
|
|
63
|
+
//#endregion
|
|
64
|
+
export { BundleEventFailure, BundleEventFailureReason, BundleEventFailureStage, BundleEventRow, BundleEventRowBase, DatabaseBundleEventMetadata };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { expect } from "vitest";
|
|
2
|
+
//#region src/server/testing/expectInsightsIndex.ts
|
|
3
|
+
/** Allow committed secondary indexes to catch up; query failures still fail. */
|
|
4
|
+
const expectInsightsIndex = async (query, expected) => {
|
|
5
|
+
const deadline = Date.now() + 5e3;
|
|
6
|
+
for (;;) {
|
|
7
|
+
const actual = await query();
|
|
8
|
+
try {
|
|
9
|
+
expect(actual).toEqual(expected);
|
|
10
|
+
return;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (Date.now() >= deadline) throw error;
|
|
13
|
+
}
|
|
14
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { expectInsightsIndex };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BundleEventRow } from "./eventRow.mjs";
|
|
2
|
+
//#region src/server/testing/fixtures.d.ts
|
|
3
|
+
/** An applied update from install `suffix`, received at `receivedAtMs`. */
|
|
4
|
+
declare const createBundleEventRowFixture: (suffix: string, receivedAtMs: number) => Extract<BundleEventRow, {
|
|
5
|
+
type: "UPDATE_APPLIED" | "RECOVERED";
|
|
6
|
+
}>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createBundleEventRowFixture };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/server/testing/fixtures.ts
|
|
2
|
+
const fixtureId = (suffix) => `00000000-0000-7000-8000-${suffix.padStart(12, "0")}`;
|
|
3
|
+
/** An applied update from install `suffix`, received at `receivedAtMs`. */
|
|
4
|
+
const createBundleEventRowFixture = (suffix, receivedAtMs) => ({
|
|
5
|
+
id: fixtureId(suffix),
|
|
6
|
+
type: "UPDATE_APPLIED",
|
|
7
|
+
install_id: `install-${suffix}`,
|
|
8
|
+
user_id: null,
|
|
9
|
+
metadata: {
|
|
10
|
+
cohort: "0",
|
|
11
|
+
update_strategy: "appVersion",
|
|
12
|
+
fingerprint_hash: null,
|
|
13
|
+
sdk_version: null
|
|
14
|
+
},
|
|
15
|
+
from_bundle_id: fixtureId(`${Number(suffix) + 1e3}`),
|
|
16
|
+
from_release_id: null,
|
|
17
|
+
to_bundle_id: fixtureId(`${Number(suffix) + 2e3}`),
|
|
18
|
+
to_release_id: null,
|
|
19
|
+
platform: "ios",
|
|
20
|
+
app_version: "1.0.0",
|
|
21
|
+
channel: "production",
|
|
22
|
+
received_at_ms: receivedAtMs
|
|
23
|
+
});
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createBundleEventRowFixture };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InsightsModel } from "./modelTypes.mjs";
|
|
2
|
+
import { DatabaseTestLifecycle, DatabaseTestState, HttpTestClient, HttpTestRequest } from "./types.mjs";
|
|
3
|
+
import { createBundleEventRowFixture } from "./fixtures.mjs";
|
|
4
|
+
import { setupInsightsHttpTestSuite } from "./setupInsightsHttpTestSuite.mjs";
|
|
5
|
+
import { setupInsightsModelTestSuite } from "./setupInsightsModelTestSuite.mjs";
|
|
6
|
+
//#region src/server/testing/index.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The Insights plugin's tests, for `setupDatabaseTestSuite`'s `plugins`: its
|
|
9
|
+
* HTTP routes on the provider's server, which must run `insights()`, and
|
|
10
|
+
* with `createModel` its report contract on the provider's database, such as
|
|
11
|
+
* `(database) => createInsightsModel(createDatabasePluginApis(database,
|
|
12
|
+
* [insights()]).insights)`.
|
|
13
|
+
*/
|
|
14
|
+
declare const insightsTestSuite: <TDatabase = unknown>(options?: {
|
|
15
|
+
readonly createModel?: (database: TDatabase) => InsightsModel;
|
|
16
|
+
}) => {
|
|
17
|
+
name: string;
|
|
18
|
+
register: (context: {
|
|
19
|
+
readonly getClient: () => HttpTestClient;
|
|
20
|
+
readonly getDatabase: () => TDatabase;
|
|
21
|
+
}) => void;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { type DatabaseTestLifecycle, type DatabaseTestState, type HttpTestClient, type HttpTestRequest, createBundleEventRowFixture, insightsTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createBundleEventRowFixture } from "./fixtures.mjs";
|
|
2
|
+
import { registerInsightsModelTests } from "./insightsModelTests.mjs";
|
|
3
|
+
import { setupInsightsHttpTestSuite } from "./setupInsightsHttpTestSuite.mjs";
|
|
4
|
+
import { setupInsightsModelTestSuite } from "./setupInsightsModelTestSuite.mjs";
|
|
5
|
+
import { describe } from "vitest";
|
|
6
|
+
//#region src/server/testing/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* The Insights plugin's tests, for `setupDatabaseTestSuite`'s `plugins`: its
|
|
9
|
+
* HTTP routes on the provider's server, which must run `insights()`, and
|
|
10
|
+
* with `createModel` its report contract on the provider's database, such as
|
|
11
|
+
* `(database) => createInsightsModel(createDatabasePluginApis(database,
|
|
12
|
+
* [insights()]).insights)`.
|
|
13
|
+
*/
|
|
14
|
+
const insightsTestSuite = (options = {}) => ({
|
|
15
|
+
name: "Insights plugin",
|
|
16
|
+
register: (context) => {
|
|
17
|
+
setupInsightsHttpTestSuite({ getClient: context.getClient });
|
|
18
|
+
const { createModel } = options;
|
|
19
|
+
if (createModel !== void 0) describe("Insights model", () => {
|
|
20
|
+
registerInsightsModelTests({ getDatabase: () => createModel(context.getDatabase()) });
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createBundleEventRowFixture, insightsTestSuite, setupInsightsHttpTestSuite, setupInsightsModelTestSuite };
|