Skip to content

Commit

Permalink
Add missing API root for external logs requests
Browse files Browse the repository at this point in the history
Somehow the external logs APIs in the client never used the API
root when constructing the URL. This means that if the Dashboard
is deployed at a non-root path, the requests never made it to
the logs proxy.

Update the external logs URL util to include the API root in the
same manner as we already do for all other APIs.
  • Loading branch information
AlanGreene authored and tekton-robot committed Sep 16, 2024
1 parent ce376bf commit 2efc34c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function getExternalLogURL({
if (queryString) {
queryString = `?${queryString}`;
}
return `${externalLogsURL}/${namespace}/${podName}/${container}${queryString}`;
return `${getAPIRoot({ isDashboardAPI: true })}${externalLogsURL}/${namespace}/${podName}/${container}${queryString}`;
}

export function getPodLogURL({ container, name, namespace, follow }) {
Expand Down
14 changes: 8 additions & 6 deletions src/api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ it('useEvents', async () => {

it('getExternalLogURL', () => {
const container = 'fake_container';
const externalLogsURL = 'fake_externalLogsURL';
const externalLogsURL = '/fake_externalLogsURL';
const namespace = 'fake_namespace';
const podName = 'fake_podName';
const startTime = '2000-01-02T03:04:05Z';
Expand All @@ -171,7 +171,7 @@ it('getExternalLogURL', () => {
startTime
})
).toEqual(
`${externalLogsURL}/${namespace}/${podName}/${container}?startTime=${startTime.replaceAll(
`http://localhost:3000${externalLogsURL}/${namespace}/${podName}/${container}?startTime=${startTime.replaceAll(
':',
'%3A'
)}&completionTime=${completionTime.replaceAll(':', '%3A')}`
Expand All @@ -180,7 +180,7 @@ it('getExternalLogURL', () => {

it('getExternalLogURL with empty completionTime', () => {
const container = 'fake_container';
const externalLogsURL = 'fake_externalLogsURL';
const externalLogsURL = '/fake_externalLogsURL';
const namespace = 'fake_namespace';
const podName = 'fake_podName';
const startTime = '2000-01-02T03:04:05Z';
Expand All @@ -193,7 +193,7 @@ it('getExternalLogURL with empty completionTime', () => {
startTime
})
).toEqual(
`${externalLogsURL}/${namespace}/${podName}/${container}?startTime=${startTime.replaceAll(
`http://localhost:3000${externalLogsURL}/${namespace}/${podName}/${container}?startTime=${startTime.replaceAll(
':',
'%3A'
)}`
Expand All @@ -202,12 +202,14 @@ it('getExternalLogURL with empty completionTime', () => {

it('getExternalLogURL with empty startTime and completionTime', () => {
const container = 'fake_container';
const externalLogsURL = 'fake_externalLogsURL';
const externalLogsURL = '/fake_externalLogsURL';
const namespace = 'fake_namespace';
const podName = 'fake_podName';
expect(
API.getExternalLogURL({ container, externalLogsURL, namespace, podName })
).toEqual(`${externalLogsURL}/${namespace}/${podName}/${container}`);
).toEqual(
`http://localhost:3000${externalLogsURL}/${namespace}/${podName}/${container}`
);
});

it('getPodLog', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('fetchLogsFallback', () => {

it('should return a function to retrieve logs from the external provider', () => {
const container = 'fake_container';
const externalLogsURL = 'fake_url';
const externalLogsURL = '/fake_url';
const namespace = 'fake_namespace';
const podName = 'fake_podName';
const stepName = 'fake_stepName';
Expand All @@ -149,7 +149,7 @@ describe('fetchLogsFallback', () => {
const fallback = fetchLogsFallback(externalLogsURL);
fallback(stepName, stepStatus, taskRun);
expect(comms.get).toHaveBeenCalledWith(
`${externalLogsURL}/${namespace}/${podName}/${container}?startTime=${startTime.replaceAll(
`http://localhost:3000${externalLogsURL}/${namespace}/${podName}/${container}?startTime=${startTime.replaceAll(
':',
'%3A'
)}&completionTime=${completionTime.replaceAll(':', '%3A')}`,
Expand All @@ -159,7 +159,7 @@ describe('fetchLogsFallback', () => {

it('should handle a missing startTime and completionTime', () => {
const container = 'fake_container';
const externalLogsURL = 'fake_url';
const externalLogsURL = '/fake_url';
const namespace = 'fake_namespace';
const podName = 'fake_podName';
const stepName = 'fake_stepName';
Expand All @@ -170,7 +170,7 @@ describe('fetchLogsFallback', () => {
const fallback = fetchLogsFallback(externalLogsURL);
fallback(stepName, stepStatus, taskRun);
expect(comms.get).toHaveBeenCalledWith(
`${externalLogsURL}/${namespace}/${podName}/${container}`,
`http://localhost:3000${externalLogsURL}/${namespace}/${podName}/${container}`,
{ Accept: 'text/plain' }
);
});
Expand Down

0 comments on commit 2efc34c

Please sign in to comment.