2021-03-11 19:13:27 +05:30
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2019-07-07 11:18:12 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { backOff } from '~/lib/utils/common_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import statusCodes from '~/lib/utils/http_status';
|
2019-09-04 21:01:54 +05:30
|
|
|
import { __ } from '~/locale';
|
|
|
|
import { MAX_REQUESTS, CHECKING_INSTALLED, TIMEOUT } from '../constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import * as types from './mutation_types';
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
export const requestFunctionsLoading = ({ commit }) => commit(types.REQUEST_FUNCTIONS_LOADING);
|
|
|
|
export const receiveFunctionsSuccess = ({ commit }, data) =>
|
|
|
|
commit(types.RECEIVE_FUNCTIONS_SUCCESS, data);
|
2019-09-04 21:01:54 +05:30
|
|
|
export const receiveFunctionsPartial = ({ commit }, data) =>
|
|
|
|
commit(types.RECEIVE_FUNCTIONS_PARTIAL, data);
|
|
|
|
export const receiveFunctionsTimeout = ({ commit }, data) =>
|
|
|
|
commit(types.RECEIVE_FUNCTIONS_TIMEOUT, data);
|
|
|
|
export const receiveFunctionsNoDataSuccess = ({ commit }, data) =>
|
|
|
|
commit(types.RECEIVE_FUNCTIONS_NODATA_SUCCESS, data);
|
2019-07-07 11:18:12 +05:30
|
|
|
export const receiveFunctionsError = ({ commit }, error) =>
|
|
|
|
commit(types.RECEIVE_FUNCTIONS_ERROR, error);
|
|
|
|
|
|
|
|
export const receiveMetricsSuccess = ({ commit }, data) =>
|
|
|
|
commit(types.RECEIVE_METRICS_SUCCESS, data);
|
|
|
|
export const receiveMetricsNoPrometheus = ({ commit }) =>
|
|
|
|
commit(types.RECEIVE_METRICS_NO_PROMETHEUS);
|
|
|
|
export const receiveMetricsNoDataSuccess = ({ commit }, data) =>
|
|
|
|
commit(types.RECEIVE_METRICS_NODATA_SUCCESS, data);
|
|
|
|
export const receiveMetricsError = ({ commit }, error) =>
|
|
|
|
commit(types.RECEIVE_METRICS_ERROR, error);
|
|
|
|
|
|
|
|
export const fetchFunctions = ({ dispatch }, { functionsPath }) => {
|
|
|
|
let retryCount = 0;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const functionsPartiallyFetched = (data) => {
|
2019-09-04 21:01:54 +05:30
|
|
|
if (data.functions !== null && data.functions.length) {
|
|
|
|
dispatch('receiveFunctionsPartial', data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
dispatch('requestFunctionsLoading');
|
|
|
|
|
|
|
|
backOff((next, stop) => {
|
|
|
|
axios
|
|
|
|
.get(functionsPath)
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((response) => {
|
2019-09-04 21:01:54 +05:30
|
|
|
if (response.data.knative_installed === CHECKING_INSTALLED) {
|
2019-07-07 11:18:12 +05:30
|
|
|
retryCount += 1;
|
|
|
|
if (retryCount < MAX_REQUESTS) {
|
2019-09-04 21:01:54 +05:30
|
|
|
functionsPartiallyFetched(response.data);
|
2019-07-07 11:18:12 +05:30
|
|
|
next();
|
|
|
|
} else {
|
2019-09-04 21:01:54 +05:30
|
|
|
stop(TIMEOUT);
|
2019-07-07 11:18:12 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stop(response.data);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(stop);
|
|
|
|
})
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((data) => {
|
2019-09-04 21:01:54 +05:30
|
|
|
if (data === TIMEOUT) {
|
|
|
|
dispatch('receiveFunctionsTimeout');
|
|
|
|
createFlash(__('Loading functions timed out. Please reload the page to try again.'));
|
|
|
|
} else if (data.functions !== null && data.functions.length) {
|
2019-07-07 11:18:12 +05:30
|
|
|
dispatch('receiveFunctionsSuccess', data);
|
|
|
|
} else {
|
2019-09-04 21:01:54 +05:30
|
|
|
dispatch('receiveFunctionsNoDataSuccess', data);
|
2019-07-07 11:18:12 +05:30
|
|
|
}
|
|
|
|
})
|
2021-03-08 18:12:59 +05:30
|
|
|
.catch((error) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
dispatch('receiveFunctionsError', error);
|
|
|
|
createFlash(error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const fetchMetrics = ({ dispatch }, { metricsPath, hasPrometheus }) => {
|
|
|
|
let retryCount = 0;
|
|
|
|
|
|
|
|
if (!hasPrometheus) {
|
|
|
|
dispatch('receiveMetricsNoPrometheus');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
backOff((next, stop) => {
|
|
|
|
axios
|
|
|
|
.get(metricsPath)
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((response) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
if (response.status === statusCodes.NO_CONTENT) {
|
|
|
|
retryCount += 1;
|
|
|
|
if (retryCount < MAX_REQUESTS) {
|
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
dispatch('receiveMetricsNoDataSuccess');
|
|
|
|
stop(null);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stop(response.data);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(stop);
|
|
|
|
})
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((data) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
if (data === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const updatedMetric = data.metrics;
|
2021-03-08 18:12:59 +05:30
|
|
|
const queries = data.metrics.queries.map((query) => ({
|
2019-07-07 11:18:12 +05:30
|
|
|
...query,
|
2021-03-08 18:12:59 +05:30
|
|
|
result: query.result.map((result) => ({
|
2019-07-07 11:18:12 +05:30
|
|
|
...result,
|
|
|
|
values: result.values.map(([timestamp, value]) => ({
|
|
|
|
time: new Date(timestamp * 1000).toISOString(),
|
|
|
|
value: Number(value),
|
|
|
|
})),
|
|
|
|
})),
|
|
|
|
}));
|
|
|
|
|
|
|
|
updatedMetric.queries = queries;
|
|
|
|
dispatch('receiveMetricsSuccess', updatedMetric);
|
|
|
|
})
|
2021-03-08 18:12:59 +05:30
|
|
|
.catch((error) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
dispatch('receiveMetricsError', error);
|
|
|
|
createFlash(error);
|
|
|
|
});
|
|
|
|
};
|