Commit a2f03694 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '33537-refactor-pods-path-to-log-endpoint' into 'master'

Logs: Rename path to endpoint and use a BE generate path for logs

Closes #33537

See merge request gitlab-org/gitlab!18929
parents 22410034 36f9471b
......@@ -32,11 +32,10 @@ export default class KubernetesPodLogs extends LogOutputBehaviours {
super();
this.options = $(container).data();
const { currentEnvironmentName, environmentsPath, logsPath, logsPage } = this.options;
const { currentEnvironmentName, environmentsPath, logsEndpoint } = this.options;
this.environmentName = currentEnvironmentName;
this.environmentsPath = environmentsPath;
this.logsPath = logsPath;
this.logsPage = logsPage;
this.logsEndpoint = logsEndpoint;
[this.podName] = getParameterValues('pod_name');
if (this.podName) {
......@@ -95,7 +94,7 @@ export default class KubernetesPodLogs extends LogOutputBehaviours {
}
getLogs() {
return requestWithBackoff(this.logsPath, { pod_name: this.podName })
return requestWithBackoff(this.logsEndpoint, { pod_name: this.podName })
.then(res => {
const { logs, pods } = res.data;
this.setupPodsDropdown(pods);
......@@ -135,11 +134,9 @@ export default class KubernetesPodLogs extends LogOutputBehaviours {
this.setupDropdown(
this.$envDropdown,
this.environmentName,
environments.map(({ name, id }) => ({ name, value: id })),
environments.map(({ name, logs_path }) => ({ name, value: logs_path })),
el => {
const envId = el.currentTarget.value;
const envRegexp = /environments\/[0-9]+/gi;
const url = this.logsPage.replace(envRegexp, `environments/${envId}`);
const url = el.currentTarget.value;
redirectTo(url);
},
);
......
......@@ -34,8 +34,7 @@ module EE
{
"current-environment-name": environment.name,
"environments-path": project_environments_path(project, format: :json),
"logs-path": logs_project_environment_path(project, environment, format: :json),
"logs-page": logs_project_environment_path(project, environment)
"logs-endpoint": logs_project_environment_path(project, environment, format: :json)
}
end
......
......@@ -43,8 +43,7 @@ describe EnvironmentsHelper do
it 'returns logs parameters data' do
expect(subject).to include(
"logs-path": logs_project_environment_path(project, environment, format: :json),
"logs-page": logs_project_environment_path(project, environment)
"logs-endpoint": logs_project_environment_path(project, environment, format: :json)
)
end
end
......
......@@ -26,7 +26,7 @@ describe('Kubernetes Logs', () => {
mock = new MockAdapter(axios);
mock.onGet(mockDataset.environmentsPath).reply(200, { environments: mockEnvironmentData });
mock.onGet(mockDataset.logsPath).reply(200, { logs: logMockData, pods: podMockData });
mock.onGet(mockDataset.logsEndpoint).reply(200, { logs: logMockData, pods: podMockData });
});
afterEach(() => {
......@@ -158,7 +158,7 @@ describe('Kubernetes Logs', () => {
describe('shows an alert', () => {
it('with an error', done => {
mock.onGet(mockDataset.logsPath).reply(400);
mock.onGet(mockDataset.logsEndpoint).reply(400);
kubernetesLog = new KubernetesLogs(kubernetesLogContainer);
kubernetesLog
......@@ -173,7 +173,7 @@ describe('Kubernetes Logs', () => {
it('with some explicit error', done => {
const errorMsg = 'Some k8s error';
mock.onGet(mockDataset.logsPath).reply(400, {
mock.onGet(mockDataset.logsEndpoint).reply(400, {
message: errorMsg,
});
......@@ -198,7 +198,7 @@ describe('Kubernetes Logs', () => {
kubernetesLogContainer = document.querySelector('.js-kubernetes-logs');
mock = new MockAdapter(axios);
mock.onGet(mockDataset.logsPath).reply(200, { logs: logMockData, pods: [hackyPodName] });
mock.onGet(mockDataset.logsEndpoint).reply(200, { logs: logMockData, pods: [hackyPodName] });
});
afterEach(() => {
......@@ -229,9 +229,9 @@ describe('Kubernetes Logs', () => {
mock = new MockAdapter(axios);
mock.onGet(mockDataset.environmentsPath).reply(200, { environments: mockEnvironmentData });
// Simulate reactive cache, 2 tries needed
mock.onGet(`${mockDataset.logsPath}`, { pod_name: podMockData[1] }).replyOnce(202);
mock.onGet(mockDataset.logsEndpoint, { pod_name: podMockData[1] }).replyOnce(202);
mock
.onGet(`${mockDataset.logsPath}`, { pod_name: podMockData[1] })
.onGet(mockDataset.logsEndpoint, { pod_name: podMockData[1] })
.reply(200, { logs: logMockData, pods: podMockData });
});
......@@ -243,7 +243,7 @@ describe('Kubernetes Logs', () => {
kubernetesLog
.getData()
.then(() => {
const calls = mock.history.get.filter(r => r.url === mockDataset.logsPath);
const calls = mock.history.get.filter(r => r.url === mockDataset.logsEndpoint);
// expect 2 tries
expect(calls.length).toEqual(2);
......@@ -278,7 +278,7 @@ describe('Kubernetes Logs', () => {
kubernetesLog
.getData()
.then(() => {
const logsCall = mock.history.get.filter(call => call.url === mockDataset.logsPath);
const logsCall = mock.history.get.filter(call => call.url === mockDataset.logsEndpoint);
expect(logsCall.length).toBe(1);
expect(logsCall[0].params.pod_name).toEqual(podMockData[2]);
......
......@@ -109,14 +109,17 @@ export const podMockData = ['production-tanuki-1', 'production-tanuki-2', 'produ
export const mockEnvironmentData = [
{
name: 'production',
logs_path: '/namespace/project/environments/1/logs',
id: 1,
},
{
name: 'stating',
logs_path: '/namespace/project/environments/2/logs',
id: 2,
},
{
name: 'review/my-new-branch',
logs_path: '/namespace/project/environments/3/logs',
id: 3,
},
];
......
......@@ -2,8 +2,7 @@
class="js-kubernetes-logs"
data-current-environment-name="production"
data-environments-path="/root/my-project/environments.json"
data-logs-page="/root/my-project/environments/1/logs"
data-logs-path="/root/my-project/environments/1/logs.json"
data-logs-endpoint="/root/my-project/environments/1/logs.json"
>
<div class="build-page-pod-logs">
<div class="build-trace-container prepend-top-default">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment