Skip to content
代码片段 群组 项目
提交 a6267c0b 编辑于 作者: Ethan Urie's avatar Ethan Urie
浏览文件

Merge branch...

Merge branch '377341-add-a-new-danger-rule-to-prevent-adding-new-metrics-to-usagedata-class' into 'master'

Add a new danger rule to prevent adding new metrics to UsageData class

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/111687



Merged-by: default avatarEthan Urie <eurie@gitlab.com>
Approved-by: default avatarEthan Urie <eurie@gitlab.com>
Approved-by: default avatarDzmitry Meshcharakou <12459192-dmeshcharakou@users.noreply.gitlab.com>
Approved-by: default avatarNao Hashizume <nhashizume@gitlab.com>
Reviewed-by: default avatarDzmitry Meshcharakou <12459192-dmeshcharakou@users.noreply.gitlab.com>
Co-authored-by: default avatarj_lar <jlarsen@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -3,3 +3,5 @@
product_intelligence.check!
product_intelligence.check_affected_scopes!
product_intelligence.check_usage_data_insertions!
......@@ -18,7 +18,7 @@
let(:has_product_intelligence_label) { true }
before do
allow(fake_helper).to receive(:changed_lines).and_return(changed_lines)
allow(fake_helper).to receive(:changed_lines).and_return(changed_lines) if defined?(changed_lines)
allow(fake_helper).to receive(:labels_to_add).and_return(labels_to_add)
allow(fake_helper).to receive(:ci?).and_return(ci_env)
allow(fake_helper).to receive(:mr_has_labels?).with('product intelligence').and_return(has_product_intelligence_label)
......@@ -175,4 +175,49 @@
end
end
end
describe '#check_usage_data_insertions!' do
context 'when usage_data.rb is modified' do
let(:modified_files) { ['lib/gitlab/usage_data.rb'] }
before do
allow(fake_helper).to receive(:changed_lines).with("lib/gitlab/usage_data.rb").and_return(changed_lines)
end
context 'and has insertions' do
let(:changed_lines) { ['+ ci_runners: count(::Ci::CiRunner),'] }
it 'produces warning' do
expect(product_intelligence).to receive(:warn).with(/usage_data\.rb has been deprecated/)
product_intelligence.check_usage_data_insertions!
end
end
context 'and changes are not insertions' do
let(:changed_lines) { ['- ci_runners: count(::Ci::CiRunner),'] }
it 'doesnt do anything' do
expect(product_intelligence).not_to receive(:warn)
product_intelligence.check_usage_data_insertions!
end
end
end
context 'when usage_data.rb is not modified' do
context 'and another file has insertions' do
let(:modified_files) { ['tooling/danger/product_intelligence.rb'] }
it 'doesnt do anything' do
expect(fake_helper).to receive(:changed_lines).with("lib/gitlab/usage_data.rb").and_return([])
allow(fake_helper).to receive(:changed_lines).with("tooling/danger/product_intelligence.rb").and_return(["+ Inserting"])
expect(product_intelligence).not_to receive(:warn)
product_intelligence.check_usage_data_insertions!
end
end
end
end
end
......@@ -22,6 +22,11 @@ module ProductIntelligence
MSG
CHANGED_USAGE_DATA_MESSAGE = <<~MSG
Notice that implementing metrics directly in usage_data.rb has been deprecated. ([Deprecated Usage Metrics](https://docs.gitlab.com/ee/development/service_ping/usage_data.html#usage-data-metrics-guide))
Please use [Instrumentation Classes](https://docs.gitlab.com/ee/development/service_ping/metrics_instrumentation.html) instead.
MSG
WORKFLOW_LABELS = [
APPROVED_LABEL,
REVIEW_LABEL
......@@ -47,6 +52,13 @@ def check_affected_scopes!
helper.labels_to_add.concat(missing_labels) unless missing_labels.empty?
end
def check_usage_data_insertions!
usage_data_changes = helper.changed_lines("lib/gitlab/usage_data.rb")
return if usage_data_changes.none? { |change| change.start_with?("+") }
warn format(CHANGED_USAGE_DATA_MESSAGE)
end
private
def convert_to_table(items)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册