Commit 03a7bc50 authored by Adrien Kohlbecker's avatar Adrien Kohlbecker Committed by Martin Wortschack

Pass logs url from backend to frontend

Instead of computing it manually
parent 1fc8efd1
......@@ -257,6 +257,7 @@ export default class ClusterStore {
name: environment.name,
project: environment.project,
environmentPath: environment.environment_path,
logsPath: environment.logs_path,
lastDeployment: environment.last_deployment,
rolloutStatus: {
status: environment.rollout_status ? environment.rollout_status.status : null,
......
......@@ -162,8 +162,7 @@ export default {
:is-loading="model.isLoadingDeployBoard"
:is-empty="model.isEmptyDeployBoard"
:has-legacy-app-label="model.hasLegacyAppLabel"
:project-path="model.project_path"
:environment-name="model.name"
:logs-path="model.logs_path"
/>
</div>
</div>
......
......@@ -142,8 +142,7 @@ export default {
:tooltip-text="instance.tooltip"
:pod-name="instance.pod_name"
:stable="instance.stable"
:project-path="`/${row.item.project.path_with_namespace}`"
:environment-name="row.item.name"
:logs-path="row.item.logsPath"
/>
</template>
</div>
......
......@@ -42,13 +42,10 @@ export default {
type: Boolean,
required: true,
},
environmentName: {
logsPath: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
required: false,
default: '',
},
hasLegacyAppLabel: {
type: Boolean,
......@@ -143,9 +140,8 @@ export default {
:key="i"
:status="instance.status"
:tooltip-text="instance.tooltip"
:environment-name="environmentName"
:pod-name="instance.pod_name"
:project-path="projectPath"
:logs-path="logsPath"
:stable="instance.stable"
/>
</template>
......
......@@ -13,6 +13,7 @@
* Mockup is https://gitlab.com/gitlab-org/gitlab/issues/35570
*/
import { GlLink, GlTooltipDirective } from '@gitlab/ui';
import { mergeUrlParams } from '~/lib/utils/url_utility';
export default {
components: {
......@@ -47,19 +48,13 @@ export default {
default: true,
},
environmentName: {
type: String,
required: false,
default: '',
},
podName: {
type: String,
required: false,
default: '',
},
projectPath: {
logsPath: {
type: String,
required: false,
default: '',
......@@ -68,7 +63,7 @@ export default {
computed: {
isLink() {
return Boolean(this.logsPath || this.podName);
return this.logsPath !== '' && this.podName !== '';
},
cssClass() {
......@@ -80,9 +75,7 @@ export default {
},
computedLogPath() {
return this.isLink
? `${this.projectPath}/-/logs?environment_name=${this.environmentName}&pod_name=${this.podName}`
: null;
return this.isLink ? mergeUrlParams({ pod_name: this.podName }, this.logsPath) : null;
},
},
};
......
......@@ -46,7 +46,7 @@ module EE
"custom-metrics-available" => "#{custom_metrics_available?(project)}",
"alerts-endpoint" => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
"prometheus-alerts-available" => "#{can?(current_user, :read_prometheus_alerts, project)}",
"logs-path" => project_logs_path(project)
"logs-path" => project_logs_path(project, environment_name: environment.name)
}
super.merge(ee_metrics_data)
......
......@@ -12,6 +12,10 @@ module Clusters
project_environment_path(environment.project, environment)
end
expose :logs_path, if: -> (*) { can_read_pod_logs? } do |environment|
project_logs_path(environment.project, environment_name: environment.name)
end
expose :rollout_status, if: -> (*) { can_read_cluster_deployments? }, using: ::RolloutStatusEntity
expose :updated_at
......@@ -27,5 +31,9 @@ module Clusters
def can_read_cluster_deployments?
can?(current_user, :read_cluster_environments, request.cluster)
end
def can_read_pod_logs?
can?(current_user, :read_pod_logs, environment.project)
end
end
end
......@@ -12,6 +12,10 @@ module EE
project_path(environment.project)
end
expose :logs_path, if: -> (*) { can_read_pod_logs? } do |environment|
project_logs_path(environment.project, environment_name: environment.name)
end
expose :enable_advanced_logs_querying, if: -> (*) { can_read_pod_logs? } do |environment|
environment.deployment_platform&.elastic_stack_available?
end
......
export default [
{
environmentPath: 'some/path',
logsPath: 'some/path/logs',
project: { path_with_namespace: 'some/path', name: 'some project' },
name: 'production',
lastDeployment: { id: '123' },
......@@ -14,6 +15,7 @@ export default [
},
{
environmentPath: 'some/other/path',
logsPath: 'some/other/path/logs',
project: { path_with_namespace: 'some/other/path', name: 'some other project' },
name: 'staging',
lastDeployment: { id: '456' },
......@@ -25,6 +27,7 @@ export default [
},
{
environmentPath: 'yet/another/path',
logsPath: 'yet/another/path/logs',
project: { path_with_namespace: 'yet/another/path', name: 'yet another project' },
name: 'development',
lastDeployment: { id: '789' },
......
......@@ -3,7 +3,7 @@ import { mount } from '@vue/test-utils';
import DeployBoard from 'ee/environments/components/deploy_board_component.vue';
import { deployBoardMockData, environment } from './mock_data';
const projectPath = 'gitlab-org/gitlab-test';
const logsPath = `gitlab-org/gitlab-test/-/logs?environment_name=${environment.name}`;
describe('Deploy Board', () => {
let wrapper;
......@@ -14,8 +14,7 @@ describe('Deploy Board', () => {
deployBoardData: deployBoardMockData,
isLoading: false,
isEmpty: false,
projectPath,
environmentName: environment.name,
logsPath,
...props,
},
});
......@@ -61,8 +60,7 @@ describe('Deploy Board', () => {
deployBoardData: {},
isLoading: false,
isEmpty: true,
projectPath,
environmentName: environment.name,
logsPath,
});
wrapper.vm.$nextTick(done);
});
......@@ -81,8 +79,7 @@ describe('Deploy Board', () => {
deployBoardData: {},
isLoading: true,
isEmpty: false,
projectPath,
environmentName: environment.name,
logsPath,
});
wrapper.vm.$nextTick(done);
});
......@@ -97,8 +94,7 @@ describe('Deploy Board', () => {
wrapper = createComponent({
isLoading: false,
isEmpty: false,
projectPath,
environmentName: environment.name,
logsPath,
hasLegacyAppLabel: true,
deployBoardData: {},
});
......
......@@ -49,7 +49,7 @@ describe('Environment table', () => {
name: 'review',
size: 1,
environment_path: 'url',
project_path: 'url',
logs_path: 'url',
id: 1,
hasDeployBoard: true,
deployBoardData: deployBoardMockData,
......
......@@ -20,7 +20,7 @@ describe('Deploy Board Instance', () => {
it('should render a div with the correct css status and tooltip data', () => {
wrapper = createComponent({
projectPath: folder.project_path,
logsPath: folder.logs_path,
tooltipText: 'This is a pod',
});
......@@ -43,8 +43,7 @@ describe('Deploy Board Instance', () => {
it('should have a log path computed with a pod name as a parameter', () => {
wrapper = createComponent({
projectPath: folder.project_path,
environmentName: 'foo',
logsPath: folder.logs_path,
podName: 'tanuki-1',
});
......@@ -76,10 +75,10 @@ describe('Deploy Board Instance', () => {
wrapper.destroy();
});
it('should not be a link without a projectPath prop', done => {
it('should not be a link without a logsPath prop', done => {
wrapper = createComponent({
stable: false,
projectPath: '',
logsPath: '',
});
wrapper.vm.$nextTick(() => {
......
......@@ -140,5 +140,5 @@ export const folder = {
created_at: '2017-02-01T19:42:18.400Z',
updated_at: '2017-02-01T19:42:18.400Z',
rollout_status: {},
project_path: '/root/review-app',
logs_path: '/root/review-app/-/logs?environment_name=foo',
};
......@@ -27,7 +27,7 @@ describe EnvironmentsHelper do
'custom-metrics-available' => 'false',
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
'prometheus-alerts-available' => 'true',
'logs-path' => project_logs_path(project)
'logs-path' => project_logs_path(project, environment_name: environment.name)
)
end
end
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
describe Clusters::EnvironmentEntity do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:project, refind: true) { create(:project, group: group) }
let_it_be(:cluster) { create(:cluster_for_group, groups: [group]) }
it 'inherits from API::Entities::EnvironmentBasic' do
......@@ -16,12 +16,12 @@ describe Clusters::EnvironmentEntity do
let(:environment) { create(:environment, project: project) }
let(:request) { double('request', current_user: user, cluster: cluster) }
subject { described_class.new(environment, request: request).as_json }
before do
group.add_maintainer(user)
end
subject { described_class.new(environment, request: request).as_json }
context 'deploy board available' do
before do
allow(group).to receive(:feature_available?).and_call_original
......@@ -50,5 +50,22 @@ describe Clusters::EnvironmentEntity do
expect(subject).not_to include(:rollout_status)
end
end
context 'when pod_logs are available' do
before do
stub_licensed_features(pod_logs: true)
project.add_maintainer(user)
end
it 'exposes logs_path' do
expect(subject).to include(:logs_path)
end
end
context 'when pod_logs are not available' do
it 'does not expose logs_path' do
expect(subject).not_to include(:logs_path)
end
end
end
end
......@@ -45,5 +45,21 @@ describe EnvironmentEntity do
expect(subject).not_to include(:rollout_status)
end
end
context 'when pod_logs are available' do
before do
stub_licensed_features(pod_logs: true)
end
it 'exposes logs_path' do
expect(subject).to include(:logs_path)
end
end
context 'when pod_logs are not available' do
it 'does not expose logs_path' do
expect(subject).not_to include(:logs_path)
end
end
end
end
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