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>
import { mapActions, mapGetters, mapState } from 'vuex';
import { once } from 'lodash';
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 ReportSection from '~/reports/components/report_section.vue';
import ReportItem from '~/reports/components/report_item.vue';
......@@ -15,6 +18,7 @@ export default {
ReportItem,
SmartVirtualList,
},
mixins: [glFeatureFlagsMixin()],
props: {
endpoint: {
type: String,
......@@ -59,6 +63,13 @@ export default {
hasMetrics() {
return this.metrics.length > 0;
},
handleToggleEvent() {
return once(() => {
if (this.glFeatures.usageDataITestingMetricsReportWidgetTotal) {
api.trackRedisHllUserEvent(this.$options.expandEvent);
}
});
},
},
created() {
this.setEndpoint(this.endpoint);
......@@ -67,6 +78,7 @@ export default {
methods: {
...mapActions(['setEndpoint', 'fetchMetrics']),
},
expandEvent: 'i_testing_metrics_report_widget_total',
};
</script>
<template>
......@@ -76,7 +88,9 @@ export default {
:loading-text="groupedSummaryText"
:error-text="groupedSummaryText"
:has-issues="hasMetrics"
should-emit-toggle-event
class="mr-widget-border-top grouped-security-reports mr-report"
@toggleEvent="handleToggleEvent"
>
<div slot="body" class="mr-widget-grouped-section report-block">
<smart-virtual-list
......
......@@ -11,6 +11,7 @@ module EE
before_action only: [:show] do
push_frontend_feature_flag(:anonymous_visual_review_feedback)
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
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';
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 { getStoreConfig } from 'ee/vue_shared/metrics_reports/store';
import Api from '~/api';
jest.mock('~/api.js');
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -11,13 +14,18 @@ describe('Grouped metrics reports app', () => {
let wrapper;
let mockStore;
const mountComponent = () => {
const findExpandButton = () => wrapper.find('[data-testid="report-section-expand-button"]');
const mountComponent = (glFeatures = {}) => {
wrapper = mount(GroupedMetricsReportsApp, {
store: mockStore,
localVue,
propsData: {
endpoint: 'metrics.json',
},
provide: {
glFeatures,
},
});
};
......@@ -62,6 +70,43 @@ describe('Grouped metrics reports app', () => {
});
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', () => {
beforeEach(() => {
mockStore.state.numberOfChanges = 0;
......
......@@ -248,6 +248,11 @@
redis_slot: testing
aggregation: weekly
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
- name: g_project_management_issue_title_changed
category: issues_edit
......
......@@ -1262,7 +1262,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
subject { described_class.redis_hll_counters }
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
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