Skip to content

Commit

Permalink
devlow-bench: add git branch and sha to datapoints (#8602)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wbinnssmith committed Jun 26, 2024
1 parent f93894a commit 5e65580
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/devlow-bench/src/interfaces/datadog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "_");
Expand All @@ -16,6 +17,22 @@ const UNIT_MAPPING: Record<string, string> = {
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,
Expand All @@ -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: {
Expand Down

0 comments on commit 5e65580

Please sign in to comment.