diff options
Diffstat (limited to 'app/assets/javascripts/clusters_list/store/actions.js')
-rw-r--r-- | app/assets/javascripts/clusters_list/store/actions.js | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/app/assets/javascripts/clusters_list/store/actions.js b/app/assets/javascripts/clusters_list/store/actions.js index 919625f69b4..5245c307c8c 100644 --- a/app/assets/javascripts/clusters_list/store/actions.js +++ b/app/assets/javascripts/clusters_list/store/actions.js @@ -2,10 +2,23 @@ import Poll from '~/lib/utils/poll'; import axios from '~/lib/utils/axios_utils'; import flash from '~/flash'; import { __ } from '~/locale'; +import { MAX_REQUESTS } from '../constants'; import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; +import * as Sentry from '@sentry/browser'; import * as types from './mutation_types'; +const allNodesPresent = (clusters, retryCount) => { + /* + Nodes are coming from external Kubernetes clusters. + They may fail for reasons GitLab cannot control. + MAX_REQUESTS will ensure this poll stops at some point. + */ + return retryCount > MAX_REQUESTS || clusters.every(cluster => cluster.nodes != null); +}; + export const fetchClusters = ({ state, commit }) => { + let retryCount = 0; + const poll = new Poll({ resource: { fetchClusters: paginatedEndPoint => axios.get(paginatedEndPoint), @@ -13,16 +26,40 @@ export const fetchClusters = ({ state, commit }) => { data: `${state.endpoint}?page=${state.page}`, method: 'fetchClusters', successCallback: ({ data, headers }) => { - if (data.clusters) { - const normalizedHeaders = normalizeHeaders(headers); - const paginationInformation = parseIntPagination(normalizedHeaders); + retryCount += 1; + + try { + if (data.clusters) { + const normalizedHeaders = normalizeHeaders(headers); + const paginationInformation = parseIntPagination(normalizedHeaders); + + commit(types.SET_CLUSTERS_DATA, { data, paginationInformation }); + commit(types.SET_LOADING_STATE, false); - commit(types.SET_CLUSTERS_DATA, { data, paginationInformation }); - commit(types.SET_LOADING_STATE, false); + if (allNodesPresent(data.clusters, retryCount)) { + poll.stop(); + } + } + } catch (error) { poll.stop(); + + Sentry.withScope(scope => { + scope.setTag('javascript_clusters_list', 'fetchClustersSuccessCallback'); + Sentry.captureException(error); + }); } }, - errorCallback: () => flash(__('An error occurred while loading clusters')), + errorCallback: response => { + poll.stop(); + + commit(types.SET_LOADING_STATE, false); + flash(__('Clusters|An error occurred while loading clusters')); + + Sentry.withScope(scope => { + scope.setTag('javascript_clusters_list', 'fetchClustersErrorCallback'); + Sentry.captureException(response); + }); + }, }); poll.makeRequest(); |