2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
2018-05-09 12:01:36 +05:30
|
|
|
import _ from 'underscore';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { s__ } from '~/locale';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2018-05-09 12:01:36 +05:30
|
|
|
import Flash from '../../flash';
|
|
|
|
import MonitoringService from '../services/monitoring_service';
|
|
|
|
import GraphGroup from './graph_group.vue';
|
|
|
|
import Graph from './graph.vue';
|
|
|
|
import EmptyState from './empty_state.vue';
|
|
|
|
import MonitoringStore from '../stores/monitoring_store';
|
|
|
|
import eventHub from '../event_hub';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Graph,
|
|
|
|
GraphGroup,
|
|
|
|
EmptyState,
|
2018-11-08 19:23:39 +05:30
|
|
|
Icon,
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
hasMetrics: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
showLegend: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
2018-03-27 19:54:05 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
showPanels: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
forceSmallGraph: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
documentationPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
settingsPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
clustersPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
tagsPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
projectPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
metricsEndpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
deploymentEndpoint: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
emptyGettingStartedSvgPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
emptyLoadingSvgPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
emptyNoDataSvgPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
emptyUnableToConnectSvgPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
environmentsEndpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
currentEnvironmentName: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
store: new MonitoringStore(),
|
|
|
|
state: 'gettingStarted',
|
|
|
|
showEmptyState: true,
|
|
|
|
updateAspectRatio: false,
|
|
|
|
updatedAspectRatios: 0,
|
|
|
|
hoverData: {},
|
|
|
|
resizeThrottled: {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.service = new MonitoringService({
|
|
|
|
metricsEndpoint: this.metricsEndpoint,
|
|
|
|
deploymentEndpoint: this.deploymentEndpoint,
|
2018-11-08 19:23:39 +05:30
|
|
|
environmentsEndpoint: this.environmentsEndpoint,
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
eventHub.$on('toggleAspectRatio', this.toggleAspectRatio);
|
|
|
|
eventHub.$on('hoverChanged', this.hoverChanged);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('toggleAspectRatio', this.toggleAspectRatio);
|
|
|
|
eventHub.$off('hoverChanged', this.hoverChanged);
|
|
|
|
window.removeEventListener('resize', this.resizeThrottled, false);
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.resizeThrottled = _.throttle(this.resize, 600);
|
|
|
|
if (!this.hasMetrics) {
|
|
|
|
this.state = 'gettingStarted';
|
|
|
|
} else {
|
|
|
|
this.getGraphsData();
|
|
|
|
window.addEventListener('resize', this.resizeThrottled, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getGraphsData() {
|
|
|
|
this.state = 'loading';
|
|
|
|
Promise.all([
|
|
|
|
this.service.getGraphsData().then(data => this.store.storeMetrics(data)),
|
|
|
|
this.service
|
|
|
|
.getDeploymentData()
|
|
|
|
.then(data => this.store.storeDeploymentData(data))
|
2018-11-08 19:23:39 +05:30
|
|
|
.catch(() => Flash(s__('Metrics|There was an error getting deployment information.'))),
|
|
|
|
this.service
|
|
|
|
.getEnvironmentsData()
|
|
|
|
.then((data) => this.store.storeEnvironmentsData(data))
|
|
|
|
.catch(() => Flash(s__('Metrics|There was an error getting environments information.'))),
|
2018-05-09 12:01:36 +05:30
|
|
|
])
|
|
|
|
.then(() => {
|
|
|
|
if (this.store.groups.length < 1) {
|
|
|
|
this.state = 'noData';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.showEmptyState = false;
|
|
|
|
})
|
2018-11-18 11:00:15 +05:30
|
|
|
.then(this.resize)
|
2018-05-09 12:01:36 +05:30
|
|
|
.catch(() => {
|
|
|
|
this.state = 'unableToConnect';
|
|
|
|
});
|
|
|
|
},
|
|
|
|
resize() {
|
|
|
|
this.updateAspectRatio = true;
|
|
|
|
},
|
|
|
|
toggleAspectRatio() {
|
2018-11-08 19:23:39 +05:30
|
|
|
this.updatedAspectRatios += 1;
|
2018-05-09 12:01:36 +05:30
|
|
|
if (this.store.getMetricsCount() === this.updatedAspectRatios) {
|
|
|
|
this.updateAspectRatio = !this.updateAspectRatio;
|
|
|
|
this.updatedAspectRatios = 0;
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
hoverChanged(data) {
|
|
|
|
this.hoverData = data;
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
v-if="!showEmptyState"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="prometheus-graphs prepend-top-10"
|
2018-03-17 18:26:18 +05:30
|
|
|
>
|
2018-11-08 19:23:39 +05:30
|
|
|
<div class="environments d-flex align-items-center">
|
|
|
|
{{ s__('Metrics|Environment') }}
|
|
|
|
<div class="dropdown prepend-left-10">
|
|
|
|
<button
|
|
|
|
class="dropdown-menu-toggle"
|
|
|
|
data-toggle="dropdown"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
{{ currentEnvironmentName }}
|
|
|
|
</span>
|
|
|
|
<icon
|
|
|
|
name="chevron-down"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
<div class="dropdown-menu dropdown-menu-selectable dropdown-menu-drop-up">
|
|
|
|
<ul>
|
|
|
|
<li
|
|
|
|
v-for="environment in store.environmentsData"
|
|
|
|
:key="environment.latest.id"
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
:href="environment.latest.metrics_path"
|
|
|
|
:class="{ 'is-active': environment.latest.name == currentEnvironmentName }"
|
|
|
|
class="dropdown-item"
|
|
|
|
>
|
|
|
|
{{ environment.latest.name }}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-03-17 18:26:18 +05:30
|
|
|
<graph-group
|
|
|
|
v-for="(groupData, index) in store.groups"
|
|
|
|
:key="index"
|
|
|
|
:name="groupData.group"
|
2018-03-27 19:54:05 +05:30
|
|
|
:show-panels="showPanels"
|
2018-03-17 18:26:18 +05:30
|
|
|
>
|
|
|
|
<graph
|
|
|
|
v-for="(graphData, index) in groupData.metrics"
|
|
|
|
:key="index"
|
|
|
|
:graph-data="graphData"
|
|
|
|
:hover-data="hoverData"
|
|
|
|
:update-aspect-ratio="updateAspectRatio"
|
|
|
|
:deployment-data="store.deploymentData"
|
|
|
|
:project-path="projectPath"
|
|
|
|
:tags-path="tagsPath"
|
2018-03-27 19:54:05 +05:30
|
|
|
:show-legend="showLegend"
|
|
|
|
:small-graph="forceSmallGraph"
|
2018-11-08 19:23:39 +05:30
|
|
|
>
|
|
|
|
<!-- EE content -->
|
|
|
|
{{ null }}
|
|
|
|
</graph>
|
2018-03-17 18:26:18 +05:30
|
|
|
</graph-group>
|
|
|
|
</div>
|
|
|
|
<empty-state
|
|
|
|
v-else
|
|
|
|
:selected-state="state"
|
|
|
|
:documentation-path="documentationPath"
|
|
|
|
:settings-path="settingsPath"
|
|
|
|
:clusters-path="clustersPath"
|
|
|
|
:empty-getting-started-svg-path="emptyGettingStartedSvgPath"
|
|
|
|
:empty-loading-svg-path="emptyLoadingSvgPath"
|
2018-05-09 12:01:36 +05:30
|
|
|
:empty-no-data-svg-path="emptyNoDataSvgPath"
|
2018-03-17 18:26:18 +05:30
|
|
|
:empty-unable-to-connect-svg-path="emptyUnableToConnectSvgPath"
|
|
|
|
/>
|
|
|
|
</template>
|