2020-05-26 20:08:11 -04:00
|
|
|
<script>
|
|
|
|
import {
|
2020-07-09 05:09:27 -04:00
|
|
|
GlButton,
|
2020-09-14 08:09:34 -04:00
|
|
|
GlDropdown,
|
2020-05-26 20:08:11 -04:00
|
|
|
GlLoadingIcon,
|
2020-09-14 14:09:48 -04:00
|
|
|
GlDropdownItem,
|
2020-09-14 20:09:47 -04:00
|
|
|
GlDropdownSectionHeader,
|
2020-05-26 20:08:11 -04:00
|
|
|
GlSearchBoxByType,
|
|
|
|
GlModalDirective,
|
|
|
|
GlTooltipDirective,
|
2020-08-24 11:10:11 -04:00
|
|
|
GlIcon,
|
2020-05-26 20:08:11 -04:00
|
|
|
} from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { debounce } from 'lodash';
|
|
|
|
import { mapActions, mapState, mapGetters } from 'vuex';
|
2020-05-26 20:08:11 -04:00
|
|
|
import invalidUrl from '~/lib/utils/invalid_url';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { mergeUrlParams, redirectTo } from '~/lib/utils/url_utility';
|
2021-03-26 08:09:15 -04:00
|
|
|
import { s__ } from '~/locale';
|
2020-05-26 20:08:11 -04:00
|
|
|
import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue';
|
|
|
|
|
2021-02-01 10:08:56 -05:00
|
|
|
import { timeRanges } from '~/vue_shared/constants';
|
|
|
|
import { timezones } from '../format_date';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { timeRangeToUrl } from '../utils';
|
|
|
|
import ActionsMenu from './dashboard_actions_menu.vue';
|
2020-05-26 20:08:11 -04:00
|
|
|
import DashboardsDropdown from './dashboards_dropdown.vue';
|
2020-07-07 08:09:16 -04:00
|
|
|
import RefreshButton from './refresh_button.vue';
|
2020-05-26 20:08:11 -04:00
|
|
|
|
|
|
|
export default {
|
2021-03-26 08:09:15 -04:00
|
|
|
i18n: {
|
|
|
|
metricsSettings: s__('Metrics|Metrics Settings'),
|
|
|
|
},
|
2020-05-26 20:08:11 -04:00
|
|
|
components: {
|
2020-08-24 11:10:11 -04:00
|
|
|
GlIcon,
|
2020-07-09 05:09:27 -04:00
|
|
|
GlButton,
|
2020-09-14 08:09:34 -04:00
|
|
|
GlDropdown,
|
2020-05-26 20:08:11 -04:00
|
|
|
GlLoadingIcon,
|
2020-09-14 14:09:48 -04:00
|
|
|
GlDropdownItem,
|
2020-09-14 20:09:47 -04:00
|
|
|
GlDropdownSectionHeader,
|
2020-08-12 11:10:02 -04:00
|
|
|
|
2020-05-26 20:08:11 -04:00
|
|
|
GlSearchBoxByType,
|
|
|
|
|
|
|
|
DateTimePicker,
|
|
|
|
DashboardsDropdown,
|
2020-07-07 08:09:16 -04:00
|
|
|
RefreshButton,
|
2020-08-11 08:09:55 -04:00
|
|
|
|
|
|
|
ActionsMenu,
|
2020-05-26 20:08:11 -04:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlModal: GlModalDirective,
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
defaultBranch: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
rearrangePanelsAvailable: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
customMetricsAvailable: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
customMetricsPath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: invalidUrl,
|
|
|
|
},
|
|
|
|
validateQueryPath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: invalidUrl,
|
|
|
|
},
|
|
|
|
isRearrangingPanels: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
selectedTimeRange: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState('monitoringDashboard', [
|
2020-07-15 05:09:34 -04:00
|
|
|
'emptyState',
|
2020-05-26 20:08:11 -04:00
|
|
|
'environmentsLoading',
|
|
|
|
'currentEnvironmentName',
|
2020-06-04 05:08:01 -04:00
|
|
|
'dashboardTimezone',
|
2020-07-08 11:09:24 -04:00
|
|
|
'projectPath',
|
2020-07-09 05:09:27 -04:00
|
|
|
'canAccessOperationsSettings',
|
|
|
|
'operationsSettingsPath',
|
2020-07-15 17:09:26 -04:00
|
|
|
'currentDashboard',
|
2020-08-10 08:09:55 -04:00
|
|
|
'externalDashboardUrl',
|
2020-05-26 20:08:11 -04:00
|
|
|
]),
|
|
|
|
...mapGetters('monitoringDashboard', ['selectedDashboard', 'filteredEnvironments']),
|
2020-07-15 05:09:34 -04:00
|
|
|
shouldShowEmptyState() {
|
|
|
|
return Boolean(this.emptyState);
|
|
|
|
},
|
2020-05-26 20:08:11 -04:00
|
|
|
shouldShowEnvironmentsDropdownNoMatchedMsg() {
|
|
|
|
return !this.environmentsLoading && this.filteredEnvironments.length === 0;
|
|
|
|
},
|
|
|
|
addingMetricsAvailable() {
|
|
|
|
return (
|
|
|
|
this.customMetricsAvailable &&
|
2020-07-15 05:09:34 -04:00
|
|
|
!this.shouldShowEmptyState &&
|
2020-05-26 20:08:11 -04:00
|
|
|
// Custom metrics only avaialble on system dashboards because
|
|
|
|
// they are stored in the database. This can be improved. See:
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/issues/28241
|
2020-08-11 08:09:55 -04:00
|
|
|
this.selectedDashboard?.out_of_the_box_dashboard
|
2020-05-26 20:08:11 -04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
showRearrangePanelsBtn() {
|
2020-07-15 05:09:34 -04:00
|
|
|
return !this.shouldShowEmptyState && this.rearrangePanelsAvailable;
|
2020-05-26 20:08:11 -04:00
|
|
|
},
|
2020-08-12 11:10:02 -04:00
|
|
|
environmentDropdownText() {
|
|
|
|
return this.currentEnvironmentName ?? '';
|
|
|
|
},
|
2020-06-04 05:08:01 -04:00
|
|
|
displayUtc() {
|
|
|
|
return this.dashboardTimezone === timezones.UTC;
|
|
|
|
},
|
2020-07-09 05:09:27 -04:00
|
|
|
shouldShowSettingsButton() {
|
|
|
|
return this.canAccessOperationsSettings && this.operationsSettingsPath;
|
|
|
|
},
|
2020-08-12 08:10:25 -04:00
|
|
|
isOOTBDashboard() {
|
|
|
|
return this.selectedDashboard?.out_of_the_box_dashboard ?? false;
|
|
|
|
},
|
2020-05-26 20:08:11 -04:00
|
|
|
},
|
|
|
|
methods: {
|
2020-08-11 08:09:55 -04:00
|
|
|
...mapActions('monitoringDashboard', ['filterEnvironments']),
|
2020-05-26 20:08:11 -04:00
|
|
|
selectDashboard(dashboard) {
|
2020-07-15 17:09:26 -04:00
|
|
|
// Once the sidebar See metrics link is updated to the new URL,
|
|
|
|
// this sort of hardcoding will not be necessary.
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/issues/229277
|
|
|
|
const baseURL = `${this.projectPath}/-/metrics`;
|
|
|
|
const dashboardPath = encodeURIComponent(
|
|
|
|
dashboard.out_of_the_box_dashboard ? dashboard.path : dashboard.display_name,
|
|
|
|
);
|
|
|
|
redirectTo(`${baseURL}/${dashboardPath}`);
|
2020-05-26 20:08:11 -04:00
|
|
|
},
|
|
|
|
debouncedEnvironmentsSearch: debounce(function environmentsSearchOnInput(searchTerm) {
|
|
|
|
this.filterEnvironments(searchTerm);
|
|
|
|
}, 500),
|
|
|
|
onDateTimePickerInput(timeRange) {
|
|
|
|
redirectTo(timeRangeToUrl(timeRange));
|
|
|
|
},
|
|
|
|
onDateTimePickerInvalid() {
|
|
|
|
this.$emit('dateTimePickerInvalid');
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleRearrangingPanels() {
|
|
|
|
this.$emit('setRearrangingPanels', !this.isRearrangingPanels);
|
|
|
|
},
|
2020-07-15 17:09:26 -04:00
|
|
|
getEnvironmentPath(environment) {
|
|
|
|
// Once the sidebar See metrics link is updated to the new URL,
|
|
|
|
// this sort of hardcoding will not be necessary.
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/issues/229277
|
|
|
|
const baseURL = `${this.projectPath}/-/metrics`;
|
|
|
|
const dashboardPath = encodeURIComponent(this.currentDashboard || '');
|
|
|
|
// The environment_metrics_spec.rb requires the URL to not have
|
|
|
|
// slashes. Hence, this additional check.
|
|
|
|
const url = dashboardPath ? `${baseURL}/${dashboardPath}` : baseURL;
|
|
|
|
return mergeUrlParams({ environment }, url);
|
|
|
|
},
|
2020-05-26 20:08:11 -04:00
|
|
|
},
|
|
|
|
timeRanges,
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div ref="prometheusGraphsHeader">
|
2020-07-08 11:09:24 -04:00
|
|
|
<div class="mb-2 mr-2 d-flex d-sm-block">
|
2020-05-26 20:08:11 -04:00
|
|
|
<dashboards-dropdown
|
|
|
|
id="monitor-dashboards-dropdown"
|
|
|
|
data-qa-selector="dashboards_filter_dropdown"
|
|
|
|
class="flex-grow-1"
|
|
|
|
toggle-class="dropdown-menu-toggle"
|
|
|
|
:default-branch="defaultBranch"
|
|
|
|
@selectDashboard="selectDashboard"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2020-07-08 11:09:24 -04:00
|
|
|
<span aria-hidden="true" class="gl-pl-3 border-left gl-mb-3 d-none d-sm-block"></span>
|
|
|
|
|
2020-05-26 20:08:11 -04:00
|
|
|
<div class="mb-2 pr-2 d-flex d-sm-block">
|
2020-09-14 08:09:34 -04:00
|
|
|
<gl-dropdown
|
2020-05-26 20:08:11 -04:00
|
|
|
id="monitor-environments-dropdown"
|
|
|
|
ref="monitorEnvironmentsDropdown"
|
|
|
|
class="flex-grow-1"
|
|
|
|
data-qa-selector="environments_dropdown"
|
|
|
|
toggle-class="dropdown-menu-toggle"
|
|
|
|
menu-class="monitor-environment-dropdown-menu"
|
2020-08-12 11:10:02 -04:00
|
|
|
:text="environmentDropdownText"
|
2020-05-26 20:08:11 -04:00
|
|
|
>
|
|
|
|
<div class="d-flex flex-column overflow-hidden">
|
2020-09-14 20:09:47 -04:00
|
|
|
<gl-dropdown-section-header>{{ __('Environment') }}</gl-dropdown-section-header>
|
2020-10-15 14:08:43 -04:00
|
|
|
<gl-search-box-by-type @input="debouncedEnvironmentsSearch" />
|
2020-08-12 11:10:02 -04:00
|
|
|
|
2021-07-07 05:08:35 -04:00
|
|
|
<gl-loading-icon v-if="environmentsLoading" size="sm" :inline="true" />
|
2020-05-26 20:08:11 -04:00
|
|
|
<div v-else class="flex-fill overflow-auto">
|
2020-09-14 14:09:48 -04:00
|
|
|
<gl-dropdown-item
|
2020-05-26 20:08:11 -04:00
|
|
|
v-for="environment in filteredEnvironments"
|
|
|
|
:key="environment.id"
|
2020-08-12 11:10:02 -04:00
|
|
|
:is-check-item="true"
|
|
|
|
:is-checked="environment.name === currentEnvironmentName"
|
2020-07-15 17:09:26 -04:00
|
|
|
:href="getEnvironmentPath(environment.id)"
|
2020-05-26 20:08:11 -04:00
|
|
|
>
|
2020-08-12 11:10:02 -04:00
|
|
|
{{ environment.name }}
|
2020-09-14 14:09:48 -04:00
|
|
|
</gl-dropdown-item>
|
2020-05-26 20:08:11 -04:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-show="shouldShowEnvironmentsDropdownNoMatchedMsg"
|
|
|
|
ref="monitorEnvironmentsDropdownMsg"
|
|
|
|
class="text-secondary no-matches-message"
|
|
|
|
>
|
|
|
|
{{ __('No matching results') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-09-14 08:09:34 -04:00
|
|
|
</gl-dropdown>
|
2020-05-26 20:08:11 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-2 pr-2 d-flex d-sm-block">
|
|
|
|
<date-time-picker
|
|
|
|
ref="dateTimePicker"
|
|
|
|
class="flex-grow-1 show-last-dropdown"
|
|
|
|
data-qa-selector="range_picker_dropdown"
|
|
|
|
:value="selectedTimeRange"
|
|
|
|
:options="$options.timeRanges"
|
2020-06-04 05:08:01 -04:00
|
|
|
:utc="displayUtc"
|
2020-05-26 20:08:11 -04:00
|
|
|
@input="onDateTimePickerInput"
|
|
|
|
@invalid="onDateTimePickerInvalid"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-2 pr-2 d-flex d-sm-block">
|
2020-07-07 08:09:16 -04:00
|
|
|
<refresh-button />
|
2020-05-26 20:08:11 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex-grow-1"></div>
|
|
|
|
|
|
|
|
<div class="d-sm-flex">
|
|
|
|
<div v-if="showRearrangePanelsBtn" class="mb-2 mr-2 d-flex">
|
2020-08-07 17:10:07 -04:00
|
|
|
<gl-button
|
2020-05-26 20:08:11 -04:00
|
|
|
:pressed="isRearrangingPanels"
|
|
|
|
variant="default"
|
|
|
|
class="flex-grow-1 js-rearrange-button"
|
|
|
|
@click="toggleRearrangingPanels"
|
|
|
|
>
|
|
|
|
{{ __('Arrange charts') }}
|
2020-08-07 17:10:07 -04:00
|
|
|
</gl-button>
|
2020-05-26 20:08:11 -04:00
|
|
|
</div>
|
|
|
|
|
2020-06-30 08:08:57 -04:00
|
|
|
<div
|
|
|
|
v-if="externalDashboardUrl && externalDashboardUrl.length"
|
|
|
|
class="mb-2 mr-2 d-flex d-sm-block"
|
|
|
|
>
|
2020-08-07 17:10:07 -04:00
|
|
|
<gl-button
|
2020-05-26 20:08:11 -04:00
|
|
|
class="flex-grow-1 js-external-dashboard-link"
|
2020-08-07 17:10:07 -04:00
|
|
|
variant="info"
|
|
|
|
category="primary"
|
2020-05-26 20:08:11 -04:00
|
|
|
:href="externalDashboardUrl"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2020-08-24 11:10:11 -04:00
|
|
|
{{ __('View full dashboard') }} <gl-icon name="external-link" />
|
2020-08-07 17:10:07 -04:00
|
|
|
</gl-button>
|
2020-05-26 20:08:11 -04:00
|
|
|
</div>
|
2020-07-08 11:09:24 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
<div class="gl-mb-3 gl-mr-3 d-flex d-sm-block">
|
|
|
|
<actions-menu
|
|
|
|
:adding-metrics-available="addingMetricsAvailable"
|
|
|
|
:custom-metrics-path="customMetricsPath"
|
|
|
|
:validate-query-path="validateQueryPath"
|
|
|
|
:default-branch="defaultBranch"
|
2020-08-12 08:10:25 -04:00
|
|
|
:is-ootb-dashboard="isOOTBDashboard"
|
2020-08-11 08:09:55 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2020-07-08 11:09:24 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
<template v-if="shouldShowSettingsButton">
|
|
|
|
<span aria-hidden="true" class="gl-pl-3 border-left gl-mb-3 d-none d-sm-block"></span>
|
2020-07-09 05:09:27 -04:00
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
<div class="mb-2 mr-2 d-flex d-sm-block">
|
|
|
|
<gl-button
|
|
|
|
v-gl-tooltip
|
|
|
|
data-testid="metrics-settings-button"
|
|
|
|
icon="settings"
|
|
|
|
:href="operationsSettingsPath"
|
2021-03-26 08:09:15 -04:00
|
|
|
:title="$options.i18n.metricsSettings"
|
|
|
|
:aria-label="$options.i18n.metricsSettings"
|
2020-07-09 05:09:27 -04:00
|
|
|
/>
|
2020-08-11 08:09:55 -04:00
|
|
|
</div>
|
|
|
|
</template>
|
2020-05-26 20:08:11 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|