@vercel/devlow-bench 0.3.1 → 0.3.3
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/browser.js +3 -0
- package/dist/cli.js +6 -0
- package/dist/file.js +5 -4
- package/dist/interfaces/console.js +5 -4
- package/dist/interfaces/constants.d.ts +11 -0
- package/dist/interfaces/constants.js +27 -0
- package/dist/interfaces/datadog.js +11 -8
- package/dist/interfaces/snowflake-test.d.ts +1 -0
- package/dist/interfaces/snowflake-test.js +42 -0
- package/dist/interfaces/snowflake.d.ts +9 -0
- package/dist/interfaces/snowflake.js +78 -0
- package/dist/shell.js +6 -4
- package/package.json +11 -5
- package/LICENSE +0 -7
package/dist/browser.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ import { pathToFileURL } from "url";
|
|
|
12
12
|
"j",
|
|
13
13
|
"console",
|
|
14
14
|
"datadog",
|
|
15
|
+
"snowflake",
|
|
15
16
|
"interactive",
|
|
16
17
|
"i",
|
|
17
18
|
"help",
|
|
@@ -39,6 +40,8 @@ import { pathToFileURL } from "url";
|
|
|
39
40
|
console.log(" --console Print the results to the console");
|
|
40
41
|
console.log(" --datadog[=<hostname>] Upload the results to Datadog");
|
|
41
42
|
console.log(" (requires DATADOG_API_KEY environment variables)");
|
|
43
|
+
console.log(" --snowflake[=<batch-uri>] Upload the results to Snowflake");
|
|
44
|
+
console.log(" (requires SNOWFLAKE_TOPIC_NAME and SNOWFLAKE_SCHEMA_ID and environment variables)");
|
|
42
45
|
console.log("## Help");
|
|
43
46
|
console.log(" --help, -h, -? Show this help");
|
|
44
47
|
}
|
|
@@ -79,10 +82,13 @@ import { pathToFileURL } from "url";
|
|
|
79
82
|
args.json && (await import("./interfaces/json.js")).default(args.json),
|
|
80
83
|
args.datadog &&
|
|
81
84
|
(await import("./interfaces/datadog.js")).default(typeof args.datadog === "string" ? { host: args.datadog } : undefined),
|
|
85
|
+
args.snowflake &&
|
|
86
|
+
(await import("./interfaces/snowflake.js")).default(typeof args.snowflake === "string" ? { gatewayUri: args.snowflake } : undefined),
|
|
82
87
|
args.console !== false &&
|
|
83
88
|
(await import("./interfaces/console.js")).default(),
|
|
84
89
|
].filter((x) => x);
|
|
85
90
|
await runScenarios(scenarios, compose(...ifaces));
|
|
86
91
|
})().catch((e) => {
|
|
87
92
|
console.error(e.stack);
|
|
93
|
+
process.exit(1);
|
|
88
94
|
});
|
package/dist/file.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { watch } from
|
|
2
|
-
import { access, constants } from
|
|
3
|
-
import { dirname } from
|
|
1
|
+
import { watch } from 'fs';
|
|
2
|
+
import { access, constants } from 'fs/promises';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
4
|
export async function waitForFile(path, timeout) {
|
|
5
|
-
let currentAction =
|
|
5
|
+
let currentAction = '';
|
|
6
6
|
let timeoutRef;
|
|
7
7
|
const timeoutPromise = new Promise((resolve, reject) => {
|
|
8
8
|
timeoutRef = setTimeout(() => {
|
|
@@ -37,6 +37,7 @@ export async function waitForFile(path, timeout) {
|
|
|
37
37
|
try {
|
|
38
38
|
do {
|
|
39
39
|
await Promise.race([timeoutPromise, checkAgainPromise]);
|
|
40
|
+
// eslint-disable-next-line no-loop-func
|
|
40
41
|
checkAgainPromise = new Promise((resolve) => {
|
|
41
42
|
resolveCheckAgain = resolve;
|
|
42
43
|
});
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import picocolors from "picocolors";
|
|
2
2
|
import { formatUnit } from "../units.js";
|
|
3
3
|
import { formatVariant } from "../utils.js";
|
|
4
|
+
const { bgCyan, bold, magenta, red, underline } = picocolors;
|
|
4
5
|
export default function createInterface() {
|
|
5
6
|
const iface = {
|
|
6
7
|
start: async (scenario, props) => {
|
|
7
|
-
console.log(
|
|
8
|
+
console.log(bold(underline(`Running ${formatVariant(scenario, props)}...`)));
|
|
8
9
|
},
|
|
9
10
|
measurement: async (scenario, props, name, value, unit, relativeTo) => {
|
|
10
|
-
console.log(
|
|
11
|
+
console.log(bgCyan(bold(magenta(`${formatVariant(scenario, props)}: ${name} = ${formatUnit(value, unit)}${relativeTo ? ` (from ${relativeTo})` : ""}`))));
|
|
11
12
|
},
|
|
12
13
|
error: async (scenario, props, error) => {
|
|
13
|
-
console.log(
|
|
14
|
+
console.log(bold(red(`${formatVariant(scenario, props)}: ${(error && error.stack) || error}`)));
|
|
14
15
|
},
|
|
15
16
|
};
|
|
16
17
|
return iface;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const UNIT_MAPPING: Record<string, string>;
|
|
2
|
+
export declare const GIT_SHA: string;
|
|
3
|
+
export declare const GIT_BRANCH: string;
|
|
4
|
+
export declare const IS_CI: boolean;
|
|
5
|
+
export declare const OS: NodeJS.Platform;
|
|
6
|
+
export declare const OS_RELEASE: string;
|
|
7
|
+
export declare const NUM_CPUS: number;
|
|
8
|
+
export declare const CPU_MODEL: string;
|
|
9
|
+
export declare const USERNAME: string;
|
|
10
|
+
export declare const CPU_ARCH: string;
|
|
11
|
+
export declare const NODE_VERSION: string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { command } from "../shell.js";
|
|
3
|
+
export const UNIT_MAPPING = {
|
|
4
|
+
ms: "millisecond",
|
|
5
|
+
requests: "request",
|
|
6
|
+
bytes: "byte",
|
|
7
|
+
};
|
|
8
|
+
export const GIT_SHA = process.env.GITHUB_SHA ??
|
|
9
|
+
(await (async () => {
|
|
10
|
+
const cmd = command("git", ["rev-parse", "HEAD"]);
|
|
11
|
+
await cmd.ok();
|
|
12
|
+
return cmd.output.trim();
|
|
13
|
+
})());
|
|
14
|
+
export const GIT_BRANCH = process.env.GITHUB_REF_NAME ??
|
|
15
|
+
(await (async () => {
|
|
16
|
+
const cmd = command("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
17
|
+
await cmd.ok();
|
|
18
|
+
return cmd.output.trim();
|
|
19
|
+
})());
|
|
20
|
+
export const IS_CI = Boolean(process.env.CI);
|
|
21
|
+
export const OS = process.platform;
|
|
22
|
+
export const OS_RELEASE = os.release();
|
|
23
|
+
export const NUM_CPUS = os.cpus().length;
|
|
24
|
+
export const CPU_MODEL = os.cpus()[0].model;
|
|
25
|
+
export const USERNAME = os.userInfo().username;
|
|
26
|
+
export const CPU_ARCH = os.arch();
|
|
27
|
+
export const NODE_VERSION = process.version;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import datadogApiClient from "@datadog/datadog-api-client";
|
|
2
2
|
import os from "os";
|
|
3
|
+
import { CPU_ARCH, CPU_MODEL, GIT_BRANCH, GIT_SHA, IS_CI, NODE_VERSION, NUM_CPUS, OS, OS_RELEASE, USERNAME } from "./constants.js";
|
|
3
4
|
function toIdentifier(str) {
|
|
4
5
|
return str.replace(/\//g, ".").replace(/ /g, "_");
|
|
5
6
|
}
|
|
@@ -12,15 +13,17 @@ export default function createInterface({ apiKey = process.env.DATADOG_API_KEY,
|
|
|
12
13
|
if (!apiKey)
|
|
13
14
|
throw new Error("Datadog API key is required (set DATADOG_API_KEY)");
|
|
14
15
|
const commonTags = [
|
|
15
|
-
`ci:${
|
|
16
|
-
`os:${
|
|
17
|
-
`os_release:${
|
|
18
|
-
`cpus:${
|
|
19
|
-
`cpu_model:${
|
|
20
|
-
`user:${
|
|
21
|
-
`arch:${
|
|
16
|
+
`ci:${IS_CI}`,
|
|
17
|
+
`os:${OS}`,
|
|
18
|
+
`os_release:${OS_RELEASE}`,
|
|
19
|
+
`cpus:${NUM_CPUS}`,
|
|
20
|
+
`cpu_model:${CPU_MODEL}`,
|
|
21
|
+
`user:${USERNAME}`,
|
|
22
|
+
`arch:${CPU_ARCH}`,
|
|
22
23
|
`total_memory:${Math.round(os.totalmem() / 1024 / 1024 / 1024)}`,
|
|
23
|
-
`node_version:${
|
|
24
|
+
`node_version:${NODE_VERSION}`,
|
|
25
|
+
`git_sha:${GIT_SHA}`,
|
|
26
|
+
`git_branch:${GIT_BRANCH}`,
|
|
24
27
|
];
|
|
25
28
|
const configuration = datadogApiClient.client.createConfiguration({
|
|
26
29
|
authMethods: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import createInterface from "./snowflake.js";
|
|
3
|
+
import { mock, test } from "node:test";
|
|
4
|
+
test('sending measurements to the batch endpoint', async () => {
|
|
5
|
+
const requests = [];
|
|
6
|
+
const fetchMock = mock.method(global, 'fetch', (req, options) => {
|
|
7
|
+
requests.push([req, options]);
|
|
8
|
+
return Promise.resolve(Response.json({}));
|
|
9
|
+
});
|
|
10
|
+
const iface = createInterface({
|
|
11
|
+
gatewayUri: 'http://127.0.0.1/v1/batch',
|
|
12
|
+
topicName: 'my-topic',
|
|
13
|
+
schemaId: 123,
|
|
14
|
+
});
|
|
15
|
+
assert(iface.measurement != null);
|
|
16
|
+
await iface.measurement('scenario', { myprop: 'foo' }, 'one', 42, 'ms');
|
|
17
|
+
await iface.measurement('scenario', { myprop: 'foo' }, 'two', 45, 'ms');
|
|
18
|
+
await iface.measurement('scenario', { myprop: 'foo' }, 'three', 38, 'ms');
|
|
19
|
+
assert(iface.end != null);
|
|
20
|
+
await iface.end('scenario', { myprop: 'foo' });
|
|
21
|
+
assert.equal(requests.length, 1);
|
|
22
|
+
const [url, options] = requests[0];
|
|
23
|
+
assert.equal(url, 'http://127.0.0.1/v1/batch');
|
|
24
|
+
assert(typeof options.body === 'string');
|
|
25
|
+
const body = JSON.parse(options.body);
|
|
26
|
+
assert.equal(body.schema_id, 123);
|
|
27
|
+
assert.equal(body.topic, 'my-topic');
|
|
28
|
+
assert(body.records.length === 3);
|
|
29
|
+
assert.equal(body.records[0].metric, 'one');
|
|
30
|
+
assert.equal(body.records[0].value, 42);
|
|
31
|
+
assert.equal(body.records[0].props_json, '{"myprop":"foo"}');
|
|
32
|
+
assert.equal(body.records[0].unit, 'ms');
|
|
33
|
+
assert.equal(body.records[1].metric, 'two');
|
|
34
|
+
assert.equal(body.records[1].value, 45);
|
|
35
|
+
assert.equal(body.records[1].props_json, '{"myprop":"foo"}');
|
|
36
|
+
assert.equal(body.records[1].unit, 'ms');
|
|
37
|
+
assert.equal(body.records[2].metric, 'three');
|
|
38
|
+
assert.equal(body.records[2].value, 38);
|
|
39
|
+
assert.equal(body.records[2].props_json, '{"myprop":"foo"}');
|
|
40
|
+
assert.equal(body.records[2].unit, 'ms');
|
|
41
|
+
fetchMock.mock.restore();
|
|
42
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Interface } from "../index.js";
|
|
2
|
+
export default function createInterface({ gatewayUri, topicName, schemaId, }?: {
|
|
3
|
+
gatewayUri?: string;
|
|
4
|
+
topicName?: string;
|
|
5
|
+
schemaId?: number;
|
|
6
|
+
}): Interface;
|
|
7
|
+
export declare function omit<T extends {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}, K extends keyof T>(object: T, keys: K[]): Omit<T, K>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import { CPU_ARCH, CPU_MODEL, GIT_BRANCH, GIT_SHA, IS_CI, NODE_VERSION, NUM_CPUS, OS, OS_RELEASE, USERNAME } from "./constants.js";
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
4
|
+
export default function createInterface({ gatewayUri = process.env.SNOWFLAKE_BATCH_URI, topicName = process.env.SNOWFLAKE_TOPIC_NAME, schemaId = process.env.SNOWFLAKE_SCHEMA_ID ? parseInt(process.env.SNOWFLAKE_SCHEMA_ID, 10) : undefined, } = {}) {
|
|
5
|
+
if (!gatewayUri)
|
|
6
|
+
throw new Error("Snowflake gateway URI is required (set SNOWFLAKE_GATEWAY_URI)");
|
|
7
|
+
if (!topicName)
|
|
8
|
+
throw new Error("Snowflake topic name is required (set SNOWFLAKE_TOPIC_NAME)");
|
|
9
|
+
if (!schemaId)
|
|
10
|
+
throw new Error("Snowflake schema ID is required (set SNOWFLAKE_SCHEMA_ID to a valid integer)");
|
|
11
|
+
const records = [];
|
|
12
|
+
const iface = {
|
|
13
|
+
measurement: async (scenario, props, name, value, unit, relativeTo) => {
|
|
14
|
+
const ts = Math.round(Date.now() / 1000);
|
|
15
|
+
records.push({
|
|
16
|
+
event_time: ts,
|
|
17
|
+
scenario,
|
|
18
|
+
props,
|
|
19
|
+
metric: name,
|
|
20
|
+
value,
|
|
21
|
+
unit,
|
|
22
|
+
relative_to: relativeTo,
|
|
23
|
+
is_ci: IS_CI,
|
|
24
|
+
os: OS,
|
|
25
|
+
os_release: OS_RELEASE,
|
|
26
|
+
cpus: NUM_CPUS,
|
|
27
|
+
cpu_model: CPU_MODEL,
|
|
28
|
+
user: USERNAME,
|
|
29
|
+
arch: CPU_ARCH,
|
|
30
|
+
total_memory_bytes: os.totalmem(),
|
|
31
|
+
node_version: NODE_VERSION,
|
|
32
|
+
git_sha: GIT_SHA,
|
|
33
|
+
git_branch: GIT_BRANCH,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
end: async (scenario, props) => {
|
|
37
|
+
await trackAnalytics(gatewayUri, topicName, schemaId, records);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return iface;
|
|
41
|
+
}
|
|
42
|
+
async function trackAnalytics(batchUri, topic, schemaId, records) {
|
|
43
|
+
try {
|
|
44
|
+
const res = await fetch(batchUri, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"Client-Id": "nextjs",
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
schema_id: schemaId,
|
|
52
|
+
topic,
|
|
53
|
+
records: records.map((record) => omit({
|
|
54
|
+
...record,
|
|
55
|
+
id: randomUUID(),
|
|
56
|
+
props_json: JSON.stringify(record.props),
|
|
57
|
+
}, ["props"])),
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
throw new Error(`Unexpected HTTP response from reporting ${topic} event to Snowflake: ${res.status}. Body: ${await res.text()}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
const wrappedError = new Error("Unexpected error tracking analytics event");
|
|
66
|
+
wrappedError.cause = e;
|
|
67
|
+
console.error(wrappedError);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function omit(object, keys) {
|
|
71
|
+
const omitted = {};
|
|
72
|
+
Object.keys(object).forEach((key) => {
|
|
73
|
+
if (!keys.includes(key)) {
|
|
74
|
+
omitted[key] = object[key];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return omitted;
|
|
78
|
+
}
|
package/dist/shell.js
CHANGED
|
@@ -5,12 +5,14 @@ import pidusage from "pidusage-tree";
|
|
|
5
5
|
import { reportMeasurement } from "./describe.js";
|
|
6
6
|
const shellOutput = !!process.env.SHELL_OUTPUT;
|
|
7
7
|
class CommandImpl {
|
|
8
|
+
process;
|
|
9
|
+
stdout = "";
|
|
10
|
+
stderr = "";
|
|
11
|
+
output = "";
|
|
12
|
+
exitPromise;
|
|
13
|
+
waitingForOutput = [];
|
|
8
14
|
constructor(process) {
|
|
9
15
|
this.process = process;
|
|
10
|
-
this.stdout = "";
|
|
11
|
-
this.stderr = "";
|
|
12
|
-
this.output = "";
|
|
13
|
-
this.waitingForOutput = [];
|
|
14
16
|
process.stdout?.pipe(split2()).on("data", (data) => {
|
|
15
17
|
const str = data.toString();
|
|
16
18
|
this.stdout += str + "\n";
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/devlow-bench",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Benchmarking tool for the developer workflow",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/vercel/next.js",
|
|
8
|
+
"directory": "turbopack/packages/devlow-bench"
|
|
9
|
+
},
|
|
5
10
|
"publishConfig": {
|
|
6
11
|
"access": "public"
|
|
7
12
|
},
|
|
@@ -29,13 +34,13 @@
|
|
|
29
34
|
"@types/minimist": "^1.2.2",
|
|
30
35
|
"@types/node": "^20.3.0",
|
|
31
36
|
"@types/split2": "^4.2.0",
|
|
32
|
-
"
|
|
37
|
+
"tsx": "4.19.2"
|
|
33
38
|
},
|
|
34
39
|
"dependencies": {
|
|
35
40
|
"@datadog/datadog-api-client": "^1.13.0",
|
|
36
|
-
"chalk": "2.4.2",
|
|
37
41
|
"inquirer": "^9.2.7",
|
|
38
42
|
"minimist": "^1.2.8",
|
|
43
|
+
"picocolors": "1.0.1",
|
|
39
44
|
"pidusage-tree": "^2.0.5",
|
|
40
45
|
"playwright-chromium": "^1.39.0",
|
|
41
46
|
"split2": "^4.2.0",
|
|
@@ -43,7 +48,8 @@
|
|
|
43
48
|
},
|
|
44
49
|
"scripts": {
|
|
45
50
|
"lint": "eslint src/",
|
|
46
|
-
"prerelease": "pnpm run build
|
|
47
|
-
"
|
|
51
|
+
"prerelease": "pnpm run build",
|
|
52
|
+
"test": "node --import tsx --test src/**/*-test.ts",
|
|
53
|
+
"build": "tsc"
|
|
48
54
|
}
|
|
49
55
|
}
|
package/LICENSE
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2024 Vercel, Inc
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|