Send job_run_uuid to status report telemetry (#1685)
This commit is contained in:
parent
8ba77ef4d3
commit
4385ad5563
12 changed files with 126 additions and 11 deletions
|
|
@ -5,6 +5,7 @@ import test from "ava";
|
|||
import * as sinon from "sinon";
|
||||
|
||||
import * as actionsutil from "./actions-util";
|
||||
import * as sharedEnv from "./shared-environment";
|
||||
import { setupActionsVars, setupTests } from "./testing-utils";
|
||||
import { initializeEnvironment, withTmpDir } from "./util";
|
||||
|
||||
|
|
@ -265,3 +266,54 @@ test("isAnalyzingDefaultBranch()", async (t) => {
|
|||
getAdditionalInputStub.restore();
|
||||
});
|
||||
});
|
||||
|
||||
test("createStatusReportBase", async (t) => {
|
||||
await withTmpDir(async (tmpDir: string) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
|
||||
process.env["GITHUB_REF"] = "refs/heads/main";
|
||||
process.env["GITHUB_SHA"] = "a".repeat(40);
|
||||
process.env["GITHUB_RUN_ID"] = "100";
|
||||
process.env["GITHUB_RUN_ATTEMPT"] = "2";
|
||||
process.env["GITHUB_REPOSITORY"] = "octocat/HelloWorld";
|
||||
process.env["CODEQL_ACTION_ANALYSIS_KEY"] = "analysis-key";
|
||||
process.env["RUNNER_OS"] = "macOS";
|
||||
|
||||
const getRequiredInput = sinon.stub(actionsutil, "getRequiredInput");
|
||||
getRequiredInput.withArgs("matrix").resolves("input/matrix");
|
||||
|
||||
const statusReport = await actionsutil.createStatusReportBase(
|
||||
"init",
|
||||
"failure",
|
||||
new Date("May 19, 2023 05:19:00"),
|
||||
"failure cause",
|
||||
"exception stack trace"
|
||||
);
|
||||
|
||||
t.assert(typeof statusReport.job_run_uuid === "string");
|
||||
t.assert(statusReport.workflow_run_id === 100);
|
||||
t.assert(statusReport.workflow_run_attempt === 2);
|
||||
t.assert(
|
||||
statusReport.workflow_name === (process.env["GITHUB_WORKFLOW"] || "")
|
||||
);
|
||||
t.assert(statusReport.job_name === (process.env["GITHUB_JOB"] || ""));
|
||||
t.assert(statusReport.analysis_key === "analysis-key");
|
||||
t.assert(statusReport.commit_oid === process.env["GITHUB_SHA"]);
|
||||
t.assert(statusReport.ref === process.env["GITHUB_REF"]);
|
||||
t.assert(statusReport.action_name === "init");
|
||||
t.assert(statusReport.action_oid === "unknown");
|
||||
t.assert(
|
||||
statusReport.started_at ===
|
||||
process.env[sharedEnv.CODEQL_WORKFLOW_STARTED_AT]
|
||||
);
|
||||
t.assert(
|
||||
statusReport.action_started_at ===
|
||||
new Date("May 19, 2023 05:19:00").toISOString()
|
||||
);
|
||||
t.assert(statusReport.status === "failure");
|
||||
t.assert(statusReport.cause === "failure cause");
|
||||
t.assert(statusReport.exception === "exception stack trace");
|
||||
t.assert(statusReport.runner_os === process.env["RUNNER_OS"]);
|
||||
t.assert(typeof statusReport.action_version === "string");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ const pkg = require("../package.json") as JSONSchemaForNPMPackageJsonFiles;
|
|||
*
|
||||
* This allows us to get stronger type checking of required/optional inputs.
|
||||
*/
|
||||
export function getRequiredInput(name: string): string {
|
||||
export const getRequiredInput = function (name: string): string {
|
||||
return core.getInput(name, { required: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper around core.getInput that converts empty inputs to undefined.
|
||||
|
|
@ -316,6 +316,18 @@ export type ActionStatus =
|
|||
| "user-error";
|
||||
|
||||
export interface StatusReportBase {
|
||||
/**
|
||||
* UUID representing the job run that this status report belongs to. We
|
||||
* generate our own UUID here because Actions currently does not expose a
|
||||
* unique job run identifier. This UUID will allow us to more easily match
|
||||
* reports from different steps in the same workflow job.
|
||||
*
|
||||
* If and when Actions does expose a unique job ID, we plan to populate a
|
||||
* separate int field, `job_run_id`, with the Actions-generated identifier,
|
||||
* as it will allow us to more easily join our telemetry data with Actions
|
||||
* telemetry tables.
|
||||
*/
|
||||
job_run_uuid: string;
|
||||
/** ID of the workflow run containing the action run. */
|
||||
workflow_run_id: number;
|
||||
/** Attempt number of the run containing the action run. */
|
||||
|
|
@ -412,6 +424,7 @@ export async function createStatusReportBase(
|
|||
): Promise<StatusReportBase> {
|
||||
const commitOid = getOptionalInput("sha") || process.env["GITHUB_SHA"] || "";
|
||||
const ref = await getRef();
|
||||
const jobRunUUID = process.env[sharedEnv.JOB_RUN_UUID] || "";
|
||||
const workflowRunID = getWorkflowRunID();
|
||||
const workflowRunAttempt = getWorkflowRunAttempt();
|
||||
const workflowName = process.env["GITHUB_WORKFLOW"] || "";
|
||||
|
|
@ -440,6 +453,7 @@ export async function createStatusReportBase(
|
|||
}
|
||||
|
||||
const statusReport: StatusReportBase = {
|
||||
job_run_uuid: jobRunUUID,
|
||||
workflow_run_id: workflowRunID,
|
||||
workflow_run_attempt: workflowRunAttempt,
|
||||
workflow_name: workflowName,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import { v4 as uuidV4 } from "uuid";
|
||||
|
||||
import {
|
||||
createStatusReportBase,
|
||||
|
|
@ -26,6 +27,7 @@ import {
|
|||
import { Language } from "./languages";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import * as sharedEnv from "./shared-environment";
|
||||
import { getTotalCacheSize } from "./trap-caching";
|
||||
import {
|
||||
checkForTimeout,
|
||||
|
|
@ -212,6 +214,8 @@ async function run() {
|
|||
logger
|
||||
);
|
||||
|
||||
core.exportVariable(sharedEnv.JOB_RUN_UUID, uuidV4());
|
||||
|
||||
try {
|
||||
const workflowErrors = await validateWorkflow(logger);
|
||||
|
||||
|
|
|
|||
|
|
@ -71,3 +71,6 @@ export const CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX =
|
|||
export const CODEQL_WORKFLOW_STARTED_AT = "CODEQL_WORKFLOW_STARTED_AT";
|
||||
|
||||
export const ODASA_TRACER_CONFIGURATION = "ODASA_TRACER_CONFIGURATION";
|
||||
|
||||
/** UUID representing the current job run. */
|
||||
export const JOB_RUN_UUID = "JOB_RUN_UUID";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue