From 5e65580f91e48526a34dbb86d19b88a1418e3d14 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 26 Jun 2024 15:57:21 -0700 Subject: [PATCH] devlow-bench: add git branch and sha to datapoints (#8602) This includes this information to datapoints sent to Datadog. Also addresses an issue where trailing newlines were added when these values were not read from GitHub Actions. --- .../devlow-bench/src/interfaces/datadog.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/devlow-bench/src/interfaces/datadog.ts b/packages/devlow-bench/src/interfaces/datadog.ts index e18a36982c2d0..e3b37cc68ada2 100644 --- a/packages/devlow-bench/src/interfaces/datadog.ts +++ b/packages/devlow-bench/src/interfaces/datadog.ts @@ -5,6 +5,7 @@ import type { import type { Interface } from "../index.js"; import datadogApiClient from "@datadog/datadog-api-client"; import os from "os"; +import { command } from "../shell.js"; function toIdentifier(str: string) { return str.replace(/\//g, ".").replace(/ /g, "_"); @@ -16,6 +17,22 @@ const UNIT_MAPPING: Record = { bytes: "byte", }; +const GIT_SHA = + process.env.GITHUB_SHA ?? + (await (async () => { + const cmd = command("git", ["rev-parse", "HEAD"]); + await cmd.ok(); + return cmd.output.trim(); + })()); + +const GIT_BRANCH = + process.env.GITHUB_REF_NAME ?? + (await (async () => { + const cmd = command("git", ["rev-parse", "--abbrev-ref", "HEAD"]); + await cmd.ok(); + return cmd.output.trim(); + })()); + export default function createInterface({ apiKey = process.env.DATADOG_API_KEY, appKey = process.env.DATADOG_APP_KEY, @@ -33,6 +50,8 @@ export default function createInterface({ `arch:${os.arch()}`, `total_memory:${Math.round(os.totalmem() / 1024 / 1024 / 1024)}`, `node_version:${process.version}`, + `git_sha:${GIT_SHA}`, + `git_branch:${GIT_BRANCH}`, ]; const configuration = datadogApiClient.client.createConfiguration({ authMethods: {