summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Vargas <jvargas@gitlab.com>2019-03-20 12:52:37 -0600
committerJose Vargas <jvargas@gitlab.com>2019-04-04 14:53:03 -0600
commit268b727a5c7723d2beb057fbf985ba0b854e4d9f (patch)
tree90578c683565f70c686e654b0a50fc0f3d07e587
parentf77ff0c7bdc0b3a18406bf256dc5814833c14d23 (diff)
downloadgitlab-ce-268b727a5c7723d2beb057fbf985ba0b854e4d9f.tar.gz
Modify the service to support the extra parameters
Added the logic to allow the start and end dates to be created
-rw-r--r--app/assets/javascripts/monitoring/components/dashboard.vue21
-rw-r--r--app/assets/javascripts/monitoring/constants.js2
-rw-r--r--app/assets/javascripts/monitoring/services/monitoring_service.js10
-rw-r--r--app/assets/javascripts/monitoring/utils.js32
4 files changed, 61 insertions, 4 deletions
diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue
index 917dc1b73b5..1a4bf70ab97 100644
--- a/app/assets/javascripts/monitoring/components/dashboard.vue
+++ b/app/assets/javascripts/monitoring/components/dashboard.vue
@@ -9,7 +9,8 @@ import MonitorAreaChart from './charts/area.vue';
import GraphGroup from './graph_group.vue';
import EmptyState from './empty_state.vue';
import MonitoringStore from '../stores/monitoring_store';
-import { timeWindows } from '../constants';
+import { timeWindows, msPerMinute } from '../constants';
+import { getTimeDifferenceMinutes } from '../utils';
const sidebarAnimationDuration = 150;
let sidebarMutationObserver;
@@ -107,6 +108,7 @@ export default {
this.timeWindows = timeWindows;
this.selectedTimeWindow = this.timeWindows.eightHours;
+ this.msPerMinute = msPerMinute;
},
beforeDestroy() {
if (sidebarMutationObserver) {
@@ -167,6 +169,23 @@ export default {
},
getGraphsDataWithTime(timeFrame) {
this.selectedTimeWindow = this.timeWindows[timeFrame];
+ this.state = 'loading';
+ this.showEmptyState = true;
+ const end = Date.now();
+ const timeDifferenceMinutes = getTimeDifferenceMinutes(this.selectedTimeWindow);
+ const start = new Date(end - timeDifferenceMinutes * this.msPerMinute).getTime();
+ this.service
+ .getGraphsData({
+ start,
+ end,
+ })
+ .then(data => {
+ this.store.storeMetrics(data);
+ this.showEmptyState = false;
+ })
+ .catch(() => {
+ this.state = 'unableToConnect';
+ });
},
onSidebarMutation() {
setTimeout(() => {
diff --git a/app/assets/javascripts/monitoring/constants.js b/app/assets/javascripts/monitoring/constants.js
index afa10e683ab..c01c8ab2dd6 100644
--- a/app/assets/javascripts/monitoring/constants.js
+++ b/app/assets/javascripts/monitoring/constants.js
@@ -16,3 +16,5 @@ export const timeWindows = {
threeDays: '3 days',
oneWeek: '1 week',
};
+
+export const msPerMinute = 60000;
diff --git a/app/assets/javascripts/monitoring/services/monitoring_service.js b/app/assets/javascripts/monitoring/services/monitoring_service.js
index 24b4acaf6da..9b103b8502b 100644
--- a/app/assets/javascripts/monitoring/services/monitoring_service.js
+++ b/app/assets/javascripts/monitoring/services/monitoring_service.js
@@ -32,11 +32,15 @@ export default class MonitoringService {
this.environmentsEndpoint = environmentsEndpoint;
}
- getGraphsData() {
- return backOffRequest(() => axios.get(this.metricsEndpoint))
+ getGraphsData(params = {}) {
+ return backOffRequest(() => axios.get(this.metricsEndpoint, {
+ params: {
+ ...params
+ }
+ }))
.then(resp => resp.data)
.then(response => {
- if (!response || !response.data) {
+ if (!response || !response.data || !response.success) {
throw new Error(s__('Metrics|Unexpected metrics data response from prometheus endpoint'));
}
return response.data;
diff --git a/app/assets/javascripts/monitoring/utils.js b/app/assets/javascripts/monitoring/utils.js
new file mode 100644
index 00000000000..581040e6141
--- /dev/null
+++ b/app/assets/javascripts/monitoring/utils.js
@@ -0,0 +1,32 @@
+import { timeWindows } from './constants'
+
+export const getTimeDifferenceMinutes = (timeWindow) => {
+ let timeDifferenceMinutes;
+ switch(timeWindow) {
+ case timeWindows.thirtyMinutes:
+ timeDifferenceMinutes = 30;
+ break;
+ case timeWindows.threeHours:
+ timeDifferenceMinutes = 60 * 3;
+ break;
+ case timeWindows.eightHours:
+ timeDifferenceMinutes = 60 * 8;
+ break;
+ case timeWindows.oneDay:
+ timeDifferenceMinutes = 60 * 24 * 1;
+ break;
+ case timeWindows.threeDays:
+ timeDifferenceMinutes = 60 * 24 * 3;
+ break;
+ case timeWindows.oneWeek:
+ timeDifferenceMinutes = 60 * 24 * 7 * 1;
+ break;
+ default:
+ timeDifferenceMinutes = 60 * 8;
+ break;
+ }
+
+ return timeDifferenceMinutes;
+};
+
+export default {};