-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code for interpolation search for asset manifest lookup
- Loading branch information
1 parent
2c2e760
commit 418ecb7
Showing
9 changed files
with
513 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@cloudflare/workers-shared": minor | ||
--- | ||
|
||
chore: Adds analytics and code (zero-percent gated) for a new asset manifest search algorithm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { afterAll, beforeAll } from "vitest"; | ||
|
||
// Can be deleted once Node.js (where these tests run) version is bumped to one which includes this global :) | ||
|
||
beforeAll(() => { | ||
// @ts-expect-error will go away once Node.js is bumped | ||
globalThis.crypto = require("crypto"); | ||
}); | ||
|
||
afterAll(() => { | ||
// @ts-expect-error will go away once Node.js is bumped | ||
delete globalThis.crypto; | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/workers-shared/asset-worker/src/experiment-analytics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { ReadyAnalytics } from "./types"; | ||
|
||
// This will allow us to make breaking changes to the analytic schema | ||
const VERSION = 1; | ||
|
||
// When adding new columns please update the schema | ||
type Data = { | ||
// -- Indexes -- | ||
accountId?: number; | ||
experimentName?: string; | ||
|
||
// -- Doubles -- | ||
// double1 - The time it takes to read the manifest in milliseconds | ||
manifestReadTime?: number; | ||
|
||
// -- Blobs -- | ||
// blob1 - Manifest read method | ||
manifestReadMethod?: string; | ||
}; | ||
|
||
export class ExperimentAnalytics { | ||
private data: Data = {}; | ||
private readyAnalytics?: ReadyAnalytics; | ||
|
||
constructor(readyAnalytics?: ReadyAnalytics) { | ||
this.readyAnalytics = readyAnalytics; | ||
} | ||
|
||
setData(newData: Partial<Data>) { | ||
this.data = { ...this.data, ...newData }; | ||
} | ||
|
||
getData(key: keyof Data) { | ||
return this.data[key]; | ||
} | ||
|
||
write() { | ||
if (!this.readyAnalytics) { | ||
return; | ||
} | ||
|
||
this.readyAnalytics.logEvent({ | ||
version: VERSION, | ||
accountId: this.data.accountId, | ||
indexId: this.data.experimentName, | ||
doubles: [ | ||
this.data.manifestReadTime ?? -1, // double1 | ||
], | ||
blobs: [ | ||
this.data.manifestReadMethod, // blob1 | ||
], | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.