Welcome to mirror list, hosted at ThFree Co, Russian Federation.

actions.js « store « serverless « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 826501c90224ceba3e7c2bda676f40e52188d053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import * as types from './mutation_types';
import axios from '~/lib/utils/axios_utils';
import statusCodes from '~/lib/utils/http_status';
import { backOff } from '~/lib/utils/common_utils';
import createFlash from '~/flash';
import { MAX_REQUESTS } from '../constants';

export const requestFunctionsLoading = ({ commit }) => commit(types.REQUEST_FUNCTIONS_LOADING);
export const receiveFunctionsSuccess = ({ commit }, data) =>
  commit(types.RECEIVE_FUNCTIONS_SUCCESS, data);
export const receiveFunctionsNoDataSuccess = ({ commit }) =>
  commit(types.RECEIVE_FUNCTIONS_NODATA_SUCCESS);
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;

  dispatch('requestFunctionsLoading');

  backOff((next, stop) => {
    axios
      .get(functionsPath)
      .then(response => {
        if (response.status === statusCodes.NO_CONTENT) {
          retryCount += 1;
          if (retryCount < MAX_REQUESTS) {
            next();
          } else {
            stop(null);
          }
        } else {
          stop(response.data);
        }
      })
      .catch(stop);
  })
    .then(data => {
      if (data !== null) {
        dispatch('receiveFunctionsSuccess', data);
      } else {
        dispatch('receiveFunctionsNoDataSuccess');
      }
    })
    .catch(error => {
      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)
      .then(response => {
        if (response.status === statusCodes.NO_CONTENT) {
          retryCount += 1;
          if (retryCount < MAX_REQUESTS) {
            next();
          } else {
            dispatch('receiveMetricsNoDataSuccess');
            stop(null);
          }
        } else {
          stop(response.data);
        }
      })
      .catch(stop);
  })
    .then(data => {
      if (data === null) {
        return;
      }

      const updatedMetric = data.metrics;
      const queries = data.metrics.queries.map(query => ({
        ...query,
        result: query.result.map(result => ({
          ...result,
          values: result.values.map(([timestamp, value]) => ({
            time: new Date(timestamp * 1000).toISOString(),
            value: Number(value),
          })),
        })),
      }));

      updatedMetric.queries = queries;
      dispatch('receiveMetricsSuccess', updatedMetric);
    })
    .catch(error => {
      dispatch('receiveMetricsError', error);
      createFlash(error);
    });
};

// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};