Commit 0b531df1 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch '224617-usage-data-generic-metrics-report' into 'master'

Add usage ping for generic metrics

See merge request gitlab-org/gitlab!50790
parents c1394220 9fe0f0ff
---
name: usage_data_i_testing_metrics_report_widget_total
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50790
rollout_issue_url:
milestone: '13.8'
type: development
group: group::testing
default_enabled: true
<script> <script>
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { once } from 'lodash';
import { componentNames } from 'ee/reports/components/issue_body'; import { componentNames } from 'ee/reports/components/issue_body';
import api from '~/api';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue'; import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue';
import ReportSection from '~/reports/components/report_section.vue'; import ReportSection from '~/reports/components/report_section.vue';
import ReportItem from '~/reports/components/report_item.vue'; import ReportItem from '~/reports/components/report_item.vue';
...@@ -15,6 +18,7 @@ export default { ...@@ -15,6 +18,7 @@ export default {
ReportItem, ReportItem,
SmartVirtualList, SmartVirtualList,
}, },
mixins: [glFeatureFlagsMixin()],
props: { props: {
endpoint: { endpoint: {
type: String, type: String,
...@@ -59,6 +63,13 @@ export default { ...@@ -59,6 +63,13 @@ export default {
hasMetrics() { hasMetrics() {
return this.metrics.length > 0; return this.metrics.length > 0;
}, },
handleToggleEvent() {
return once(() => {
if (this.glFeatures.usageDataITestingMetricsReportWidgetTotal) {
api.trackRedisHllUserEvent(this.$options.expandEvent);
}
});
},
}, },
created() { created() {
this.setEndpoint(this.endpoint); this.setEndpoint(this.endpoint);
...@@ -67,6 +78,7 @@ export default { ...@@ -67,6 +78,7 @@ export default {
methods: { methods: {
...mapActions(['setEndpoint', 'fetchMetrics']), ...mapActions(['setEndpoint', 'fetchMetrics']),
}, },
expandEvent: 'i_testing_metrics_report_widget_total',
}; };
</script> </script>
<template> <template>
...@@ -76,7 +88,9 @@ export default { ...@@ -76,7 +88,9 @@ export default {
:loading-text="groupedSummaryText" :loading-text="groupedSummaryText"
:error-text="groupedSummaryText" :error-text="groupedSummaryText"
:has-issues="hasMetrics" :has-issues="hasMetrics"
should-emit-toggle-event
class="mr-widget-border-top grouped-security-reports mr-report" class="mr-widget-border-top grouped-security-reports mr-report"
@toggleEvent="handleToggleEvent"
> >
<div slot="body" class="mr-widget-grouped-section report-block"> <div slot="body" class="mr-widget-grouped-section report-block">
<smart-virtual-list <smart-virtual-list
......
...@@ -11,6 +11,7 @@ module EE ...@@ -11,6 +11,7 @@ module EE
before_action only: [:show] do before_action only: [:show] do
push_frontend_feature_flag(:anonymous_visual_review_feedback) push_frontend_feature_flag(:anonymous_visual_review_feedback)
push_frontend_feature_flag(:missing_mr_security_scan_types, @project) push_frontend_feature_flag(:missing_mr_security_scan_types, @project)
push_frontend_feature_flag(:usage_data_i_testing_metrics_report_widget_total, @project, default_enabled: true)
end end
before_action :whitelist_query_limiting_ee_merge, only: [:merge] before_action :whitelist_query_limiting_ee_merge, only: [:merge]
......
---
title: Capture generic metrics report views via usage ping
merge_request: 50790
author:
type: added
...@@ -3,6 +3,9 @@ import Vuex from 'vuex'; ...@@ -3,6 +3,9 @@ import Vuex from 'vuex';
import MetricsReportsIssueBody from 'ee/vue_shared/metrics_reports/components/metrics_reports_issue_body.vue'; import MetricsReportsIssueBody from 'ee/vue_shared/metrics_reports/components/metrics_reports_issue_body.vue';
import GroupedMetricsReportsApp from 'ee/vue_shared/metrics_reports/grouped_metrics_reports_app.vue'; import GroupedMetricsReportsApp from 'ee/vue_shared/metrics_reports/grouped_metrics_reports_app.vue';
import { getStoreConfig } from 'ee/vue_shared/metrics_reports/store'; import { getStoreConfig } from 'ee/vue_shared/metrics_reports/store';
import Api from '~/api';
jest.mock('~/api.js');
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -11,13 +14,18 @@ describe('Grouped metrics reports app', () => { ...@@ -11,13 +14,18 @@ describe('Grouped metrics reports app', () => {
let wrapper; let wrapper;
let mockStore; let mockStore;
const mountComponent = () => { const findExpandButton = () => wrapper.find('[data-testid="report-section-expand-button"]');
const mountComponent = (glFeatures = {}) => {
wrapper = mount(GroupedMetricsReportsApp, { wrapper = mount(GroupedMetricsReportsApp, {
store: mockStore, store: mockStore,
localVue, localVue,
propsData: { propsData: {
endpoint: 'metrics.json', endpoint: 'metrics.json',
}, },
provide: {
glFeatures,
},
}); });
}; };
...@@ -62,6 +70,43 @@ describe('Grouped metrics reports app', () => { ...@@ -62,6 +70,43 @@ describe('Grouped metrics reports app', () => {
}); });
describe('with metrics', () => { describe('with metrics', () => {
describe('when user expands to view metrics', () => {
beforeEach(() => {
mockStore.state.numberOfChanges = 0;
mockStore.state.existingMetrics = [
{
name: 'name',
value: 'value',
},
];
});
describe('with :usage_data_group_code_coverage_visit_total enabled', () => {
beforeEach(() => {
mountComponent({ usageDataITestingMetricsReportWidgetTotal: true });
});
it('tracks group_code_coverage_visit_total metric', () => {
findExpandButton().trigger('click');
expect(Api.trackRedisHllUserEvent).toHaveBeenCalledTimes(1);
expect(Api.trackRedisHllUserEvent).toHaveBeenCalledWith(wrapper.vm.$options.expandEvent);
});
});
describe('with :usage_data_group_code_coverage_visit_total disabled', () => {
beforeEach(() => {
mountComponent({ usageDataITestingMetricsReportWidgetTotal: false });
});
it('does not track group_code_coverage_visit_total metric', () => {
findExpandButton().trigger('click');
expect(Api.trackRedisHllUserEvent).not.toHaveBeenCalled();
});
});
});
describe('with no changes', () => { describe('with no changes', () => {
beforeEach(() => { beforeEach(() => {
mockStore.state.numberOfChanges = 0; mockStore.state.numberOfChanges = 0;
......
...@@ -248,6 +248,11 @@ ...@@ -248,6 +248,11 @@
redis_slot: testing redis_slot: testing
aggregation: weekly aggregation: weekly
feature_flag: usage_data_i_testing_test_case_parsed feature_flag: usage_data_i_testing_test_case_parsed
- name: i_testing_metrics_report_widget_total
category: testing
redis_slot: testing
aggregation: weekly
feature_flag: usage_data_i_testing_metrics_report_widget_total
# Project Management group # Project Management group
- name: g_project_management_issue_title_changed - name: g_project_management_issue_title_changed
category: issues_edit category: issues_edit
......
...@@ -1262,7 +1262,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1262,7 +1262,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
subject { described_class.redis_hll_counters } subject { described_class.redis_hll_counters }
let(:categories) { ::Gitlab::UsageDataCounters::HLLRedisCounter.categories } let(:categories) { ::Gitlab::UsageDataCounters::HLLRedisCounter.categories }
let(:ineligible_total_categories) { %w[source_code testing ci_secrets_management incident_management_alerts snippets terraform] } let(:ineligible_total_categories) { %w[source_code ci_secrets_management incident_management_alerts snippets terraform] }
it 'has all known_events' do it 'has all known_events' do
expect(subject).to have_key(:redis_hll_counters) expect(subject).to have_key(:redis_hll_counters)
......
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