Merge pull request #938 from github/respect-end-tracing
Respect `end-tracing` script instead of deleting one variable
This commit is contained in:
commit
d7ad71d803
6 changed files with 84 additions and 8 deletions
12
lib/analyze.js
generated
12
lib/analyze.js
generated
|
|
@ -29,6 +29,7 @@ const codeql_1 = require("./codeql");
|
||||||
const count_loc_1 = require("./count-loc");
|
const count_loc_1 = require("./count-loc");
|
||||||
const languages_1 = require("./languages");
|
const languages_1 = require("./languages");
|
||||||
const sharedEnv = __importStar(require("./shared-environment"));
|
const sharedEnv = __importStar(require("./shared-environment"));
|
||||||
|
const tracer_config_1 = require("./tracer-config");
|
||||||
const util = __importStar(require("./util"));
|
const util = __importStar(require("./util"));
|
||||||
class CodeQLAnalysisError extends Error {
|
class CodeQLAnalysisError extends Error {
|
||||||
constructor(queriesStatusReport, message) {
|
constructor(queriesStatusReport, message) {
|
||||||
|
|
@ -232,8 +233,15 @@ function packWithVersionToQuerySuiteEntry(pack) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
async function runFinalize(outputDir, threadsFlag, memoryFlag, config, logger) {
|
async function runFinalize(outputDir, threadsFlag, memoryFlag, config, logger) {
|
||||||
// Delete the tracer config env var to avoid tracing ourselves
|
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
|
||||||
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
|
if (await util.codeQlVersionAbove(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING)) {
|
||||||
|
// Delete variables as specified by the end-tracing script
|
||||||
|
await (0, tracer_config_1.endTracingForCluster)(config);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Delete the tracer config env var to avoid tracing ourselves
|
||||||
|
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
|
||||||
|
}
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
await finalizeDatabaseCreation(config, threadsFlag, memoryFlag, logger);
|
await finalizeDatabaseCreation(config, threadsFlag, memoryFlag, logger);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
26
lib/tracer-config.js
generated
26
lib/tracer-config.js
generated
|
|
@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getCombinedTracerConfig = exports.concatTracerConfigs = exports.getTracerConfigForLanguage = exports.getTracerConfigForCluster = void 0;
|
exports.getCombinedTracerConfig = exports.concatTracerConfigs = exports.getTracerConfigForLanguage = exports.getTracerConfigForCluster = exports.endTracingForCluster = void 0;
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const codeql_1 = require("./codeql");
|
const codeql_1 = require("./codeql");
|
||||||
|
|
@ -33,6 +33,30 @@ const CRITICAL_TRACER_VARS = new Set([
|
||||||
"SEMMLE_DEPTRACE_SOCKET",
|
"SEMMLE_DEPTRACE_SOCKET",
|
||||||
"SEMMLE_JAVA_TOOL_OPTIONS",
|
"SEMMLE_JAVA_TOOL_OPTIONS",
|
||||||
]);
|
]);
|
||||||
|
async function endTracingForCluster(config) {
|
||||||
|
// If there are no traced languages, we don't need to do anything.
|
||||||
|
if (!config.languages.some(languages_1.isTracedLanguage))
|
||||||
|
return;
|
||||||
|
const envVariablesFile = path.resolve(config.dbLocation, "temp/tracingEnvironment/end-tracing.json");
|
||||||
|
if (!fs.existsSync(envVariablesFile)) {
|
||||||
|
throw new Error(`Environment file for ending tracing not found: ${envVariablesFile}`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const endTracingEnvVariables = JSON.parse(fs.readFileSync(envVariablesFile, "utf8"));
|
||||||
|
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
|
||||||
|
if (value !== null) {
|
||||||
|
process.env[key] = value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delete process.env[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw new Error(`Failed to parse file containing end tracing environment variables: ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.endTracingForCluster = endTracingForCluster;
|
||||||
async function getTracerConfigForCluster(config) {
|
async function getTracerConfigForCluster(config) {
|
||||||
const tracingEnvVariables = JSON.parse(fs.readFileSync(path.resolve(config.dbLocation, "temp/tracingEnvironment/start-tracing.json"), "utf8"));
|
const tracingEnvVariables = JSON.parse(fs.readFileSync(path.resolve(config.dbLocation, "temp/tracingEnvironment/start-tracing.json"), "utf8"));
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -5,12 +5,17 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||||
import * as yaml from "js-yaml";
|
import * as yaml from "js-yaml";
|
||||||
|
|
||||||
import * as analysisPaths from "./analysis-paths";
|
import * as analysisPaths from "./analysis-paths";
|
||||||
import { CODEQL_VERSION_COUNTS_LINES, getCodeQL } from "./codeql";
|
import {
|
||||||
|
CODEQL_VERSION_COUNTS_LINES,
|
||||||
|
CODEQL_VERSION_NEW_TRACING,
|
||||||
|
getCodeQL,
|
||||||
|
} from "./codeql";
|
||||||
import * as configUtils from "./config-utils";
|
import * as configUtils from "./config-utils";
|
||||||
import { countLoc } from "./count-loc";
|
import { countLoc } from "./count-loc";
|
||||||
import { isScannedLanguage, Language } from "./languages";
|
import { isScannedLanguage, Language } from "./languages";
|
||||||
import { Logger } from "./logging";
|
import { Logger } from "./logging";
|
||||||
import * as sharedEnv from "./shared-environment";
|
import * as sharedEnv from "./shared-environment";
|
||||||
|
import { endTracingForCluster } from "./tracer-config";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
||||||
export class CodeQLAnalysisError extends Error {
|
export class CodeQLAnalysisError extends Error {
|
||||||
|
|
@ -409,8 +414,14 @@ export async function runFinalize(
|
||||||
config: configUtils.Config,
|
config: configUtils.Config,
|
||||||
logger: Logger
|
logger: Logger
|
||||||
) {
|
) {
|
||||||
// Delete the tracer config env var to avoid tracing ourselves
|
const codeql = await getCodeQL(config.codeQLCmd);
|
||||||
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
|
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) {
|
||||||
|
// Delete variables as specified by the end-tracing script
|
||||||
|
await endTracingForCluster(config);
|
||||||
|
} else {
|
||||||
|
// Delete the tracer config env var to avoid tracing ourselves
|
||||||
|
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
|
||||||
|
}
|
||||||
|
|
||||||
fs.mkdirSync(outputDir, { recursive: true });
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,39 @@ const CRITICAL_TRACER_VARS = new Set([
|
||||||
"SEMMLE_JAVA_TOOL_OPTIONS",
|
"SEMMLE_JAVA_TOOL_OPTIONS",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
export async function endTracingForCluster(
|
||||||
|
config: configUtils.Config
|
||||||
|
): Promise<void> {
|
||||||
|
// If there are no traced languages, we don't need to do anything.
|
||||||
|
if (!config.languages.some(isTracedLanguage)) return;
|
||||||
|
|
||||||
|
const envVariablesFile = path.resolve(
|
||||||
|
config.dbLocation,
|
||||||
|
"temp/tracingEnvironment/end-tracing.json"
|
||||||
|
);
|
||||||
|
if (!fs.existsSync(envVariablesFile)) {
|
||||||
|
throw new Error(
|
||||||
|
`Environment file for ending tracing not found: ${envVariablesFile}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
|
||||||
|
fs.readFileSync(envVariablesFile, "utf8")
|
||||||
|
);
|
||||||
|
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
|
||||||
|
if (value !== null) {
|
||||||
|
process.env[key] = value;
|
||||||
|
} else {
|
||||||
|
delete process.env[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to parse file containing end tracing environment variables: ${e}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getTracerConfigForCluster(
|
export async function getTracerConfigForCluster(
|
||||||
config: configUtils.Config
|
config: configUtils.Config
|
||||||
): Promise<TracerConfig> {
|
): Promise<TracerConfig> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue