Commit b901715d authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '34157-snowplow-custom-events-for-monitor-apm' into 'master'

Snowplow custom events for Monitor: APM

See merge request gitlab-org/gitlab!19455
parents ff90095e 12042405
import Tracking from '~/tracking';
const trackDashboardLoad = ({ label, value }) =>
Tracking.event(document.body.dataset.page, 'dashboard_fetch', {
label,
property: 'count',
value,
});
export default trackDashboardLoad;
import * as types from './mutation_types'; import * as types from './mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
import trackDashboardLoad from '../monitoring_tracking_helper';
import statusCodes from '../../lib/utils/http_status'; import statusCodes from '../../lib/utils/http_status';
import { backOff } from '../../lib/utils/common_utils'; import { backOff } from '../../lib/utils/common_utils';
import { s__, __ } from '../../locale'; import { s__, __ } from '../../locale';
...@@ -45,7 +46,7 @@ export const requestMetricsDashboard = ({ commit }) => { ...@@ -45,7 +46,7 @@ export const requestMetricsDashboard = ({ commit }) => {
export const receiveMetricsDashboardSuccess = ({ commit, dispatch }, { response, params }) => { export const receiveMetricsDashboardSuccess = ({ commit, dispatch }, { response, params }) => {
commit(types.SET_ALL_DASHBOARDS, response.all_dashboards); commit(types.SET_ALL_DASHBOARDS, response.all_dashboards);
commit(types.RECEIVE_METRICS_DATA_SUCCESS, response.dashboard.panel_groups); commit(types.RECEIVE_METRICS_DATA_SUCCESS, response.dashboard.panel_groups);
dispatch('fetchPrometheusMetrics', params); return dispatch('fetchPrometheusMetrics', params);
}; };
export const receiveMetricsDashboardFailure = ({ commit }, error) => { export const receiveMetricsDashboardFailure = ({ commit }, error) => {
commit(types.RECEIVE_METRICS_DATA_FAILURE, error); commit(types.RECEIVE_METRICS_DATA_FAILURE, error);
...@@ -83,10 +84,12 @@ export const fetchDashboard = ({ state, dispatch }, params) => { ...@@ -83,10 +84,12 @@ export const fetchDashboard = ({ state, dispatch }, params) => {
return backOffRequest(() => axios.get(state.dashboardEndpoint, { params })) return backOffRequest(() => axios.get(state.dashboardEndpoint, { params }))
.then(resp => resp.data) .then(resp => resp.data)
.then(response => { .then(response => dispatch('receiveMetricsDashboardSuccess', { response, params }))
dispatch('receiveMetricsDashboardSuccess', { .then(() => {
response, const dashboardType = state.currentDashboard === '' ? 'default' : 'custom';
params, return trackDashboardLoad({
label: `${dashboardType}_metrics_dashboard`,
value: state.metricsWithData.length,
}); });
}) })
.catch(error => { .catch(error => {
......
---
title: Add snowplow events for monitoring dashboard
merge_request: 19455
author:
type: added
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import Tracking from '~/tracking';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -226,12 +227,14 @@ describe('Monitoring store actions', () => { ...@@ -226,12 +227,14 @@ describe('Monitoring store actions', () => {
let state; let state;
const response = metricsDashboardResponse; const response = metricsDashboardResponse;
beforeEach(() => { beforeEach(() => {
jest.spyOn(Tracking, 'event');
dispatch = jest.fn(); dispatch = jest.fn();
state = storeState(); state = storeState();
state.dashboardEndpoint = '/dashboard'; state.dashboardEndpoint = '/dashboard';
}); });
it('dispatches receive and success actions', done => { it('dispatches receive and success actions', done => {
const params = {}; const params = {};
document.body.dataset.page = 'projects:environments:metrics';
mock.onGet(state.dashboardEndpoint).reply(200, response); mock.onGet(state.dashboardEndpoint).reply(200, response);
fetchDashboard( fetchDashboard(
{ {
...@@ -246,6 +249,17 @@ describe('Monitoring store actions', () => { ...@@ -246,6 +249,17 @@ describe('Monitoring store actions', () => {
response, response,
params, params,
}); });
})
.then(() => {
expect(Tracking.event).toHaveBeenCalledWith(
document.body.dataset.page,
'dashboard_fetch',
{
label: 'custom_metrics_dashboard',
property: 'count',
value: 0,
},
);
done(); done();
}) })
.catch(done.fail); .catch(done.fail);
......
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