Commit f499165e authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch '321191-track-group-coverage-views-usage-ping-in-vue-instead' into 'master'

Track group coverage visits in vue instead

See merge request gitlab-org/gitlab!55687
parents 415f0254 ef2efb83
<script> <script>
import Api from '~/api';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import DownloadTestCoverage from './download_test_coverage.vue'; import DownloadTestCoverage from './download_test_coverage.vue';
import TestCoverageSummary from './test_coverage_summary.vue'; import TestCoverageSummary from './test_coverage_summary.vue';
import TestCoverageTable from './test_coverage_table.vue'; import TestCoverageTable from './test_coverage_table.vue';
export const VISIT_EVENT_FEATURE_FLAG = 'usageDataITestingGroupCodeCoverageVisitTotal';
export const VISIT_EVENT_NAME = 'i_testing_group_code_coverage_visit_total';
export default { export default {
name: 'GroupRepositoryAnalytics', name: 'GroupRepositoryAnalytics',
components: { components: {
...@@ -13,6 +17,11 @@ export default { ...@@ -13,6 +17,11 @@ export default {
DownloadTestCoverage, DownloadTestCoverage,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
mounted() {
if (this.glFeatures[VISIT_EVENT_FEATURE_FLAG]) {
Api.trackRedisHllUserEvent(VISIT_EVENT_NAME);
}
},
text: { text: {
codeCoverageHeader: s__('RepositoriesAnalytics|Test Code Coverage'), codeCoverageHeader: s__('RepositoriesAnalytics|Test Code Coverage'),
}, },
......
# frozen_string_literal: true # frozen_string_literal: true
class Groups::Analytics::RepositoryAnalyticsController < Groups::Analytics::ApplicationController class Groups::Analytics::RepositoryAnalyticsController < Groups::Analytics::ApplicationController
include RedisTracking
layout 'group' layout 'group'
before_action :load_group before_action :load_group
before_action -> { check_feature_availability!(:group_repository_analytics) } before_action -> { check_feature_availability!(:group_repository_analytics) }
before_action -> { authorize_view_by_action!(:read_group_repository_analytics) } before_action -> { authorize_view_by_action!(:read_group_repository_analytics) }
before_action only: [:show] do before_action only: [:show] do
push_frontend_feature_flag(:usage_data_i_testing_group_code_coverage_visit_total, @group, default_enabled: :yaml)
push_frontend_feature_flag(:usage_data_i_testing_group_code_coverage_project_click_total, @group, default_enabled: :yaml) push_frontend_feature_flag(:usage_data_i_testing_group_code_coverage_project_click_total, @group, default_enabled: :yaml)
end end
track_redis_hll_event :show, name: 'i_testing_group_code_coverage_visit_total'
def show def show
track_event(**pageview_tracker_params) track_event(**pageview_tracker_params)
......
---
title: Track group coverage usage ping event in Vue template
merge_request: 55687
author:
type: changed
...@@ -33,19 +33,6 @@ RSpec.describe Groups::Analytics::RepositoryAnalyticsController do ...@@ -33,19 +33,6 @@ RSpec.describe Groups::Analytics::RepositoryAnalyticsController do
) )
end end
context 'unique users tracking' do
before do
allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event)
end
it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: { group_id: group } }
let(:target_id) { 'i_testing_group_code_coverage_visit_total' }
let(:expected_type) { instance_of(String) }
end
end
context 'when license is missing' do context 'when license is missing' do
before do before do
stub_licensed_features(feature_name => false) stub_licensed_features(feature_name => false)
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import DownloadTestCoverage from 'ee/analytics/repository_analytics/components/download_test_coverage.vue'; import DownloadTestCoverage from 'ee/analytics/repository_analytics/components/download_test_coverage.vue';
import GroupRepositoryAnalytics from 'ee/analytics/repository_analytics/components/group_repository_analytics.vue'; import GroupRepositoryAnalytics, {
VISIT_EVENT_FEATURE_FLAG,
VISIT_EVENT_NAME,
} from 'ee/analytics/repository_analytics/components/group_repository_analytics.vue';
import Api from '~/api';
const localVue = createLocalVue(); const localVue = createLocalVue();
jest.mock('~/api.js');
describe('Group repository analytics app', () => { describe('Group repository analytics app', () => {
let wrapper; let wrapper;
const createComponent = () => { const createComponent = (glFeatures = {}) => {
wrapper = shallowMount(GroupRepositoryAnalytics, { localVue }); wrapper = shallowMount(GroupRepositoryAnalytics, { localVue, provide: { glFeatures } });
}; };
beforeEach(() => {
createComponent();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('test coverage', () => { describe('test coverage', () => {
beforeEach(() => {
createComponent();
});
it('renders test coverage header', () => { it('renders test coverage header', () => {
const header = wrapper.find('[data-testid="test-coverage-header"]'); const header = wrapper.find('[data-testid="test-coverage-header"]');
...@@ -31,4 +35,26 @@ describe('Group repository analytics app', () => { ...@@ -31,4 +35,26 @@ describe('Group repository analytics app', () => {
expect(wrapper.find(DownloadTestCoverage).exists()).toBe(true); expect(wrapper.find(DownloadTestCoverage).exists()).toBe(true);
}); });
}); });
describe('usage ping events', () => {
describe('with the feature flag enabled', () => {
beforeEach(() => {
createComponent({ [VISIT_EVENT_FEATURE_FLAG]: true });
});
it('tracks a visit event on mount', () => {
expect(Api.trackRedisHllUserEvent).toHaveBeenCalledWith(VISIT_EVENT_NAME);
});
});
describe('with the feature flag disabled', () => {
beforeEach(() => {
createComponent({ [VISIT_EVENT_FEATURE_FLAG]: false });
});
it('does not track a visit event on mount', () => {
expect(Api.trackRedisHllUserEvent).not.toHaveBeenCalled();
});
});
});
}); });
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