Commit e622d585 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'ak/url' into 'master'

Pass logs url from backend to frontend

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