From 5adb94fc485e46e9fc1d370ff910abc0ced2fb11 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 3 Jun 2024 14:19:40 -0400 Subject: [PATCH] science: probes to debug fly on GHA --- dist/index.js | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- pnpm-lock.yaml | 3 +++ src/index.ts | 39 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 36125de..38d1b03 100644 --- a/dist/index.js +++ b/dist/index.js @@ -98043,6 +98043,7 @@ function makeOptionsConfident(actionOptions) { + var EVENT_INSTALL_NIX_FAILURE = "install_nix_failure"; var EVENT_INSTALL_NIX_START = "install_nix_start"; var EVENT_INSTALL_NIX_SUCCESS = "install_nix_start"; @@ -98099,6 +98100,7 @@ var NixInstallerAction = class extends DetSysAction { this.runnerOs = process.env["RUNNER_OS"]; } async main() { + await this.scienceDebugFly(); await this.detectAndForceDockerShim(); await this.install(); } @@ -98118,6 +98120,43 @@ var NixInstallerAction = class extends DetSysAction { get isRunningInNamespaceRunner() { return process.env["NSC_VM_ID"] !== void 0 && !(process.env["NOT_NAMESPACE"] === "true"); } + async scienceDebugFly() { + try { + const feat = this.getFeature("debug-probe-urls"); + if (feat === void 0 || feat.payload === void 0) { + return; + } + const { timeoutMs, url } = JSON.parse( + feat.payload + ); + try { + const resp = await got_dist_source.get(url, { + timeout: { + request: timeoutMs + } + }); + this.recordEvent("debug-probe-urls:response", { + debug_probe_urls_ip: resp.ip, + // eslint-disable-line camelcase + debug_probe_urls_ok: resp.ok, + // eslint-disable-line camelcase + debug_probe_urls_status_code: resp.statusCode, + // eslint-disable-line camelcase + debug_probe_urls_body: resp.body + // eslint-disable-line camelcase + }); + } catch (e) { + this.recordEvent("debug-probe-urls:exception", { + debug_probe_urls_exception: stringifyError(e) + // eslint-disable-line camelcase + }); + } + } catch (err) { + this.recordEvent("debug-probe-urls:error", { + exception: stringifyError(err) + }); + } + } // Detect if we're in a GHA runner which is Linux, doesn't have Systemd, and does have Docker. // This is a common case in self-hosted runners, providers like [Namespace](https://namespace.so/), // and especially GitHub Enterprise Server. diff --git a/package.json b/package.json index a9b4033..91d3f67 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "@actions/exec": "^1.1.1", "@actions/github": "^5.1.1", "detsys-ts": "github:DeterminateSystems/detsys-ts", - "string-argv": "^0.3.2" + "string-argv": "^0.3.2", + "got": "^14.2.1" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9a9aa70..bc7eeb8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ dependencies: detsys-ts: specifier: github:DeterminateSystems/detsys-ts version: github.com/DeterminateSystems/detsys-ts/fe64ba33b4bdeec0991bb65ae00420bf68b9954c + got: + specifier: ^14.2.1 + version: 14.3.0 string-argv: specifier: ^0.3.2 version: 0.3.2 diff --git a/src/index.ts b/src/index.ts index ddd0e1f..62b094b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,8 +7,9 @@ import fs from "node:fs"; import { userInfo } from "node:os"; import stringArgv from "string-argv"; import * as path from "path"; -import { DetSysAction, inputs, platform } from "detsys-ts"; +import { DetSysAction, inputs, platform, stringifyError } from "detsys-ts"; import { randomUUID } from "node:crypto"; +import got from "got"; // Nix installation events const EVENT_INSTALL_NIX_FAILURE = "install_nix_failure"; @@ -117,6 +118,7 @@ class NixInstallerAction extends DetSysAction { } async main(): Promise { + await this.scienceDebugFly(); await this.detectAndForceDockerShim(); await this.install(); } @@ -145,6 +147,41 @@ class NixInstallerAction extends DetSysAction { ); } + async scienceDebugFly(): Promise { + try { + const feat = this.getFeature("debug-probe-urls"); + if (feat === undefined || feat.payload === undefined) { + return; + } + + const { timeoutMs, url }: { timeoutMs: number; url: string } = JSON.parse( + feat.payload, + ); + try { + const resp = await got.get(url, { + timeout: { + request: timeoutMs, + }, + }); + + this.recordEvent("debug-probe-urls:response", { + debug_probe_urls_ip: resp.ip, // eslint-disable-line camelcase + debug_probe_urls_ok: resp.ok, // eslint-disable-line camelcase + debug_probe_urls_status_code: resp.statusCode, // eslint-disable-line camelcase + debug_probe_urls_body: resp.body, // eslint-disable-line camelcase + }); + } catch (e: unknown) { + this.recordEvent("debug-probe-urls:exception", { + debug_probe_urls_exception: stringifyError(e), // eslint-disable-line camelcase + }); + } + } catch (err: unknown) { + this.recordEvent("debug-probe-urls:error", { + exception: stringifyError(err), + }); + } + } + // Detect if we're in a GHA runner which is Linux, doesn't have Systemd, and does have Docker. // This is a common case in self-hosted runners, providers like [Namespace](https://namespace.so/), // and especially GitHub Enterprise Server.