Skip to content
代码片段 群组 项目
提交 d3e207e8 编辑于 作者: Max Woolf's avatar Max Woolf 提交者: Rémy Coutable
浏览文件

Add RedisHLL counter for creating dashboards

On push, we enqueue a new worker to check
if a new analytics dashboard was created and
increments a project-specific counter.

This will give us a count of the number of projects
with at least one dashboard.

EE: true
Changelog: added
上级 83e6d97f
No related branches found
No related tags found
无相关合并请求
...@@ -421,6 +421,8 @@ ...@@ -421,6 +421,8 @@
- 1 - 1
- - product_analytics_initialize_snowplow_product_analytics - - product_analytics_initialize_snowplow_product_analytics
- 1 - 1
- - product_analytics_post_push
- 1
- - project_cache - - project_cache
- 1 - 1
- - project_destroy - - project_destroy
......
...@@ -10,12 +10,20 @@ def execute ...@@ -10,12 +10,20 @@ def execute
enqueue_elasticsearch_indexing enqueue_elasticsearch_indexing
enqueue_zoekt_indexing enqueue_zoekt_indexing
enqueue_update_external_pull_requests enqueue_update_external_pull_requests
enqueue_product_analytics_event_metrics
super super
end end
private private
def enqueue_product_analytics_event_metrics
return unless project.product_analytics_enabled?
return unless default_branch?
::ProductAnalytics::PostPushWorker.perform_async(project.id, newrev)
end
def enqueue_elasticsearch_indexing def enqueue_elasticsearch_indexing
return unless should_index_commits? return unless should_index_commits?
......
...@@ -1524,6 +1524,15 @@ ...@@ -1524,6 +1524,15 @@
:weight: 1 :weight: 1
:idempotent: true :idempotent: true
:tags: [] :tags: []
- :name: product_analytics_post_push
:worker_name: ProductAnalytics::PostPushWorker
:feature_category: :product_analytics
:has_external_dependencies: false
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: project_import_schedule - :name: project_import_schedule
:worker_name: ProjectImportScheduleWorker :worker_name: ProjectImportScheduleWorker
:feature_category: :source_code_management :feature_category: :source_code_management
......
# frozen_string_literal: true
module ProductAnalytics
class PostPushWorker
include ApplicationWorker
data_consistency :sticky
feature_category :product_analytics
idempotent!
def perform(project_id, newrev)
@project = Project.find_by_id(project_id)
@commit = @project.repository.commit(newrev)
track_event if commit_has_new_dashboard?
end
private
def commit_has_new_dashboard?
@commit.deltas.any? do |delta|
delta.new_path.start_with?(".gitlab/analytics/dashboards/") && delta.new_file
end
end
def track_event
Gitlab::UsageDataCounters::HLLRedisCounter.track_usage_event(
:project_created_analytics_dashboard,
@project.id
)
end
end
end
---
key_path: counts.projects_with_analytics_dashboard_monthly
description: Count of projects with an analytics dashboard
product_section: dev
product_stage: analyze
product_group: product_analytics
value_type: number
status: active
milestone: "16.0"
introduced_by_url:
time_frame: 28d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
distribution:
- ee
tier:
- ultimate
options:
events:
- project_created_analytics_dashboard
---
key_path: counts.projects_with_analytics_dashboard_weekly
description: Count of projects with an analytics dashboard
product_section: dev
product_stage: analyze
product_group: product_analytics
value_type: number
status: active
milestone: "16.0"
introduced_by_url:
time_frame: 7d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
distribution:
- ee
tier:
- ultimate
options:
events:
- project_created_analytics_dashboard
...@@ -184,5 +184,38 @@ ...@@ -184,5 +184,38 @@
end end
end end
end end
context 'Product Analytics' do
using RSpec::Parameterized::TableSyntax
where(:flag_enabled, :default_branch, :licence_available, :called) do
true | 'master' | true | true
true | 'master' | false | false
true | 'other' | true | false
true | 'other' | false | false
false | 'master' | true | false
false | 'master' | false | false
false | 'other' | true | false
false | 'other' | false | false
end
before do
stub_feature_flags(product_analytics_dashboards: flag_enabled)
stub_licensed_features(product_analytics: licence_available)
allow(project).to receive(:default_branch).and_return(default_branch)
end
with_them do
it 'enqueues the worker if appropriate' do
if called
expect(::ProductAnalytics::PostPushWorker).to receive(:perform_async).once
else
expect(::ProductAnalytics::PostPushWorker).not_to receive(:perform_async)
end
subject.execute
end
end
end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProductAnalytics::PostPushWorker, feature_category: :product_analytics do
include RepoHelpers
let_it_be(:project) { create(:project, :repository) }
let(:commit) { project.repository.commit }
subject { described_class.new.perform(project.id, commit.sha) }
shared_examples 'tracks a usage event' do
it 'tracks a usage event' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter)
.to receive(:track_usage_event).with(:project_created_analytics_dashboard, project.id)
subject
end
end
shared_examples 'does not track a usage event' do
it 'does not track a usage event' do
expect(Gitlab::Utils::UsageData).not_to receive(:track_usage_event)
subject
end
end
context 'when the commit includes a new dashboard' do
before do
create_new_dashboard
end
it_behaves_like 'tracks a usage event'
end
context 'when the commit includes a new file that is not a dashboard' do
it_behaves_like 'does not track a usage event'
end
private
def create_new_dashboard
project.repository.create_file(
project.creator,
'.gitlab/analytics/dashboards/dashboard_hello/dashboard_hello.yml',
'content',
message: 'Add dashboard',
branch_name: 'master'
)
end
end
- name: project_created_analytics_dashboard
aggregation: weekly
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册