feat: add native resource telemetry
Replace scheduled process shell probes with a persistent native collector, Electron power/process telemetry, Effect services, diagnostics UI, attribution, and release packaging. Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
79ad071184
commit
dbd8a8e09c
62 files changed
+7749
-1965
No files matched your search
@@ -9,12 +9,15 @@ import {
|
||||
createStageWorkspaceConfig,
|
||||
createStagePnpmConfig,
|
||||
DESKTOP_ASAR_UNPACK,
|
||||
DESKTOP_EXTRA_RESOURCES,
|
||||
resolveDesktopRuntimeDependencies,
|
||||
resolveFffNativeDependencies,
|
||||
resolveBuildOptions,
|
||||
resolveDesktopBuildIconAssets,
|
||||
resolveDesktopProductName,
|
||||
resolveDesktopUpdateChannel,
|
||||
resolveResourceMonitorRustTargets,
|
||||
resourceMonitorExecutableName,
|
||||
resolveGitHubPublishConfig,
|
||||
resolveMockUpdateServerPort,
|
||||
resolveMockUpdateServerUrl,
|
||||
@@ -175,6 +178,27 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
|
||||
assert.deepStrictEqual(DESKTOP_ASAR_UNPACK, ["node_modules/@ff-labs/fff-bin-*/**/*"]);
|
||||
});
|
||||
|
||||
it("stages the resource monitor as an external executable resource", () => {
|
||||
assert.deepStrictEqual(DESKTOP_EXTRA_RESOURCES, [
|
||||
{
|
||||
from: "apps/desktop/prod-resources/resource-monitor",
|
||||
to: "resource-monitor",
|
||||
},
|
||||
]);
|
||||
assert.deepStrictEqual(resolveResourceMonitorRustTargets("mac", "universal"), [
|
||||
"aarch64-apple-darwin",
|
||||
"x86_64-apple-darwin",
|
||||
]);
|
||||
assert.deepStrictEqual(resolveResourceMonitorRustTargets("linux", "x64"), [
|
||||
"x86_64-unknown-linux-gnu",
|
||||
]);
|
||||
assert.deepStrictEqual(resolveResourceMonitorRustTargets("win", "arm64"), [
|
||||
"aarch64-pc-windows-msvc",
|
||||
]);
|
||||
assert.equal(resourceMonitorExecutableName("mac"), "t3-resource-monitor");
|
||||
assert.equal(resourceMonitorExecutableName("win"), "t3-resource-monitor.exe");
|
||||
});
|
||||
|
||||
it("promotes target fff binaries to direct staged dependencies", () => {
|
||||
assert.deepStrictEqual(resolveFffNativeDependencies("mac", "arm64", "0.9.4"), {
|
||||
"@ff-labs/fff-bin-darwin-arm64": "0.9.4",
|
||||
|
||||
@@ -72,6 +72,26 @@ interface PlatformConfig {
|
||||
readonly archChoices: ReadonlyArray<typeof BuildArch.Type>;
|
||||
}
|
||||
|
||||
export function resolveResourceMonitorRustTargets(
|
||||
platform: typeof BuildPlatform.Type,
|
||||
arch: typeof BuildArch.Type,
|
||||
): ReadonlyArray<string> {
|
||||
if (platform === "mac") {
|
||||
if (arch === "universal") {
|
||||
return ["aarch64-apple-darwin", "x86_64-apple-darwin"];
|
||||
}
|
||||
return [arch === "arm64" ? "aarch64-apple-darwin" : "x86_64-apple-darwin"];
|
||||
}
|
||||
if (platform === "linux") {
|
||||
return [arch === "arm64" ? "aarch64-unknown-linux-gnu" : "x86_64-unknown-linux-gnu"];
|
||||
}
|
||||
return [arch === "arm64" ? "aarch64-pc-windows-msvc" : "x86_64-pc-windows-msvc"];
|
||||
}
|
||||
|
||||
export function resourceMonitorExecutableName(platform: typeof BuildPlatform.Type): string {
|
||||
return platform === "win" ? "t3-resource-monitor.exe" : "t3-resource-monitor";
|
||||
}
|
||||
|
||||
const PLATFORM_CONFIG: Record<typeof BuildPlatform.Type, PlatformConfig> = {
|
||||
mac: {
|
||||
cliFlag: "--mac",
|
||||
@@ -292,6 +312,12 @@ interface StagePackageJson {
|
||||
|
||||
export const STAGE_INSTALL_ARGS = ["install", "--prod"] as const;
|
||||
export const DESKTOP_ASAR_UNPACK = ["node_modules/@ff-labs/fff-bin-*/**/*"] as const;
|
||||
export const DESKTOP_EXTRA_RESOURCES = [
|
||||
{
|
||||
from: "apps/desktop/prod-resources/resource-monitor",
|
||||
to: "resource-monitor",
|
||||
},
|
||||
] as const;
|
||||
|
||||
export function resolveFffNativeDependencies(
|
||||
platform: typeof BuildPlatform.Type,
|
||||
@@ -497,6 +523,78 @@ const runCommand = Effect.fn("runCommand")(function* (
|
||||
}
|
||||
});
|
||||
|
||||
const stageResourceMonitor = Effect.fn("stageResourceMonitor")(function* (input: {
|
||||
readonly repoRoot: string;
|
||||
readonly stageResourcesDir: string;
|
||||
readonly platform: typeof BuildPlatform.Type;
|
||||
readonly arch: typeof BuildArch.Type;
|
||||
readonly verbose: boolean;
|
||||
}) {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const manifestPath = path.join(input.repoRoot, "native/resource-monitor/Cargo.toml");
|
||||
const executableName = resourceMonitorExecutableName(input.platform);
|
||||
const rustTargets = resolveResourceMonitorRustTargets(input.platform, input.arch);
|
||||
const builtBinaries: string[] = [];
|
||||
|
||||
for (const rustTarget of rustTargets) {
|
||||
const spawnCommand = yield* resolveSpawnCommand("cargo", [
|
||||
"build",
|
||||
"--locked",
|
||||
"--release",
|
||||
"--manifest-path",
|
||||
manifestPath,
|
||||
"--target",
|
||||
rustTarget,
|
||||
]);
|
||||
yield* runCommand(
|
||||
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
|
||||
cwd: input.repoRoot,
|
||||
shell: spawnCommand.shell,
|
||||
}),
|
||||
{
|
||||
label: `cargo build resource monitor (${rustTarget})`,
|
||||
verbose: input.verbose,
|
||||
},
|
||||
);
|
||||
|
||||
const binaryPath = path.join(
|
||||
input.repoRoot,
|
||||
"native/resource-monitor/target",
|
||||
rustTarget,
|
||||
"release",
|
||||
executableName,
|
||||
);
|
||||
if (!(yield* fs.exists(binaryPath))) {
|
||||
return yield* new BuildScriptError({
|
||||
message: `Resource monitor build did not produce ${binaryPath}.`,
|
||||
});
|
||||
}
|
||||
builtBinaries.push(binaryPath);
|
||||
}
|
||||
|
||||
const destinationDirectory = path.join(input.stageResourcesDir, "resource-monitor");
|
||||
const destinationPath = path.join(destinationDirectory, executableName);
|
||||
yield* fs.remove(destinationDirectory, { recursive: true, force: true }).pipe(Effect.ignore);
|
||||
yield* fs.makeDirectory(destinationDirectory, { recursive: true });
|
||||
|
||||
if (builtBinaries.length === 1) {
|
||||
yield* fs.copyFile(builtBinaries[0]!, destinationPath);
|
||||
} else {
|
||||
yield* runCommand(
|
||||
ChildProcess.make("lipo", ["-create", ...builtBinaries, "-output", destinationPath]),
|
||||
{
|
||||
label: "lipo resource monitor universal binary",
|
||||
verbose: input.verbose,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (input.platform !== "win") {
|
||||
yield* fs.chmod(destinationPath, 0o755);
|
||||
}
|
||||
});
|
||||
|
||||
function generateMacIconSet(
|
||||
sourcePng: string,
|
||||
targetIcns: string,
|
||||
@@ -755,6 +853,7 @@ const createBuildConfig = Effect.fn("createBuildConfig")(function* (
|
||||
directories: {
|
||||
buildResources: "apps/desktop/resources",
|
||||
},
|
||||
extraResources: DESKTOP_EXTRA_RESOURCES,
|
||||
};
|
||||
const updateChannel = resolveDesktopUpdateChannel(version);
|
||||
const publishConfig = yield* resolveGitHubPublishConfig(updateChannel);
|
||||
@@ -941,6 +1040,13 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
yield* fs.copy(distDirs.desktopDist, path.join(stageAppDir, "apps/desktop/dist-electron"));
|
||||
yield* fs.copy(distDirs.desktopResources, stageResourcesDir);
|
||||
yield* fs.copy(distDirs.serverDist, path.join(stageAppDir, "apps/server/dist"));
|
||||
yield* stageResourceMonitor({
|
||||
repoRoot,
|
||||
stageResourcesDir,
|
||||
platform: options.platform,
|
||||
arch: options.arch,
|
||||
verbose: options.verbose,
|
||||
});
|
||||
|
||||
yield* assertPlatformBuildResources(
|
||||
options.platform,
|
||||
|
||||
Reference in new issue
Block a user