Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge artifacts and verdicts from API into log #212

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/bublik/src/pages/log-page/log-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const LogHeader = ({ runId }: LogHeaderProps) => {
<CopyShortUrlButtonContainer />
</div>
</CardHeader>
<div className="flex-grow min-h-[200px]">
<div className="flex-grow">
<RunDetailsContainer runId={runId} isFullMode={isFullMode} />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/bublik/src/pages/run-page/run-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const RunHeader = ({ runId }: RunHeaderProps) => {
link.searchParams.delete('rowState');

return (
<header className="flex flex-col bg-white rounded min-h-[260px]">
<header className="flex flex-col bg-white rounded">
<CardHeader label="Info">
<div className="flex h-full gap-3">
<Tooltip content="Copy identifier for comparison">
Expand Down
1 change: 1 addition & 0 deletions libs/services/bublik-api/src/lib/bublikAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const {
useGetTreeByRunIdQuery,
useGetLogUrlByResultIdQuery,
useGetHistoryLinkDefaultsQuery,
useGetResultsAndVerdictsForIterationQuery,
// Auth
useMeQuery,
useLazyMeQuery,
Expand Down
47 changes: 43 additions & 4 deletions libs/services/bublik-api/src/lib/endpoints/log-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
/* SPDX-FileCopyrightText: 2021-2023 OKTET Labs Ltd. */
import { EndpointBuilder } from '@reduxjs/toolkit/dist/query/endpointDefinitions';
import { QueryReturnValue } from '@reduxjs/toolkit/dist/query/baseQueryTypes';
import { createNextState } from '@reduxjs/toolkit';

import {
HistoryDefaultResultAPIResponse,
ResultLogAPIResponse,
RootBlock,
TreeDataAPIResponse
} from '@/shared/types';
import { config } from '@/bublik/config';

import { transformLogTree } from '../transform';
import { BUBLIK_TAG } from '../types';
Expand All @@ -19,7 +21,7 @@ import {
BublikHttpError,
isBublikParsableError
} from '../error-handling';
import { config } from '@/bublik/config';
import { ResultsAndVerdictsForIteration } from './run-endpoints';

type GetLogJsonInputs = {
id: string | number;
Expand Down Expand Up @@ -90,9 +92,19 @@ export const logEndpoints = {
}

try {
const blocksJson = await fetchJson(jsonUrl.data.url);

return { data: blocksJson };
const [blocksJson, artifactsAndVerdicts] = (await Promise.all([
fetchJson(jsonUrl.data.url),
baseQuery(withApiV2(`/results/${id}/artifacts_and_verdicts`))
])) as [RootBlock, QueryReturnValue<ResultsAndVerdictsForIteration>];

const blocksWithAddedVerdictsAndArtifacts = addArtifactsVerdicts(
blocksJson,
artifactsAndVerdicts.data!
);

return {
data: blocksWithAddedVerdictsAndArtifacts
};
} catch (e) {
console.error(e);

Expand All @@ -111,3 +123,30 @@ export const logEndpoints = {
})
})
};

function addArtifactsVerdicts(
logBlocks: RootBlock,
artifactsAndVerdicts: ResultsAndVerdictsForIteration
): RootBlock {
return createNextState(logBlocks, (s) => {
const teLog = s.root.find((b) => b.type === 'te-log');
if (!teLog) return;

const logMeta = teLog.content.find((b) => b.type === 'te-log-meta');
if (!logMeta) return;

if (artifactsAndVerdicts.verdicts.length) {
logMeta.meta.verdicts = artifactsAndVerdicts.verdicts.map((v) => ({
level: 'RING', // default to this level since level is not provided by API
verdict: v.value
}));
}

if (artifactsAndVerdicts.artifacts.length) {
logMeta.meta.artifacts = artifactsAndVerdicts.artifacts.map((v) => ({
level: 'RING', // default to this level since level is not provided by API
artifact: v.value
}));
}
});
}
30 changes: 30 additions & 0 deletions libs/services/bublik-api/src/lib/endpoints/run-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ import { API_REDUCER_PATH } from '../constants';
import { BublikBaseQueryFn, withApiV2 } from '../config';
import { groupBy } from 'remeda';

export interface ResultsAndVerdictsForIteration {
artifacts: Artifact[];
verdicts: Verdict[];
}

export interface Artifact {
id: number;
name: string;
type: string;
value: string;
hash: string;
comment: string;
}

export interface Verdict {
id: number;
name: string;
type: string;
value: string;
hash: string;
comment: string;
}

/**
* Merges runs based on result_id and exec_seqno
* @param runs - Top most packages of runs that contain children
Expand Down Expand Up @@ -295,6 +318,13 @@ export const runEndpoints = {
return { data: mergeRuns(filteredResults) };
},
providesTags: [BUBLIK_TAG.Run]
}),
getResultsAndVerdictsForIteration: build.query<
ResultsAndVerdictsForIteration,
string | number
>({
query: (iterationId) =>
withApiV2(`/results/${iterationId}/artifacts_and_verdicts`)
})
})
};