Skip to content

Commit

Permalink
Merge pull request #156 from lokanandaprabhu/feature/SRVKP-6363
Browse files Browse the repository at this point in the history
SRVKP-6363: use TaskRuns `results.tekton.dev/record` annotation to get the logs
  • Loading branch information
openshift-merge-bot[bot] authored Sep 13, 2024
2 parents c416771 + 3f8692b commit a4b3159
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/components/hooks/useTektonResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export const useGetTaskRuns = (
export const useTRTaskRunLog = (
namespace: string,
taskRunName: string,
taskRunPath: string,
): [string, boolean, unknown] => {
const [result, setResult] = React.useState<[string, boolean, unknown]>([
null,
Expand All @@ -210,7 +211,7 @@ export const useTRTaskRunLog = (
if (namespace && taskRunName) {
(async () => {
try {
const log = await getTaskRunLog(namespace, taskRunName);
const log = await getTaskRunLog(taskRunPath);
if (!disposed) {
setResult([log, true, undefined]);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/logs/TektonTaskRunLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const TektonTaskRunLog: React.FC<TektonTaskRunLogProps> = ({
const [trResults, trLoaded, trError] = useTRTaskRunLog(
taskRun.metadata.namespace,
taskRun.metadata.name,
taskRun.metadata?.annotations?.['results.tekton.dev/record'],
);

React.useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/logs/logs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type StepsWatchUrl = {
[key: string]: {
name: string;
steps: { [step: string]: WatchURLStatus };
taskRunPath: string;
};
};

Expand Down Expand Up @@ -133,6 +134,8 @@ export const getDownloadAllLogsCallback = (
acc[currTask] = {
name: pipelineTaskName,
steps: { ...allStepUrls },
taskRunPath:
taskRun.metadata?.annotations?.['results.tekton.dev/record'],
};
return acc;
}, {});
Expand Down Expand Up @@ -167,7 +170,7 @@ export const getDownloadAllLogsCallback = (
}
} else {
// eslint-disable-next-line no-await-in-loop
allLogs += await getTaskRunLog(namespace, currTask).then(
allLogs += await getTaskRunLog(task.taskRunPath).then(
(log) => `${tasks[currTask].name.toUpperCase()}\n\n${log}\n\n`,
);
}
Expand Down
26 changes: 4 additions & 22 deletions src/components/utils/tekton-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export const NEQ = (left: string, right: string) =>
export enum DataType {
PipelineRun = 'tekton.dev/v1.PipelineRun',
TaskRun = 'tekton.dev/v1.TaskRun',
Log = 'results.tekton.dev/v1alpha2.Log',
}

export const labelsToFilter = (labels?: MatchLabels): string =>
Expand Down Expand Up @@ -481,31 +480,14 @@ export const getTRURLHost = async () => {
return route?.spec.host;
};

const getLog = async (taskRunPath: string) => {
export const getTaskRunLog = async (taskRunPath: string): Promise<string> => {
if (!taskRunPath) {
throw404();
}
const tektonResultsAPI = await getTektonResultsAPIUrl();
const url = `https://${tektonResultsAPI}/apis/results.tekton.dev/v1alpha2/parents/${taskRunPath.replace(
'/records/',
'/logs/',
)}`;
return consoleProxyFetchLog({ url, method: 'GET', allowInsecure: true });
};

export const getTaskRunLog = (
namespace: string,
taskRunName: string,
): Promise<string> =>
getFilteredRecord<any>(
namespace,
DataType.Log,
AND(
EQ(`data.spec.resource.kind`, 'TaskRun'),
EQ(`data.spec.resource.name`, taskRunName),
),
{ limit: 1 },
).then((x) =>
x?.[1]?.records.length > 0
? getLog(x?.[1]?.records[0].name).then((response: string) => {
return response;
})
: throw404(),
);

0 comments on commit a4b3159

Please # to comment.