Commit c8ebde5b authored by Mike Greiling's avatar Mike Greiling

Merge branch 'sentry-cluster-list' into 'master'

Move Sentry to vue clusters_list store

See merge request gitlab-org/gitlab!35372
parents 9eb4a94c 0115bcc6
<script> <script>
import * as Sentry from '@sentry/browser';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { import {
GlDeprecatedBadge as GlBadge, GlDeprecatedBadge as GlBadge,
...@@ -88,7 +87,7 @@ export default { ...@@ -88,7 +87,7 @@ export default {
this.fetchClusters(); this.fetchClusters();
}, },
methods: { methods: {
...mapActions(['fetchClusters', 'setPage']), ...mapActions(['fetchClusters', 'reportSentryError', 'setPage']),
k8sQuantityToGb(quantity) { k8sQuantityToGb(quantity) {
if (!quantity) { if (!quantity) {
return 0; return 0;
...@@ -150,7 +149,7 @@ export default { ...@@ -150,7 +149,7 @@ export default {
}; };
} }
} catch (error) { } catch (error) {
Sentry.captureException(error); this.reportSentryError({ error, tag: 'totalMemoryAndUsageError' });
} }
return { totalMemory: null, freeSpacePercentage: null }; return { totalMemory: null, freeSpacePercentage: null };
...@@ -183,7 +182,7 @@ export default { ...@@ -183,7 +182,7 @@ export default {
}; };
} }
} catch (error) { } catch (error) {
Sentry.captureException(error); this.reportSentryError({ error, tag: 'totalCpuAndUsageError' });
} }
return { totalCpu: null, freeSpacePercentage: null }; return { totalCpu: null, freeSpacePercentage: null };
......
...@@ -16,7 +16,14 @@ const allNodesPresent = (clusters, retryCount) => { ...@@ -16,7 +16,14 @@ const allNodesPresent = (clusters, retryCount) => {
return retryCount > MAX_REQUESTS || clusters.every(cluster => cluster.nodes != null); return retryCount > MAX_REQUESTS || clusters.every(cluster => cluster.nodes != null);
}; };
export const fetchClusters = ({ state, commit }) => { export const reportSentryError = (_store, { error, tag }) => {
Sentry.withScope(scope => {
scope.setTag('javascript_clusters_list', tag);
Sentry.captureException(error);
});
};
export const fetchClusters = ({ state, commit, dispatch }) => {
let retryCount = 0; let retryCount = 0;
commit(types.SET_LOADING_NODES, true); commit(types.SET_LOADING_NODES, true);
...@@ -49,10 +56,7 @@ export const fetchClusters = ({ state, commit }) => { ...@@ -49,10 +56,7 @@ export const fetchClusters = ({ state, commit }) => {
commit(types.SET_LOADING_CLUSTERS, false); commit(types.SET_LOADING_CLUSTERS, false);
commit(types.SET_LOADING_NODES, false); commit(types.SET_LOADING_NODES, false);
Sentry.withScope(scope => { dispatch('reportSentryError', { error, tag: 'fetchClustersSuccessCallback' });
scope.setTag('javascript_clusters_list', 'fetchClustersSuccessCallback');
Sentry.captureException(error);
});
} }
}, },
errorCallback: response => { errorCallback: response => {
...@@ -62,10 +66,7 @@ export const fetchClusters = ({ state, commit }) => { ...@@ -62,10 +66,7 @@ export const fetchClusters = ({ state, commit }) => {
commit(types.SET_LOADING_NODES, false); commit(types.SET_LOADING_NODES, false);
flash(__('Clusters|An error occurred while loading clusters')); flash(__('Clusters|An error occurred while loading clusters'));
Sentry.withScope(scope => { dispatch('reportSentryError', { error: response, tag: 'fetchClustersErrorCallback' });
scope.setTag('javascript_clusters_list', 'fetchClustersErrorCallback');
Sentry.captureException(response);
});
}, },
}); });
......
...@@ -13,6 +13,28 @@ import * as Sentry from '@sentry/browser'; ...@@ -13,6 +13,28 @@ import * as Sentry from '@sentry/browser';
jest.mock('~/flash.js'); jest.mock('~/flash.js');
describe('Clusters store actions', () => { describe('Clusters store actions', () => {
let captureException;
describe('reportSentryError', () => {
beforeEach(() => {
captureException = jest.spyOn(Sentry, 'captureException');
});
afterEach(() => {
captureException.mockRestore();
});
it('should report sentry error', done => {
const sentryError = new Error('New Sentry Error');
const tag = 'sentryErrorTag';
testAction(actions.reportSentryError, { error: sentryError, tag }, {}, [], [], () => {
expect(captureException).toHaveBeenCalledWith(sentryError);
done();
});
});
});
describe('fetchClusters', () => { describe('fetchClusters', () => {
let mock; let mock;
...@@ -69,7 +91,15 @@ describe('Clusters store actions', () => { ...@@ -69,7 +91,15 @@ describe('Clusters store actions', () => {
{ type: types.SET_LOADING_CLUSTERS, payload: false }, { type: types.SET_LOADING_CLUSTERS, payload: false },
{ type: types.SET_LOADING_NODES, payload: false }, { type: types.SET_LOADING_NODES, payload: false },
], ],
[], [
{
type: 'reportSentryError',
payload: {
error: new Error('Request failed with status code 400'),
tag: 'fetchClustersErrorCallback',
},
},
],
() => { () => {
expect(flashError).toHaveBeenCalledWith(expect.stringMatching('error')); expect(flashError).toHaveBeenCalledWith(expect.stringMatching('error'));
done(); done();
...@@ -78,7 +108,6 @@ describe('Clusters store actions', () => { ...@@ -78,7 +108,6 @@ describe('Clusters store actions', () => {
}); });
describe('multiple api requests', () => { describe('multiple api requests', () => {
let captureException;
let pollRequest; let pollRequest;
let pollStop; let pollStop;
...@@ -86,7 +115,6 @@ describe('Clusters store actions', () => { ...@@ -86,7 +115,6 @@ describe('Clusters store actions', () => {
const pollHeaders = { 'poll-interval': pollInterval, ...headers }; const pollHeaders = { 'poll-interval': pollInterval, ...headers };
beforeEach(() => { beforeEach(() => {
captureException = jest.spyOn(Sentry, 'captureException');
pollRequest = jest.spyOn(Poll.prototype, 'makeRequest'); pollRequest = jest.spyOn(Poll.prototype, 'makeRequest');
pollStop = jest.spyOn(Poll.prototype, 'stop'); pollStop = jest.spyOn(Poll.prototype, 'stop');
...@@ -94,7 +122,6 @@ describe('Clusters store actions', () => { ...@@ -94,7 +122,6 @@ describe('Clusters store actions', () => {
}); });
afterEach(() => { afterEach(() => {
captureException.mockRestore();
pollRequest.mockRestore(); pollRequest.mockRestore();
pollStop.mockRestore(); pollStop.mockRestore();
}); });
...@@ -164,11 +191,18 @@ describe('Clusters store actions', () => { ...@@ -164,11 +191,18 @@ describe('Clusters store actions', () => {
{ type: types.SET_LOADING_CLUSTERS, payload: false }, { type: types.SET_LOADING_CLUSTERS, payload: false },
{ type: types.SET_LOADING_NODES, payload: false }, { type: types.SET_LOADING_NODES, payload: false },
], ],
[], [
{
type: 'reportSentryError',
payload: {
error: new Error('clusters.every is not a function'),
tag: 'fetchClustersSuccessCallback',
},
},
],
() => { () => {
expect(pollRequest).toHaveBeenCalledTimes(1); expect(pollRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(1); expect(pollStop).toHaveBeenCalledTimes(1);
expect(captureException).toHaveBeenCalledTimes(1);
done(); done();
}, },
); );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment