Merge pull request #3803 from asgerf/asgerf/factor-out-evaluator-log-paths

Refactor: Store EvaluatorLogPaths object on LocalQueryInfo
This commit is contained in:
Asger F
2024-11-20 14:24:46 +01:00
committed by GitHub
5 changed files with 35 additions and 33 deletions

View File

@@ -94,19 +94,19 @@ export class LogScannerService extends DisposableObject {
public async scanEvalLog(query: QueryHistoryInfo | undefined): Promise<void> { public async scanEvalLog(query: QueryHistoryInfo | undefined): Promise<void> {
this.diagnosticCollection.clear(); this.diagnosticCollection.clear();
if ( if (query?.t !== "local" || query.evaluatorLogPaths === undefined) {
query?.t !== "local" ||
query.evalLogSummaryLocation === undefined ||
query.jsonEvalLogSummaryLocation === undefined
) {
return; return;
} }
const diagnostics = await this.scanLog( const { summarySymbols, jsonSummary, humanReadableSummary } =
query.jsonEvalLogSummaryLocation, query.evaluatorLogPaths;
query.evalLogSummarySymbolsLocation,
); if (jsonSummary === undefined || humanReadableSummary === undefined) {
const uri = Uri.file(query.evalLogSummaryLocation); return;
}
const diagnostics = await this.scanLog(jsonSummary, summarySymbols);
const uri = Uri.file(humanReadableSummary);
this.diagnosticCollection.set(uri, diagnostics); this.diagnosticCollection.set(uri, diagnostics);
} }

View File

@@ -781,7 +781,7 @@ export class QueryHistoryManager extends DisposableObject {
private async warnNoEvalLogSummary(item: LocalQueryInfo) { private async warnNoEvalLogSummary(item: LocalQueryInfo) {
const evalLogLocation = const evalLogLocation =
item.evalLogLocation ?? item.initialInfo.outputDir?.evalLogPath; item.evaluatorLogPaths?.log ?? item.initialInfo.outputDir?.evalLogPath;
// Summary log file doesn't exist. // Summary log file doesn't exist.
if (evalLogLocation && (await pathExists(evalLogLocation))) { if (evalLogLocation && (await pathExists(evalLogLocation))) {
@@ -801,7 +801,7 @@ export class QueryHistoryManager extends DisposableObject {
} }
const evalLogLocation = const evalLogLocation =
item.evalLogLocation ?? item.initialInfo.outputDir?.evalLogPath; item.evaluatorLogPaths?.log ?? item.initialInfo.outputDir?.evalLogPath;
if (evalLogLocation && (await pathExists(evalLogLocation))) { if (evalLogLocation && (await pathExists(evalLogLocation))) {
await tryOpenExternalFile(this.app.commands, evalLogLocation); await tryOpenExternalFile(this.app.commands, evalLogLocation);
@@ -816,12 +816,15 @@ export class QueryHistoryManager extends DisposableObject {
} }
// If the summary file location wasn't saved, display error // If the summary file location wasn't saved, display error
if (!item.evalLogSummaryLocation) { if (!item.evaluatorLogPaths?.humanReadableSummary) {
await this.warnNoEvalLogSummary(item); await this.warnNoEvalLogSummary(item);
return; return;
} }
await tryOpenExternalFile(this.app.commands, item.evalLogSummaryLocation); await tryOpenExternalFile(
this.app.commands,
item.evaluatorLogPaths.humanReadableSummary,
);
} }
async handleShowEvalLogViewer(item: QueryHistoryInfo) { async handleShowEvalLogViewer(item: QueryHistoryInfo) {
@@ -830,7 +833,7 @@ export class QueryHistoryManager extends DisposableObject {
} }
// If the JSON summary file location wasn't saved, display error // If the JSON summary file location wasn't saved, display error
if (item.jsonEvalLogSummaryLocation === undefined) { if (item.evaluatorLogPaths?.jsonSummary === undefined) {
await this.warnNoEvalLogSummary(item); await this.warnNoEvalLogSummary(item);
return; return;
} }
@@ -838,7 +841,7 @@ export class QueryHistoryManager extends DisposableObject {
// TODO(angelapwen): Stream the file in. // TODO(angelapwen): Stream the file in.
try { try {
const evalLogData: EvalLogData[] = await parseViewerData( const evalLogData: EvalLogData[] = await parseViewerData(
item.jsonEvalLogSummaryLocation, item.evaluatorLogPaths.jsonSummary,
); );
const evalLogTreeBuilder = new EvalLogTreeBuilder( const evalLogTreeBuilder = new EvalLogTreeBuilder(
item.getQueryName(), item.getQueryName(),
@@ -847,7 +850,7 @@ export class QueryHistoryManager extends DisposableObject {
this.evalLogViewer.updateRoots(await evalLogTreeBuilder.getRoots()); this.evalLogViewer.updateRoots(await evalLogTreeBuilder.getRoots());
} catch { } catch {
throw new Error( throw new Error(
`Could not read evaluator log summary JSON file to generate viewer data at ${item.jsonEvalLogSummaryLocation}.`, `Could not read evaluator log summary JSON file to generate viewer data at ${item.evaluatorLogPaths.jsonSummary}.`,
); );
} }
} }

View File

@@ -25,10 +25,10 @@ export function mapLocalQueryInfoToDto(
return { return {
initialInfo: mapInitialQueryInfoToDto(query.initialInfo), initialInfo: mapInitialQueryInfoToDto(query.initialInfo),
t: "local", t: "local",
evalLogLocation: query.evalLogLocation, evalLogLocation: query.evaluatorLogPaths?.log,
evalLogSummaryLocation: query.evalLogSummaryLocation, evalLogSummaryLocation: query.evaluatorLogPaths?.humanReadableSummary,
jsonEvalLogSummaryLocation: query.jsonEvalLogSummaryLocation, jsonEvalLogSummaryLocation: query.evaluatorLogPaths?.jsonSummary,
evalLogSummarySymbolsLocation: query.evalLogSummarySymbolsLocation, evalLogSummarySymbolsLocation: query.evaluatorLogPaths?.summarySymbols,
failureReason: query.failureReason, failureReason: query.failureReason,
completedQuery: completedQuery:
query.completedQuery && mapCompletedQueryToDto(query.completedQuery), query.completedQuery && mapCompletedQueryToDto(query.completedQuery),

View File

@@ -32,10 +32,15 @@ export function mapLocalQueryItemToDomainModel(
localQuery.failureReason, localQuery.failureReason,
localQuery.completedQuery && localQuery.completedQuery &&
mapCompletedQueryInfoToDomainModel(localQuery.completedQuery), mapCompletedQueryInfoToDomainModel(localQuery.completedQuery),
localQuery.evalLogLocation, localQuery.evalLogLocation
localQuery.evalLogSummaryLocation, ? {
localQuery.jsonEvalLogSummaryLocation, log: localQuery.evalLogLocation,
localQuery.evalLogSummarySymbolsLocation, humanReadableSummary: localQuery.evalLogSummaryLocation,
jsonSummary: localQuery.jsonEvalLogSummaryLocation,
summarySymbols: localQuery.evalLogSummarySymbolsLocation,
endSummary: undefined,
}
: undefined,
); );
} }

View File

@@ -200,10 +200,7 @@ export class LocalQueryInfo {
private cancellationSource?: CancellationTokenSource, // used to cancel in progress queries private cancellationSource?: CancellationTokenSource, // used to cancel in progress queries
public failureReason?: string, public failureReason?: string,
public completedQuery?: CompletedQueryInfo, public completedQuery?: CompletedQueryInfo,
public evalLogLocation?: string, public evaluatorLogPaths?: EvaluatorLogPaths,
public evalLogSummaryLocation?: string,
public jsonEvalLogSummaryLocation?: string,
public evalLogSummarySymbolsLocation?: string,
) { ) {
/**/ /**/
} }
@@ -229,10 +226,7 @@ export class LocalQueryInfo {
/** Sets the paths to the various structured evaluator logs. */ /** Sets the paths to the various structured evaluator logs. */
public setEvaluatorLogPaths(logPaths: EvaluatorLogPaths): void { public setEvaluatorLogPaths(logPaths: EvaluatorLogPaths): void {
this.evalLogLocation = logPaths.log; this.evaluatorLogPaths = logPaths;
this.evalLogSummaryLocation = logPaths.humanReadableSummary;
this.jsonEvalLogSummaryLocation = logPaths.jsonSummary;
this.evalLogSummarySymbolsLocation = logPaths.summarySymbols;
} }
/** /**