Skip to content

Commit 0ed60b5

Browse files
Merge pull request #13455 from lokanandaprabhu/feature/OCPBUGS-25612-1
OCPBUGS-25612: Logs for PipelineRuns fetched from the Tekton Results API is not loading
2 parents 2c30034 + f67d2dc commit 0ed60b5

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

  • frontend/packages/pipelines-plugin/src/components/pipelineruns/utils

frontend/packages/pipelines-plugin/src/components/pipelineruns/utils/tekton-results.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@console/dynamic-plugin-sdk/src';
88
import { RouteModel } from '@console/internal/models';
99
import { k8sGet } from '@console/internal/module/k8s';
10-
import { consoleProxyFetchJSON } from '@console/shared/src/utils/proxy';
10+
import { consoleProxyFetch, consoleProxyFetchJSON } from '@console/shared/src/utils/proxy';
1111
import {
1212
DELETED_RESOURCE_IN_K8S_ANNOTATION,
1313
RESOURCE_LOADED_FROM_RESULTS_ANNOTATION,
@@ -23,7 +23,7 @@ import { PipelineRunKind, TaskRunKind } from '../../../types';
2323
const MINIMUM_PAGE_SIZE = 5;
2424
const MAXIMUM_PAGE_SIZE = 10000;
2525

26-
export type Record = {
26+
export type ResultRecord = {
2727
name: string;
2828
uid: string;
2929
createTime: string;
@@ -43,9 +43,18 @@ export type Log = {
4343
};
4444
};
4545

46+
type ProxyRequest = {
47+
allowInsecure?: boolean;
48+
method: string;
49+
url: string;
50+
headers?: Record<string, string[]>;
51+
queryparams?: Record<string, string[]>;
52+
body?: string;
53+
};
54+
4655
export type RecordsList = {
4756
nextPageToken?: string;
48-
records: Record[];
57+
records: ResultRecord[];
4958
};
5059

5160
export type TektonResultsOptions = {
@@ -346,13 +355,28 @@ export const getTaskRuns = (
346355
cacheKey?: string,
347356
) => getFilteredTaskRuns(namespace, '', options, nextPageToken, cacheKey);
348357

358+
const isJSONString = (str: string): boolean => {
359+
try {
360+
JSON.parse(str);
361+
} catch (e) {
362+
return false;
363+
}
364+
return true;
365+
};
366+
367+
export const consoleProxyFetchLog = <T>(proxyRequest: ProxyRequest): Promise<T> => {
368+
return consoleProxyFetch(proxyRequest).then((response) => {
369+
return isJSONString(response.body) ? JSON.parse(response.body) : response.body;
370+
});
371+
};
372+
349373
const getLog = async (taskRunPath: string) => {
350374
const tektonResultUrl = await getTRURLHost();
351375
const url = `https://${tektonResultUrl}/apis/results.tekton.dev/v1alpha2/parents/${taskRunPath.replace(
352376
'/records/',
353377
'/logs/',
354378
)}`;
355-
return consoleProxyFetchJSON({ url, method: 'GET', allowInsecure: true });
379+
return consoleProxyFetchLog({ url, method: 'GET', allowInsecure: true });
356380
};
357381

358382
export const getTaskRunLog = (namespace: string, taskRunName: string): Promise<string> =>
@@ -364,6 +388,8 @@ export const getTaskRunLog = (namespace: string, taskRunName: string): Promise<s
364388
).then((x) =>
365389
x?.[1]?.records.length > 0
366390
? // eslint-disable-next-line promise/no-nesting
367-
getLog(x?.[1]?.records[0].name).then((response: Log) => decodeValue(response.result.data))
391+
getLog(x?.[1]?.records[0].name).then((response: string) => {
392+
return response;
393+
})
368394
: throw404(),
369395
);

0 commit comments

Comments
 (0)