Skip to content
代码片段 群组 项目
提交 bd358321 编辑于 作者: Niko Belokolodov's avatar Niko Belokolodov 提交者: Jennifer Li
浏览文件

Add dangerbot for Deprecated Redis, RedisHLL and Snowplow tracking

上级 c7047267
No related branches found
No related tags found
无相关合并请求
...@@ -7,3 +7,5 @@ analytics_instrumentation.check! ...@@ -7,3 +7,5 @@ analytics_instrumentation.check!
analytics_instrumentation.check_affected_scopes! analytics_instrumentation.check_affected_scopes!
analytics_instrumentation.check_usage_data_insertions! analytics_instrumentation.check_usage_data_insertions!
analytics_instrumentation.check_deprecated_data_sources!
...@@ -231,4 +231,64 @@ ...@@ -231,4 +231,64 @@
end end
end end
end end
describe '#check_deprecated_data_sources!' do
let(:fake_project_helper) { instance_double(Tooling::Danger::ProjectHelper) }
subject(:check_data_source) { analytics_instrumentation.check_deprecated_data_sources! }
before do
allow(fake_helper).to receive(:added_files).and_return([added_file])
allow(fake_helper).to receive(:changed_lines).with(added_file).and_return(changed_lines)
allow(analytics_instrumentation).to receive(:project_helper).and_return(fake_project_helper)
allow(analytics_instrumentation.project_helper).to receive(:file_lines).and_return(changed_lines.map { |line| line.delete_prefix('+') })
end
context 'when no metric definitions were modified' do
let(:added_file) { 'app/models/user.rb' }
let(:changed_lines) { ['+ data_source: redis,'] }
it 'does not trigger warning' do
expect(analytics_instrumentation).not_to receive(:markdown)
check_data_source
end
end
context 'when metrics fields were modified' do
let(:added_file) { 'config/metrics/count7_d/example_metric.yml' }
[:redis, :redis_hll].each do |source|
context "when source is #{source}" do
let(:changed_lines) { ["+ data_source: #{source}"] }
let(:template) do
<<~SUGGEST_COMMENT
```suggestion
data_source: internal_events
```
%<message>s
SUGGEST_COMMENT
end
it 'issues a warning' do
expected_comment = format(template, message: Tooling::Danger::AnalyticsInstrumentation::CHANGE_DEPRECATED_DATA_SOURCE_MESSAGE)
expect(analytics_instrumentation).to receive(:markdown).with(expected_comment.strip, file: added_file, line: 1)
check_data_source
end
end
end
context 'when neither redis nor redis_hll used as a data_source' do
let(:changed_lines) { ['+ data_source: database,'] }
it 'does not issue a warning' do
expect(analytics_instrumentation).not_to receive(:markdown)
check_data_source
end
end
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
require_relative 'suggestor'
module Tooling module Tooling
module Danger module Danger
module AnalyticsInstrumentation module AnalyticsInstrumentation
include ::Tooling::Danger::Suggestor
METRIC_DIRS = %w[lib/gitlab/usage/metrics/instrumentations ee/lib/gitlab/usage/metrics/instrumentations].freeze METRIC_DIRS = %w[lib/gitlab/usage/metrics/instrumentations ee/lib/gitlab/usage/metrics/instrumentations].freeze
APPROVED_LABEL = 'analytics instrumentation::approved' APPROVED_LABEL = 'analytics instrumentation::approved'
REVIEW_LABEL = 'analytics instrumentation::review pending' REVIEW_LABEL = 'analytics instrumentation::review pending'
...@@ -26,6 +30,10 @@ module AnalyticsInstrumentation ...@@ -26,6 +30,10 @@ module AnalyticsInstrumentation
Please use [Instrumentation Classes](https://docs.gitlab.com/ee/development/service_ping/metrics_instrumentation.html) instead. Please use [Instrumentation Classes](https://docs.gitlab.com/ee/development/service_ping/metrics_instrumentation.html) instead.
MSG MSG
CHANGE_DEPRECATED_DATA_SOURCE_MESSAGE = <<~MSG
Redis and RedisHLL tracking is deprecated, consider using Internal Events tracking instead https://docs.gitlab.com/ee/development/internal_analytics/internal_event_instrumentation/quick_start.html#defining-event-and-metrics
MSG
WORKFLOW_LABELS = [ WORKFLOW_LABELS = [
APPROVED_LABEL, APPROVED_LABEL,
REVIEW_LABEL REVIEW_LABEL
...@@ -58,6 +66,17 @@ def check_usage_data_insertions! ...@@ -58,6 +66,17 @@ def check_usage_data_insertions!
warn format(CHANGED_USAGE_DATA_MESSAGE) warn format(CHANGED_USAGE_DATA_MESSAGE)
end end
def check_deprecated_data_sources!
new_metric_files.each do |filename|
add_suggestion(
filename: filename,
regex: /^\+?\s+data_source: redis\w*/,
replacement: 'data_source: internal_events',
comment_text: CHANGE_DEPRECATED_DATA_SOURCE_MESSAGE
)
end
end
private private
def convert_to_table(items) def convert_to_table(items)
...@@ -99,6 +118,10 @@ def select_models(files) ...@@ -99,6 +118,10 @@ def select_models(files)
end end
end end
def new_metric_files
helper.added_files.select { |f| f.include?('config/metrics') && f.end_with?('.yml') }
end
def each_metric(&block) def each_metric(&block)
METRIC_DIRS.each do |dir| METRIC_DIRS.each do |dir|
Dir.glob(File.join(dir, '*.rb')).each(&block) Dir.glob(File.join(dir, '*.rb')).each(&block)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册