Add detected tar version to telemetry

This commit is contained in:
Henry Mercer
2024-08-16 12:18:36 +01:00
parent ffa1b05b27
commit 335044a8db
6 changed files with 71 additions and 12 deletions

View File

@@ -42,6 +42,7 @@ import {
getActionsStatus,
sendStatusReport,
} from "./status-report";
import { isZstdAvailable } from "./tar";
import { ToolsFeature } from "./tools-features";
import { getTotalCacheSize } from "./trap-caching";
import {
@@ -375,6 +376,8 @@ async function run() {
try {
cleanupDatabaseClusterDirectory(config, logger);
await logZstdAvailability(config, logger);
// Log CodeQL download telemetry, if appropriate
if (toolsDownloadStatusReport) {
addDiagnostic(
@@ -670,6 +673,29 @@ function getTrapCachingEnabled(): boolean {
return true;
}
async function logZstdAvailability(config: configUtils.Config, logger: Logger) {
// Log zstd availability
const zstdAvailableResult = await isZstdAvailable(logger);
addDiagnostic(
config,
// Arbitrarily choose the first language. We could also choose all languages, but that
// increases the risk of misinterpreting the data.
config.languages[0],
makeDiagnostic(
"codeql-action/zstd-availability",
"Zstandard availability",
{
attributes: zstdAvailableResult,
visibility: {
cliSummaryTable: false,
statusPage: false,
telemetry: true,
},
},
),
);
}
async function runWrapper() {
try {
await run();

View File

@@ -8,7 +8,7 @@ import { assertNever } from "./util";
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
type TarVersion = {
export type TarVersion = {
type: "gnu" | "bsd";
version: string;
};
@@ -46,15 +46,24 @@ async function getTarVersion(): Promise<TarVersion> {
}
}
export async function isZstdAvailable(logger: Logger): Promise<boolean> {
export async function isZstdAvailable(
logger: Logger,
): Promise<{ available: boolean; version?: TarVersion }> {
try {
const { type, version } = await getTarVersion();
const tarVersion = await getTarVersion();
const { type, version } = tarVersion;
logger.info(`Found ${type} tar version ${version}.`);
switch (type) {
case "gnu":
return version >= MIN_REQUIRED_GNU_TAR_VERSION;
return {
available: version >= MIN_REQUIRED_GNU_TAR_VERSION,
version: tarVersion,
};
case "bsd":
return version >= MIN_REQUIRED_BSD_TAR_VERSION;
return {
available: version >= MIN_REQUIRED_BSD_TAR_VERSION,
version: tarVersion,
};
default:
assertNever(type);
}
@@ -63,7 +72,7 @@ export async function isZstdAvailable(logger: Logger): Promise<boolean> {
"Failed to determine tar version, therefore will assume zstd may not be available. " +
`The underlying error was: ${e}`,
);
return false;
return { available: false };
}
}