@hot-updater/server 1.0.0-rc.16 → 1.0.0-rc.18
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/adapters/drizzle.cjs +5 -5
- package/dist/adapters/drizzle.mjs +4 -4
- package/dist/adapters/kysely.cjs +3 -3
- package/dist/adapters/kysely.mjs +2 -2
- package/dist/adapters/mongodb.cjs +3 -3
- package/dist/adapters/mongodb.mjs +2 -2
- package/dist/adapters/mongodbAdapter.cjs +19 -1
- package/dist/adapters/mongodbAdapter.mjs +19 -1
- package/dist/adapters/prisma.cjs +5 -5
- package/dist/adapters/prisma.mjs +4 -4
- package/dist/assembly/assemblePlugins.cjs +47 -28
- package/dist/assembly/assemblePlugins.d.cts +3 -7
- package/dist/assembly/assemblePlugins.d.mts +3 -7
- package/dist/assembly/assemblePlugins.mjs +46 -27
- package/dist/assembly/clientPlugins.cjs +86 -0
- package/dist/assembly/clientPlugins.d.cts +16 -0
- package/dist/assembly/clientPlugins.d.mts +16 -0
- package/dist/assembly/clientPlugins.mjs +86 -0
- package/dist/assembly/configError.cjs +7 -0
- package/dist/assembly/configError.d.cts +7 -0
- package/dist/assembly/configError.d.mts +7 -0
- package/dist/assembly/configError.mjs +7 -0
- package/dist/assembly/databasePlugins.cjs +5 -1
- package/dist/assembly/databasePlugins.d.cts +5 -5
- package/dist/assembly/databasePlugins.d.mts +5 -5
- package/dist/assembly/databasePlugins.mjs +5 -1
- package/dist/assembly/pluginCli.cjs +125 -0
- package/dist/assembly/pluginCli.d.cts +59 -0
- package/dist/assembly/pluginCli.d.mts +59 -0
- package/dist/assembly/pluginCli.mjs +121 -0
- package/dist/createHotUpdaterCore.cjs +14 -16
- package/dist/createHotUpdaterCore.d.cts +10 -3
- package/dist/createHotUpdaterCore.d.mts +10 -3
- package/dist/createHotUpdaterCore.mjs +11 -13
- package/dist/database/aggregateBatching.cjs +626 -0
- package/dist/database/aggregateBatching.d.cts +10 -0
- package/dist/database/aggregateBatching.d.mts +10 -0
- package/dist/database/aggregateBatching.mjs +625 -0
- package/dist/{insights/errors.cjs → database/busy.cjs} +2 -15
- package/dist/database/busy.d.cts +12 -0
- package/dist/database/busy.d.mts +12 -0
- package/dist/{insights/errors.mjs → database/busy.mjs} +3 -14
- package/dist/database/database.cjs +22 -3
- package/dist/database/database.d.cts +15 -2
- package/dist/database/database.d.mts +15 -2
- package/dist/database/database.mjs +22 -3
- package/dist/database/definitions.d.cts +10 -0
- package/dist/database/definitions.d.mts +10 -0
- package/dist/database/engine.d.cts +2 -1
- package/dist/database/engine.d.mts +2 -1
- package/dist/database/engineAggregates.cjs +7 -4
- package/dist/database/engineAggregates.mjs +8 -5
- package/dist/database/engineReads.cjs +5 -3
- package/dist/database/engineReads.mjs +6 -4
- package/dist/database/engineTransaction.cjs +2 -6
- package/dist/database/engineTransaction.mjs +2 -6
- package/dist/database/fence.cjs +2 -1
- package/dist/database/fence.mjs +2 -1
- package/dist/database/index.cjs +17 -8
- package/dist/database/index.d.cts +5 -4
- package/dist/database/index.d.mts +5 -4
- package/dist/database/index.mjs +6 -5
- package/dist/database/kv/kvAdapter.cjs +15 -3
- package/dist/database/kv/kvAdapter.d.cts +8 -0
- package/dist/database/kv/kvAdapter.d.mts +8 -0
- package/dist/database/kv/kvAdapter.mjs +16 -4
- package/dist/database/resolveSchema.cjs +4 -1
- package/dist/database/resolveSchema.d.cts +1 -1
- package/dist/database/resolveSchema.d.mts +1 -1
- package/dist/database/resolveSchema.mjs +4 -1
- package/dist/database/retention.cjs +92 -0
- package/dist/database/retention.mjs +90 -0
- package/dist/database/schema.cjs +5 -2
- package/dist/database/schema.d.cts +30 -1
- package/dist/database/schema.d.mts +30 -1
- package/dist/database/schema.mjs +5 -2
- package/dist/database/sql/sqlAdapter.cjs +8 -0
- package/dist/database/sql/sqlAdapter.mjs +9 -1
- package/dist/database/sql/sqlSchema.cjs +56 -0
- package/dist/database/sql/sqlSchema.mjs +55 -1
- package/dist/db/coreDatabase.cjs +85 -0
- package/dist/db/coreDatabase.d.cts +57 -0
- package/dist/db/coreDatabase.d.mts +57 -0
- package/dist/db/coreDatabase.mjs +78 -0
- package/dist/db/index.cjs +11 -3
- package/dist/db/index.d.cts +7 -3
- package/dist/db/index.d.mts +7 -3
- package/dist/db/index.mjs +6 -3
- package/dist/db/types.d.cts +3 -3
- package/dist/db/types.d.mts +3 -3
- package/dist/diff.cjs +3 -0
- package/dist/diff.d.cts +2 -0
- package/dist/diff.d.mts +2 -0
- package/dist/diff.mjs +2 -0
- package/dist/handler.cjs +2 -14
- package/dist/handler.mjs +1 -13
- package/dist/handlerReleaseCatalogRoutes.cjs +21 -2
- package/dist/handlerReleaseCatalogRoutes.mjs +21 -2
- package/dist/index.cjs +2 -6
- package/dist/index.d.cts +4 -7
- package/dist/index.d.mts +4 -7
- package/dist/index.mjs +2 -4
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/{apiKeys.cjs → plugins/api-keys/apiKeys.cjs} +1 -1
- package/dist/{apiKeys.d.cts → plugins/api-keys/apiKeys.d.cts} +2 -2
- package/dist/{apiKeys.d.mts → plugins/api-keys/apiKeys.d.mts} +2 -2
- package/dist/{apiKeys.mjs → plugins/api-keys/apiKeys.mjs} +1 -1
- package/dist/plugins/api-keys/cli.cjs +115 -0
- package/dist/plugins/api-keys/cli.mjs +114 -0
- package/dist/plugins/api-keys/index.cjs +9 -6
- package/dist/plugins/api-keys/index.d.cts +4 -5
- package/dist/plugins/api-keys/index.d.mts +4 -5
- package/dist/plugins/api-keys/index.mjs +9 -7
- package/dist/plugins/api-keys/model.d.cts +20 -2
- package/dist/plugins/api-keys/model.d.mts +20 -2
- package/dist/plugins/definePlugin.cjs +1 -1
- package/dist/plugins/definePlugin.d.cts +130 -3
- package/dist/plugins/definePlugin.d.mts +130 -3
- package/dist/plugins/definePlugin.mjs +1 -1
- package/dist/plugins/index.cjs +25 -4
- package/dist/plugins/index.d.cts +7 -4
- package/dist/plugins/index.d.mts +7 -4
- package/dist/plugins/index.mjs +6 -4
- package/dist/plugins/insights/contract.cjs +193 -0
- package/dist/plugins/insights/contract.mjs +189 -0
- package/dist/{insights → plugins/insights}/domain.d.cts +60 -15
- package/dist/{insights → plugins/insights}/domain.d.mts +60 -15
- package/dist/plugins/insights/errors.cjs +15 -0
- package/dist/plugins/insights/errors.mjs +14 -0
- package/dist/{insights → plugins/insights}/eventInput.cjs +155 -22
- package/dist/{insights → plugins/insights}/eventInput.mjs +155 -22
- package/dist/plugins/insights/eventRow.cjs +49 -0
- package/dist/plugins/insights/eventRow.d.cts +64 -0
- package/dist/plugins/insights/eventRow.d.mts +64 -0
- package/dist/plugins/insights/eventRow.mjs +47 -0
- package/dist/plugins/insights/index.cjs +106 -26
- package/dist/plugins/insights/index.d.cts +130 -27
- package/dist/plugins/insights/index.d.mts +130 -27
- package/dist/plugins/insights/index.mjs +106 -29
- package/dist/plugins/insights/model.cjs +2 -2
- package/dist/plugins/insights/model.d.cts +1 -1
- package/dist/plugins/insights/model.d.mts +1 -1
- package/dist/plugins/insights/model.mjs +1 -1
- package/dist/plugins/insights/modelTypes.d.cts +176 -0
- package/dist/plugins/insights/modelTypes.d.mts +176 -0
- package/dist/plugins/insights/overview.cjs +109 -0
- package/dist/plugins/insights/overview.d.cts +15 -0
- package/dist/plugins/insights/overview.d.mts +15 -0
- package/dist/plugins/insights/overview.mjs +107 -0
- package/dist/{insights → plugins/insights}/provider.cjs +33 -14
- package/dist/{insights → plugins/insights}/provider.d.cts +2 -2
- package/dist/{insights → plugins/insights}/provider.d.mts +2 -2
- package/dist/{insights → plugins/insights}/provider.mjs +30 -11
- package/dist/{insights → plugins/insights}/queryInput.cjs +2 -2
- package/dist/{insights → plugins/insights}/queryInput.mjs +2 -2
- package/dist/plugins/insights/reads.cjs +298 -88
- package/dist/plugins/insights/reads.d.cts +61 -0
- package/dist/plugins/insights/reads.d.mts +61 -0
- package/dist/plugins/insights/reads.mjs +298 -90
- package/dist/plugins/insights/recordEvent.cjs +223 -39
- package/dist/plugins/insights/recordEvent.d.cts +9 -4
- package/dist/plugins/insights/recordEvent.d.mts +9 -4
- package/dist/plugins/insights/recordEvent.mjs +221 -37
- package/dist/{insights → plugins/insights}/routes.cjs +3 -30
- package/dist/{insights → plugins/insights}/routes.mjs +4 -28
- package/dist/plugins/insights/schema.cjs +182 -40
- package/dist/plugins/insights/schema.d.cts +446 -6
- package/dist/plugins/insights/schema.d.mts +446 -6
- package/dist/plugins/insights/schema.mjs +180 -41
- package/dist/plugins/insights/testing/eventRow.d.mts +64 -0
- package/dist/plugins/insights/testing/expectInsightsIndex.mjs +18 -0
- package/dist/plugins/insights/testing/fixtures.d.mts +8 -0
- package/dist/plugins/insights/testing/fixtures.mjs +25 -0
- package/dist/plugins/insights/testing/index.d.mts +24 -0
- package/dist/plugins/insights/testing/index.mjs +25 -0
- package/dist/plugins/insights/testing/insightsModelTests.mjs +714 -0
- package/dist/plugins/insights/testing/modelTypes.d.mts +176 -0
- package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.d.mts +11 -0
- package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.mjs +107 -0
- package/dist/plugins/insights/testing/setupInsightsModelTestSuite.d.mts +11 -0
- package/dist/plugins/insights/testing/setupInsightsModelTestSuite.mjs +31 -0
- package/dist/plugins/insights/testing/types.d.mts +26 -0
- package/dist/{insights → plugins/insights}/types.d.cts +3 -2
- package/dist/{insights → plugins/insights}/types.d.mts +3 -2
- package/package.json +18 -7
- package/src/adapters/drizzle.conformance.integration.spec.ts +2 -2
- package/src/adapters/drizzle.readBudgets.integration.spec.ts +6 -4
- package/src/adapters/drizzle.spec.ts +15 -7
- package/src/adapters/drizzle.ts +6 -6
- package/src/adapters/kysely.conformance.integration.spec.ts +2 -2
- package/src/adapters/kysely.readBudgets.integration.spec.ts +4 -2
- package/src/adapters/kysely.spec.ts +13 -9
- package/src/adapters/kysely.ts +2 -2
- package/src/adapters/mongodb.integration.spec.ts +98 -7
- package/src/adapters/mongodb.ts +2 -2
- package/src/adapters/mongodbAdapter.ts +14 -0
- package/src/adapters/prisma.conformance.integration.spec.ts +2 -2
- package/src/adapters/prisma.integration.spec.ts +16 -8
- package/src/adapters/prisma.readBudgets.integration.spec.ts +5 -2
- package/src/adapters/prisma.spec.ts +17 -9
- package/src/adapters/prisma.ts +6 -6
- package/src/adapters/prismaTestClients.ts +8 -1
- package/src/assembly/assemblePlugins.ts +73 -40
- package/src/assembly/assembly.spec.ts +63 -11
- package/src/assembly/assembly.types.spec.ts +50 -2
- package/src/assembly/clientPlugins.ts +113 -0
- package/src/assembly/configError.ts +4 -0
- package/src/assembly/databasePlugins.ts +11 -5
- package/src/assembly/pluginCli.spec.ts +254 -0
- package/src/assembly/pluginCli.ts +248 -0
- package/src/assembly/{builtInRoutes.spec.ts → pluginRoutes.spec.ts} +10 -37
- package/src/createHotUpdaterCore.ts +21 -17
- package/src/database/aggregateBatching.spec.ts +577 -0
- package/src/database/aggregateBatching.ts +803 -0
- package/src/{insights/errors.spec.ts → database/busy.spec.ts} +2 -5
- package/src/{insights/errors.ts → database/busy.ts} +1 -13
- package/src/database/database.ts +39 -8
- package/src/database/definitions.ts +4 -0
- package/src/database/engineAggregates.spec.ts +4 -7
- package/src/database/engineAggregates.ts +5 -9
- package/src/database/engineReads.ts +7 -5
- package/src/database/engineTransaction.ts +1 -7
- package/src/database/fence.spec.ts +5 -5
- package/src/database/fence.ts +4 -0
- package/src/database/index.ts +13 -7
- package/src/database/kv/kvAdapter.batching.integration.spec.ts +15 -0
- package/src/database/kv/kvAdapter.conformance.integration.spec.ts +2 -0
- package/src/database/kv/kvAdapter.spec.ts +128 -1
- package/src/database/kv/kvAdapter.ts +30 -1
- package/src/database/kv/kvTestStore.ts +28 -1
- package/src/database/resolveSchema.ts +4 -1
- package/src/database/retention.spec.ts +314 -0
- package/src/database/retention.ts +129 -0
- package/src/database/schema.ts +44 -0
- package/src/database/sql/sqlAdapter.integration.spec.ts +4 -7
- package/src/database/sql/sqlAdapter.readBudgets.integration.spec.ts +18 -4
- package/src/database/sql/sqlAdapter.spec.ts +91 -3
- package/src/database/sql/sqlAdapter.ts +20 -0
- package/src/database/sql/sqlSchema.ts +81 -0
- package/src/databaseTestSuite.spec.ts +9 -4
- package/src/db/coreDatabase.ts +153 -0
- package/src/db/engineSql.spec.ts +8 -7
- package/src/db/index.ts +19 -2
- package/src/db/pluginTables.spec.ts +57 -27
- package/src/db/types.ts +3 -3
- package/src/diff.ts +6 -0
- package/src/handler-standalone.integration.spec.ts +2 -3
- package/src/handler.ts +1 -32
- package/src/handlerReleaseCatalogRoutes.ts +26 -2
- package/src/index.ts +0 -10
- package/src/{apiKeys.integration.spec.ts → plugins/api-keys/apiKeys.integration.spec.ts} +4 -4
- package/src/{apiKeys.spec.ts → plugins/api-keys/apiKeys.spec.ts} +3 -3
- package/src/{apiKeys.ts → plugins/api-keys/apiKeys.ts} +1 -1
- package/src/plugins/api-keys/apiKeysPlugin.spec.ts +11 -15
- package/src/plugins/api-keys/cli.spec.ts +187 -0
- package/src/plugins/api-keys/cli.ts +140 -0
- package/src/plugins/api-keys/index.ts +48 -41
- package/src/plugins/api-keys/model.ts +21 -2
- package/src/plugins/definePlugin.ts +144 -2
- package/src/plugins/index.ts +20 -2
- package/src/plugins/insights/contract.spec.ts +285 -0
- package/src/plugins/insights/contract.ts +372 -0
- package/src/{insights → plugins/insights}/domain.ts +73 -15
- package/src/plugins/insights/errors.ts +11 -0
- package/src/{insights → plugins/insights}/eventInput.ts +189 -29
- package/src/plugins/insights/eventRow.ts +209 -0
- package/src/plugins/insights/index.ts +181 -45
- package/src/{insights → plugins/insights}/insights.integration.spec.ts +330 -34
- package/src/plugins/insights/insightsRollout.integration.spec.ts +1 -2
- package/src/plugins/insights/model.spec.ts +3 -5
- package/src/plugins/insights/model.ts +2 -3
- package/src/plugins/insights/modelTypes.ts +197 -0
- package/src/plugins/insights/overview.spec.ts +64 -0
- package/src/plugins/insights/overview.ts +214 -0
- package/src/{insights → plugins/insights}/provider.spec.ts +21 -10
- package/src/{insights → plugins/insights}/provider.ts +58 -21
- package/src/{insights → plugins/insights}/queryInput.ts +2 -2
- package/src/plugins/insights/reads.spec.ts +340 -52
- package/src/plugins/insights/reads.ts +453 -123
- package/src/plugins/insights/recordEvent.spec.ts +474 -20
- package/src/plugins/insights/recordEvent.ts +301 -63
- package/src/plugins/insights/retention.spec.ts +115 -0
- package/src/{insights → plugins/insights}/routes.ts +1 -31
- package/src/plugins/insights/schema.ts +356 -176
- package/src/plugins/insights/testing/expectInsightsIndex.spec.ts +42 -0
- package/src/plugins/insights/testing/expectInsightsIndex.ts +20 -0
- package/src/plugins/insights/testing/fixtures.ts +30 -0
- package/src/plugins/insights/testing/index.ts +45 -0
- package/src/plugins/insights/testing/insightsModelTests.ts +860 -0
- package/src/plugins/insights/testing/setupInsightsHttpTestSuite.ts +152 -0
- package/src/plugins/insights/testing/setupInsightsModelTestSuite.ts +36 -0
- package/src/plugins/insights/testing/types.ts +30 -0
- package/src/{insights → plugins/insights}/types.ts +1 -1
- package/src/readBudgets.testFixtures.ts +2 -2
- package/src/releaseCatalogRoutes.integration.spec.ts +7 -0
- package/src/retention.spec.ts +73 -0
- package/src/runtime.spec.ts +11 -12
- package/src/runtime.testFixtures.ts +7 -2
- package/src/testUtilsMutation.integration.spec.ts +2 -1
- package/src/testUtilsPackage.integration.spec.ts +7 -3
- package/dist/db/builtInDatabase.cjs +0 -104
- package/dist/db/builtInDatabase.d.cts +0 -38
- package/dist/db/builtInDatabase.d.mts +0 -38
- package/dist/db/builtInDatabase.mjs +0 -97
- package/dist/plugins/builtIn.cjs +0 -7
- package/dist/plugins/builtIn.mjs +0 -6
- package/src/db/builtInDatabase.ts +0 -149
- package/src/plugins/builtIn.ts +0 -5
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
addInsightsDistinct,
|
|
4
|
-
assertBundleEventRow,
|
|
5
|
-
compareUtf8,
|
|
6
|
-
currentInsightsReleaseId,
|
|
7
|
-
insightsKey,
|
|
8
|
-
insightsOverviewDeltas,
|
|
9
|
-
insightsOverviewId,
|
|
10
|
-
type InsightsOverviewIdentity,
|
|
11
|
-
} from "@hot-updater/plugin-core/internal";
|
|
1
|
+
import { addDistinct, compareUtf8 } from "@hot-updater/plugin-core/internal";
|
|
12
2
|
|
|
13
3
|
import type {
|
|
14
4
|
HotUpdaterDatabase,
|
|
15
5
|
HotUpdaterTransaction,
|
|
16
6
|
} from "../../database/database";
|
|
17
|
-
import {
|
|
7
|
+
import { assertBundleEventRow } from "./contract";
|
|
8
|
+
import type { BundleEventFailure, BundleEventRow } from "./eventRow";
|
|
9
|
+
import {
|
|
10
|
+
insightsKey,
|
|
11
|
+
insightsOverviewDeltas,
|
|
12
|
+
insightsOverviewId,
|
|
13
|
+
type InsightsOverviewIdentity,
|
|
14
|
+
} from "./overview";
|
|
15
|
+
import {
|
|
16
|
+
DAILY_EVENTS,
|
|
17
|
+
DAY_MS,
|
|
18
|
+
HOUR_MS,
|
|
19
|
+
isFailedCheck,
|
|
20
|
+
type InsightsSchema,
|
|
21
|
+
} from "./schema";
|
|
18
22
|
|
|
19
|
-
/** The head columns `countHead`
|
|
23
|
+
/** The head columns `countHead` and `repeatsHead` read. */
|
|
20
24
|
interface Head {
|
|
21
25
|
readonly install_id: string;
|
|
22
26
|
readonly id: string;
|
|
@@ -24,34 +28,54 @@ interface Head {
|
|
|
24
28
|
readonly platform: string;
|
|
25
29
|
readonly channel: string;
|
|
26
30
|
readonly type: string;
|
|
31
|
+
readonly user_id: string | null;
|
|
32
|
+
readonly from_release_id: string | null;
|
|
27
33
|
readonly from_bundle_id: string | null;
|
|
34
|
+
readonly to_release_id: string | null;
|
|
28
35
|
readonly to_bundle_id: string;
|
|
29
|
-
readonly current_release_id: string | null;
|
|
30
36
|
readonly app_version: string;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
const hourOf = (ms: number) => ms - (ms % HOUR_MS);
|
|
34
40
|
const dayOf = (ms: number) => ms - (ms % DAY_MS);
|
|
35
41
|
|
|
36
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* An overview or sketch row's scope and period; day periods roll up channel
|
|
44
|
+
* and usage rows. The `failure` and `check` scopes key the sketches of
|
|
45
|
+
* installations whose update, or whose update check, failed.
|
|
46
|
+
*/
|
|
37
47
|
export type InsightsIdentityParts = Omit<
|
|
38
48
|
InsightsOverviewIdentity,
|
|
39
|
-
"bucketStartMs" | "periodKind"
|
|
40
|
-
> & {
|
|
49
|
+
"bucketStartMs" | "periodKind" | "scopeKind"
|
|
50
|
+
> & {
|
|
51
|
+
readonly scopeKind:
|
|
52
|
+
| InsightsOverviewIdentity["scopeKind"]
|
|
53
|
+
| "failure"
|
|
54
|
+
| "check";
|
|
55
|
+
readonly periodKind: InsightsOverviewIdentity["periodKind"] | "day";
|
|
56
|
+
};
|
|
41
57
|
|
|
42
58
|
/** The `identity` of an overview or sketch row: its scope and period, hashed. */
|
|
43
59
|
export const insightsIdentity = (identity: InsightsIdentityParts): string =>
|
|
44
60
|
insightsOverviewId({
|
|
45
61
|
...identity,
|
|
62
|
+
scopeKind: identity.scopeKind as InsightsOverviewIdentity["scopeKind"],
|
|
46
63
|
periodKind: identity.periodKind as InsightsOverviewIdentity["periodKind"],
|
|
47
64
|
bucketStartMs: 0,
|
|
48
65
|
});
|
|
49
66
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
/**
|
|
68
|
+
* The bucket a head's gauges count it in, the UTC day of its event, and the
|
|
69
|
+
* release its distribution row names: the one it runs, which a download
|
|
70
|
+
* leaves at its source.
|
|
71
|
+
*/
|
|
72
|
+
const gaugeSlot = (head: Head) => ({
|
|
73
|
+
bucket: dayOf(head.received_at_ms),
|
|
74
|
+
releaseId:
|
|
75
|
+
head.type === "UPDATE_DOWNLOADED"
|
|
76
|
+
? head.from_release_id
|
|
77
|
+
: head.to_release_id,
|
|
78
|
+
});
|
|
55
79
|
|
|
56
80
|
/**
|
|
57
81
|
* The `insights_latest_by_bundle` field of a head's (from, to) pair. A head
|
|
@@ -64,13 +88,16 @@ export const PAIR_FIELD = "from_to";
|
|
|
64
88
|
export const bundlePairKey = (from: string, to: string): string =>
|
|
65
89
|
insightsKey(`${from.length}:${from}${to.length}:${to}`);
|
|
66
90
|
|
|
67
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Moves a head's gauges: the distribution row, one row per bundle it
|
|
93
|
+
* references, and its pair; -1 takes back the head an event replaces.
|
|
94
|
+
*/
|
|
68
95
|
const countHead = (
|
|
69
96
|
tx: HotUpdaterTransaction<InsightsSchema>,
|
|
70
97
|
head: Head,
|
|
71
98
|
delta: 1 | -1,
|
|
72
99
|
) => {
|
|
73
|
-
const bucket =
|
|
100
|
+
const { bucket, releaseId } = gaugeSlot(head);
|
|
74
101
|
const shardBy = head.install_id;
|
|
75
102
|
tx.aggregate(
|
|
76
103
|
"insights_distribution",
|
|
@@ -78,7 +105,7 @@ const countHead = (
|
|
|
78
105
|
channel: head.channel,
|
|
79
106
|
platform: head.platform,
|
|
80
107
|
app_version: head.app_version,
|
|
81
|
-
release_id:
|
|
108
|
+
release_id: releaseId ?? "",
|
|
82
109
|
bucket_start_ms: bucket,
|
|
83
110
|
},
|
|
84
111
|
{ latest_installations: delta },
|
|
@@ -118,10 +145,37 @@ const countHead = (
|
|
|
118
145
|
}
|
|
119
146
|
};
|
|
120
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Where each period's rows go, each with its retention: hours for 90 days,
|
|
150
|
+
* days for 13 months, and a release's lifetime counters kept.
|
|
151
|
+
*/
|
|
152
|
+
const PERIOD_MODELS = {
|
|
153
|
+
hour: { counters: "insights_overview", sketches: "insights_sketches" },
|
|
154
|
+
day: {
|
|
155
|
+
counters: "insights_overview_daily",
|
|
156
|
+
sketches: "insights_sketches_daily",
|
|
157
|
+
},
|
|
158
|
+
lifetime: { counters: "insights_overview_lifetime", sketches: undefined },
|
|
159
|
+
} as const;
|
|
160
|
+
|
|
161
|
+
/** A download's patch counters: a patch delivered it, or it fell back from one. */
|
|
162
|
+
const patchCounters = (event: BundleEventRow) =>
|
|
163
|
+
event.type !== "UPDATE_DOWNLOADED"
|
|
164
|
+
? {}
|
|
165
|
+
: {
|
|
166
|
+
...(event.metadata.delivery === "patch" ? { patch_downloads: 1 } : {}),
|
|
167
|
+
...(event.metadata.patch_fallback === true
|
|
168
|
+
? { patch_fallbacks: 1 }
|
|
169
|
+
: {}),
|
|
170
|
+
};
|
|
171
|
+
|
|
121
172
|
/**
|
|
122
173
|
* Counters and sketches for one event: release, channel, and usage rows, with
|
|
123
|
-
* day rollups for channel and usage
|
|
124
|
-
*
|
|
174
|
+
* day rollups for channel and usage. Usage rows are written for the event's
|
|
175
|
+
* platform only, since a read for every platform merges the ios and android
|
|
176
|
+
* sketches; a channel's active installations come from its usage rows, so
|
|
177
|
+
* channel rows keep no sketch of their own. A download's patch counters go
|
|
178
|
+
* in the rows that count it.
|
|
125
179
|
*/
|
|
126
180
|
const countEvent = (
|
|
127
181
|
tx: HotUpdaterTransaction<InsightsSchema>,
|
|
@@ -129,6 +183,7 @@ const countEvent = (
|
|
|
129
183
|
) => {
|
|
130
184
|
const shardBy = event.install_id;
|
|
131
185
|
for (const delta of insightsOverviewDeltas(event)) {
|
|
186
|
+
if (delta.identity.platform === "all") continue;
|
|
132
187
|
const { bucketStartMs, ...parts } = delta.identity;
|
|
133
188
|
const periods =
|
|
134
189
|
parts.scopeKind === "channel" || parts.scopeKind === "usage"
|
|
@@ -138,6 +193,7 @@ const countEvent = (
|
|
|
138
193
|
] as const)
|
|
139
194
|
: ([[parts.periodKind, bucketStartMs]] as const);
|
|
140
195
|
for (const [periodKind, bucket] of periods) {
|
|
196
|
+
const models = PERIOD_MODELS[periodKind as keyof typeof PERIOD_MODELS];
|
|
141
197
|
const key = {
|
|
142
198
|
identity: insightsIdentity({ ...parts, periodKind }),
|
|
143
199
|
bucket_start_ms: bucket,
|
|
@@ -146,54 +202,198 @@ const countEvent = (
|
|
|
146
202
|
downloads?: number;
|
|
147
203
|
launches?: number;
|
|
148
204
|
failed_launches?: number;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
[
|
|
154
|
-
|
|
155
|
-
|
|
205
|
+
patch_downloads?: number;
|
|
206
|
+
patch_fallbacks?: number;
|
|
207
|
+
} = {
|
|
208
|
+
...Object.fromEntries(
|
|
209
|
+
[
|
|
210
|
+
["downloads", delta.downloads],
|
|
211
|
+
["launches", delta.launches],
|
|
212
|
+
["failed_launches", delta.failedLaunches],
|
|
213
|
+
].filter(([, value]) => value !== 0),
|
|
214
|
+
),
|
|
215
|
+
...(delta.downloads === 0 ? {} : patchCounters(event)),
|
|
216
|
+
};
|
|
156
217
|
if (Object.keys(counters).length > 0) {
|
|
157
|
-
tx.aggregate(
|
|
218
|
+
tx.aggregate(models.counters, key, counters, { shardBy });
|
|
158
219
|
}
|
|
159
220
|
const sketches = {
|
|
160
|
-
...(delta.launchIdentity === undefined
|
|
221
|
+
...(delta.launchIdentity === undefined || parts.scopeKind === "channel"
|
|
161
222
|
? {}
|
|
162
|
-
: { launch_users:
|
|
223
|
+
: { launch_users: addDistinct(null, delta.launchIdentity) }),
|
|
163
224
|
...(delta.activityIdentity === undefined
|
|
164
225
|
? {}
|
|
165
226
|
: {
|
|
166
|
-
activity_users:
|
|
227
|
+
activity_users: addDistinct(null, delta.activityIdentity),
|
|
167
228
|
}),
|
|
168
229
|
};
|
|
169
|
-
if (Object.keys(sketches).length > 0) {
|
|
170
|
-
tx.aggregate(
|
|
230
|
+
if (models.sketches !== undefined && Object.keys(sketches).length > 0) {
|
|
231
|
+
tx.aggregate(models.sketches, key, sketches, { shardBy });
|
|
171
232
|
}
|
|
172
233
|
}
|
|
173
234
|
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A stored event's outcome rows: its bundle filter's hour, which a failed
|
|
239
|
+
* check has none of, and every stored event's UTC day.
|
|
240
|
+
*/
|
|
241
|
+
const countOutcome = (
|
|
242
|
+
tx: HotUpdaterTransaction<InsightsSchema>,
|
|
243
|
+
event: BundleEventRow,
|
|
244
|
+
) => {
|
|
245
|
+
const shardBy = event.install_id;
|
|
246
|
+
if (!isFailedCheck(event)) {
|
|
247
|
+
tx.aggregate(
|
|
248
|
+
"insights_outcomes",
|
|
249
|
+
{
|
|
250
|
+
platform: event.platform,
|
|
251
|
+
channel: event.channel,
|
|
252
|
+
type: event.type,
|
|
253
|
+
bundle_ref:
|
|
254
|
+
event.type === "RECOVERED"
|
|
255
|
+
? `from:${event.from_bundle_id}`
|
|
256
|
+
: `to:${event.to_bundle_id}`,
|
|
257
|
+
bucket_start_ms: hourOf(event.received_at_ms),
|
|
258
|
+
},
|
|
259
|
+
{ events: 1 },
|
|
260
|
+
{ shardBy },
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
// The global event list reads only the days this row counts: a gap costs
|
|
264
|
+
// it one empty day and one read of this row, not a read a day. One more
|
|
265
|
+
// blind increment per event, on the event's shard like the others.
|
|
174
266
|
tx.aggregate(
|
|
175
267
|
"insights_outcomes",
|
|
268
|
+
{ ...DAILY_EVENTS, bucket_start_ms: dayOf(event.received_at_ms) },
|
|
269
|
+
{ events: 1 },
|
|
270
|
+
{ shardBy },
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/** The row check requires an UPDATE_FAILED row's failure; its type leaves it optional. */
|
|
275
|
+
const UNKNOWN_FAILURE: BundleEventFailure = {
|
|
276
|
+
stage: "unknown",
|
|
277
|
+
reason: "unknown",
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/** A failure's `detail`: what else the client knew, as a JSON array. */
|
|
281
|
+
const failureDetail = (failure: BundleEventFailure): string =>
|
|
282
|
+
JSON.stringify([
|
|
283
|
+
failure.resource ?? null,
|
|
284
|
+
failure.http_status ?? null,
|
|
285
|
+
failure.origin_code ?? null,
|
|
286
|
+
failure.transport ?? null,
|
|
287
|
+
]);
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* An update failure's sketches, breakdown row, and lifetime counter. Its
|
|
291
|
+
* hourly breakdown row is what windowed reads sum, so no hourly or daily
|
|
292
|
+
* counter repeats it. A failed check counts for its channel, in the `check`
|
|
293
|
+
* sketch of installations. Any other failure counts in the channel's
|
|
294
|
+
* `failure` sketch, and for its target release, when it names one, in the
|
|
295
|
+
* release's hourly and lifetime `failure` sketches and its lifetime
|
|
296
|
+
* `failed_updates`, which the bundle detail reads. A failure is no launch
|
|
297
|
+
* and no activity: the installation reports its launch that day.
|
|
298
|
+
*/
|
|
299
|
+
const countFailure = (
|
|
300
|
+
tx: HotUpdaterTransaction<InsightsSchema>,
|
|
301
|
+
event: BundleEventRow & { readonly type: "UPDATE_FAILED" },
|
|
302
|
+
) => {
|
|
303
|
+
const shardBy = event.install_id;
|
|
304
|
+
const failure = event.metadata.failure ?? UNKNOWN_FAILURE;
|
|
305
|
+
const check = failure.stage === "check";
|
|
306
|
+
const hour = hourOf(event.received_at_ms);
|
|
307
|
+
const scope = {
|
|
308
|
+
channel: event.channel,
|
|
309
|
+
platform: event.platform,
|
|
310
|
+
appVersionKind: "all",
|
|
311
|
+
appVersion: "",
|
|
312
|
+
} as const;
|
|
313
|
+
const channel = { ...scope, releaseKind: "all", releaseId: "" } as const;
|
|
314
|
+
const users = { failed_users: addDistinct(null, event.install_id) };
|
|
315
|
+
for (const [periodKind, bucket] of [
|
|
316
|
+
["hour", hour],
|
|
317
|
+
["day", dayOf(event.received_at_ms)],
|
|
318
|
+
] as const) {
|
|
319
|
+
const identity = insightsIdentity({
|
|
320
|
+
...channel,
|
|
321
|
+
scopeKind: check ? "check" : "failure",
|
|
322
|
+
periodKind,
|
|
323
|
+
});
|
|
324
|
+
tx.aggregate(
|
|
325
|
+
PERIOD_MODELS[periodKind].sketches,
|
|
326
|
+
{ identity, bucket_start_ms: bucket },
|
|
327
|
+
users,
|
|
328
|
+
{ shardBy },
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
const releaseId = check ? null : event.to_release_id;
|
|
332
|
+
if (releaseId !== null) {
|
|
333
|
+
const release = { ...scope, releaseKind: "specific", releaseId } as const;
|
|
334
|
+
for (const [periodKind, bucket, sketches] of [
|
|
335
|
+
["hour", hour, "insights_sketches"],
|
|
336
|
+
["lifetime", 0, "insights_sketches_lifetime"],
|
|
337
|
+
] as const) {
|
|
338
|
+
const key = (scopeKind: InsightsIdentityParts["scopeKind"]) => ({
|
|
339
|
+
identity: insightsIdentity({ ...release, scopeKind, periodKind }),
|
|
340
|
+
bucket_start_ms: bucket,
|
|
341
|
+
});
|
|
342
|
+
tx.aggregate(sketches, key("failure"), users, { shardBy });
|
|
343
|
+
}
|
|
344
|
+
tx.aggregate(
|
|
345
|
+
"insights_overview_lifetime",
|
|
346
|
+
{
|
|
347
|
+
identity: insightsIdentity({
|
|
348
|
+
...release,
|
|
349
|
+
scopeKind: "release",
|
|
350
|
+
periodKind: "lifetime",
|
|
351
|
+
}),
|
|
352
|
+
bucket_start_ms: 0,
|
|
353
|
+
},
|
|
354
|
+
{ failed_updates: 1 },
|
|
355
|
+
{ shardBy },
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
tx.aggregate(
|
|
359
|
+
"insights_failures",
|
|
176
360
|
{
|
|
177
361
|
platform: event.platform,
|
|
178
362
|
channel: event.channel,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
bucket_start_ms: hourOf(event.received_at_ms),
|
|
363
|
+
bucket_start_ms: hour,
|
|
364
|
+
release_id: releaseId ?? "",
|
|
365
|
+
stage: failure.stage,
|
|
366
|
+
reason: failure.reason,
|
|
367
|
+
detail: failureDetail(failure),
|
|
185
368
|
},
|
|
186
369
|
{ events: 1 },
|
|
187
370
|
{ shardBy },
|
|
188
371
|
);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* A recovery's exit reason, which Android 11+ reports, in the breakdown of
|
|
376
|
+
* the release whose launch failed: stage `launch`, the reason as its reason.
|
|
377
|
+
*/
|
|
378
|
+
const countExit = (
|
|
379
|
+
tx: HotUpdaterTransaction<InsightsSchema>,
|
|
380
|
+
event: BundleEventRow,
|
|
381
|
+
) => {
|
|
382
|
+
const exit = event.metadata.previous_process_exit;
|
|
383
|
+
if (event.type !== "RECOVERED" || exit === undefined) return;
|
|
192
384
|
tx.aggregate(
|
|
193
|
-
"
|
|
194
|
-
{
|
|
385
|
+
"insights_failures",
|
|
386
|
+
{
|
|
387
|
+
platform: event.platform,
|
|
388
|
+
channel: event.channel,
|
|
389
|
+
bucket_start_ms: hourOf(event.received_at_ms),
|
|
390
|
+
release_id: event.from_release_id ?? "",
|
|
391
|
+
stage: "launch",
|
|
392
|
+
reason: exit,
|
|
393
|
+
detail: "",
|
|
394
|
+
},
|
|
195
395
|
{ events: 1 },
|
|
196
|
-
{ shardBy },
|
|
396
|
+
{ shardBy: event.install_id },
|
|
197
397
|
);
|
|
198
398
|
};
|
|
199
399
|
|
|
@@ -202,11 +402,39 @@ const isNewer = (event: Head, head: Head) =>
|
|
|
202
402
|
? event.received_at_ms > head.received_at_ms
|
|
203
403
|
: compareUtf8(event.id, head.id) > 0;
|
|
204
404
|
|
|
405
|
+
/** What an UNCHANGED report must share with its installation's head to repeat it. */
|
|
406
|
+
const REPEATED_FIELDS = [
|
|
407
|
+
"channel",
|
|
408
|
+
"platform",
|
|
409
|
+
"app_version",
|
|
410
|
+
"to_bundle_id",
|
|
411
|
+
"to_release_id",
|
|
412
|
+
"user_id",
|
|
413
|
+
] as const;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* An UNCHANGED report that repeats its installation's head from the same UTC
|
|
417
|
+
* day: the installation already counts as active that day, on that bundle,
|
|
418
|
+
* so the report records nothing. A download's head does not count, because
|
|
419
|
+
* its installation still ran the bundle it downloaded from.
|
|
420
|
+
*/
|
|
421
|
+
const repeatsHead = (event: BundleEventRow, head: Head) =>
|
|
422
|
+
event.type === "UNCHANGED" &&
|
|
423
|
+
head.type !== "UPDATE_DOWNLOADED" &&
|
|
424
|
+
dayOf(event.received_at_ms) === dayOf(head.received_at_ms) &&
|
|
425
|
+
REPEATED_FIELDS.every((field) => event[field] === head[field]);
|
|
426
|
+
|
|
205
427
|
/**
|
|
206
428
|
* Records one event in one transaction: one batch read of the event and its
|
|
207
429
|
* installation's head, one of the gauge and sketch rows it changes, then one
|
|
208
|
-
* write.
|
|
209
|
-
*
|
|
430
|
+
* write. On a database that batches aggregates (DynamoDB, Firestore), the
|
|
431
|
+
* write holds the event's rows and one log row instead, and a compaction
|
|
432
|
+
* reads and writes the aggregate rows. A stored event's id changes nothing
|
|
433
|
+
* when repeated, whichever installation sends it, and neither does the id
|
|
434
|
+
* of the installation's head. An UNCHANGED report that repeats its head on
|
|
435
|
+
* the same UTC day writes nothing at all. An older event still counts in its
|
|
436
|
+
* own hour but never replaces the head. An update failure is stored and
|
|
437
|
+
* counted, but changes what no installation runs, so it moves no head.
|
|
210
438
|
*/
|
|
211
439
|
export const recordEvent = (
|
|
212
440
|
db: HotUpdaterDatabase<InsightsSchema>,
|
|
@@ -219,20 +447,30 @@ export const recordEvent = (
|
|
|
219
447
|
tx.findOne("bundle_event_heads", { install_id: event.install_id }),
|
|
220
448
|
]);
|
|
221
449
|
// The id is the report's idempotency key: a retry, or any report under
|
|
222
|
-
// an id already stored
|
|
223
|
-
// duplicates.
|
|
224
|
-
if (existing !== null) return;
|
|
225
|
-
|
|
450
|
+
// an id already stored or already the installation's head, changes
|
|
451
|
+
// nothing, as analytics ingestion drops duplicates.
|
|
452
|
+
if (existing !== null || previous?.id === event.id) return;
|
|
453
|
+
if (previous !== null && repeatsHead(event, previous)) return;
|
|
454
|
+
// An UNCHANGED report is a launch: it counts and moves the head, but no
|
|
455
|
+
// event list shows it, so no event row or outcome row keeps it.
|
|
456
|
+
if (event.type !== "UNCHANGED") {
|
|
457
|
+
tx.create("bundle_events", event);
|
|
458
|
+
countOutcome(tx, event);
|
|
459
|
+
}
|
|
460
|
+
if (event.type === "UPDATE_FAILED") {
|
|
461
|
+
countFailure(tx, event);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
226
464
|
countEvent(tx, event);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (previous !== null && !isNewer(head, previous)) return;
|
|
465
|
+
countExit(tx, event);
|
|
466
|
+
if (previous !== null && !isNewer(event, previous)) return;
|
|
230
467
|
if (previous === null) {
|
|
231
|
-
tx.create("bundle_event_heads",
|
|
468
|
+
tx.create("bundle_event_heads", event);
|
|
232
469
|
} else {
|
|
470
|
+
const { install_id: _, ...fields } = event;
|
|
233
471
|
countHead(tx, previous, -1);
|
|
234
472
|
tx.update("bundle_event_heads", previous, fields);
|
|
235
473
|
}
|
|
236
|
-
countHead(tx,
|
|
474
|
+
countHead(tx, event, 1);
|
|
237
475
|
});
|
|
238
476
|
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createMemoryAdapter } from "@hot-updater/plugin-core/internal";
|
|
2
|
+
import { createPluginTestHarness } from "@hot-updater/test-utils";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { HotUpdaterConfigError } from "../../assembly/configError";
|
|
6
|
+
import * as engine from "../../database";
|
|
7
|
+
import { resolveSchema } from "../../database/resolveSchema";
|
|
8
|
+
import { createHotUpdater } from "../../index";
|
|
9
|
+
import { insights } from "./index";
|
|
10
|
+
|
|
11
|
+
const DAY = 86_400_000;
|
|
12
|
+
const HOUR = 3_600_000;
|
|
13
|
+
const T = Date.UTC(2026, 8, 23, 10);
|
|
14
|
+
|
|
15
|
+
/** Each table's retention in days, or null where rows are kept. */
|
|
16
|
+
const periods = (plugin: ReturnType<typeof insights>) =>
|
|
17
|
+
Object.fromEntries(
|
|
18
|
+
resolveSchema([{ id: "insights", schema: plugin.schema }]).tables.map(
|
|
19
|
+
(table) => [
|
|
20
|
+
table.name,
|
|
21
|
+
table.retention ? table.retention.ms / DAY : null,
|
|
22
|
+
],
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
describe("insights retention", () => {
|
|
27
|
+
it("keeps raw events and hourly rows 90 days, daily rows and heads 400, lifetime rows always", () => {
|
|
28
|
+
expect(periods(insights())).toEqual({
|
|
29
|
+
bundle_events: 90,
|
|
30
|
+
bundle_event_heads: 400,
|
|
31
|
+
insights_overview: 90,
|
|
32
|
+
insights_sketches: 90,
|
|
33
|
+
insights_overview_daily: 400,
|
|
34
|
+
insights_sketches_daily: 400,
|
|
35
|
+
insights_overview_lifetime: null,
|
|
36
|
+
insights_sketches_lifetime: null,
|
|
37
|
+
insights_distribution: 400,
|
|
38
|
+
insights_latest_by_bundle: 400,
|
|
39
|
+
insights_outcomes: 90,
|
|
40
|
+
insights_failures: 90,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("takes other periods, whose tables are the same", () => {
|
|
45
|
+
const plugin = insights({ retention: { rawDays: 30, dailyDays: 60 } });
|
|
46
|
+
|
|
47
|
+
expect(periods(plugin)).toMatchObject({
|
|
48
|
+
bundle_events: 30,
|
|
49
|
+
bundle_event_heads: 60,
|
|
50
|
+
insights_overview: 30,
|
|
51
|
+
insights_overview_daily: 60,
|
|
52
|
+
insights_overview_lifetime: null,
|
|
53
|
+
insights_distribution: 60,
|
|
54
|
+
insights_outcomes: 30,
|
|
55
|
+
});
|
|
56
|
+
const tables = (value: ReturnType<typeof insights>) =>
|
|
57
|
+
resolveSchema([{ id: "insights", schema: value.schema }]).tables.map(
|
|
58
|
+
({ retention: _retention, ...table }) => table,
|
|
59
|
+
);
|
|
60
|
+
expect(tables(plugin)).toEqual(tables(insights()));
|
|
61
|
+
expect(periods(insights({ retention: { rawDays: 7 } }))).toMatchObject({
|
|
62
|
+
bundle_events: 7,
|
|
63
|
+
bundle_event_heads: 400,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("refuses periods under a day, fractions, or a daily period under the raw one", () => {
|
|
68
|
+
for (const retention of [
|
|
69
|
+
{ rawDays: 0 },
|
|
70
|
+
{ dailyDays: 0 },
|
|
71
|
+
{ rawDays: 1.5 },
|
|
72
|
+
{ rawDays: 30, dailyDays: 10 },
|
|
73
|
+
{ rawDays: 500 },
|
|
74
|
+
]) {
|
|
75
|
+
expect(() => insights({ retention })).toThrow(HotUpdaterConfigError);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("reports its periods through its API and its admin route", async () => {
|
|
80
|
+
const hotUpdater = createHotUpdater({
|
|
81
|
+
clientAccess: "public",
|
|
82
|
+
database: { name: "memory", adapter: createMemoryAdapter() },
|
|
83
|
+
plugins: [insights({ retention: { rawDays: 30, dailyDays: 60 } })],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(hotUpdater.api.insights.retention).toEqual({
|
|
87
|
+
rawDays: 30,
|
|
88
|
+
dailyDays: 60,
|
|
89
|
+
});
|
|
90
|
+
const response = await hotUpdater.handlers.admin(
|
|
91
|
+
new Request("https://admin.example.com/retention"),
|
|
92
|
+
);
|
|
93
|
+
await expect(response.json()).resolves.toEqual({
|
|
94
|
+
rawDays: 30,
|
|
95
|
+
dailyDays: 60,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("reads hourly rows only within the raw period", async () => {
|
|
100
|
+
const harness = await createPluginTestHarness(
|
|
101
|
+
insights({ retention: { rawDays: 30, dailyDays: 60 } }),
|
|
102
|
+
{ engine, adapter: createMemoryAdapter() },
|
|
103
|
+
);
|
|
104
|
+
harness.setNow(() => T);
|
|
105
|
+
|
|
106
|
+
const usage = await harness.api.getAppUsage({
|
|
107
|
+
channel: "production",
|
|
108
|
+
platform: "ios",
|
|
109
|
+
timeRange: { start: T - 40 * DAY, end: T },
|
|
110
|
+
intervalMs: HOUR,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(usage.coverage).toEqual({ kind: "partial", sinceMs: T - 30 * DAY });
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { isDatabaseBusyError } from "../../database/busy";
|
|
1
2
|
import {
|
|
2
3
|
InsightsBadRequestError,
|
|
3
4
|
InsightsPayloadTooLargeError,
|
|
4
|
-
isDatabaseBusyError,
|
|
5
5
|
} from "./errors";
|
|
6
6
|
import { parseBundleEventRequest } from "./eventInput";
|
|
7
7
|
import {
|
|
@@ -110,36 +110,6 @@ export type InsightsRouteHandler = (
|
|
|
110
110
|
request: Request,
|
|
111
111
|
) => Promise<Response>;
|
|
112
112
|
|
|
113
|
-
/** Without the insights plugin, its routes answer 204 and say Insights is off. */
|
|
114
|
-
export const insightsDisabled: InsightsRouteHandler = async () =>
|
|
115
|
-
new Response(null, {
|
|
116
|
-
headers: {
|
|
117
|
-
"cache-control": "private, no-store",
|
|
118
|
-
"x-hot-updater-insights": "disabled",
|
|
119
|
-
},
|
|
120
|
-
status: 204,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
/** What a server without the insights plugin logs on the first event it drops. */
|
|
124
|
-
export const INSIGHTS_OFF_WARNING =
|
|
125
|
-
"[hot-updater] Insights is off, so POST /events answered 204 and stored nothing. Add insights() from @hot-updater/server/plugins/insights to plugins to record app events, or set insights: false in the app's HotUpdater.init to stop sending them. This warning prints once per server.";
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* The client's `POST /events` without the insights plugin. It answers as
|
|
129
|
-
* {@link insightsDisabled} does, so apps need no change, and warns on the
|
|
130
|
-
* first event it drops, so a server that left out `insights()` says so.
|
|
131
|
-
*/
|
|
132
|
-
export const createDroppedEventHandler = (): InsightsRouteHandler => {
|
|
133
|
-
let warned = false;
|
|
134
|
-
return (params, request) => {
|
|
135
|
-
if (!warned) {
|
|
136
|
-
warned = true;
|
|
137
|
-
console.warn(INSIGHTS_OFF_WARNING);
|
|
138
|
-
}
|
|
139
|
-
return insightsDisabled(params, request);
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
|
|
143
113
|
export const createInsightsRouteHandlers = (
|
|
144
114
|
provider: InsightsProvider,
|
|
145
115
|
): Record<InsightsRouteName, InsightsRouteHandler> => ({
|