Commit 36fd0950 authored by Marc Shaw's avatar Marc Shaw

Merge branch '344264-update-batch-size-for-secure-jobs-metric' into 'master'

Update batch size when calculating secure build metrics

See merge request gitlab-org/gitlab!80763
parents a3a63d3f 9dd4cdc2
......@@ -7,6 +7,11 @@ module Gitlab
class CountCiBuildsMetric < DatabaseMetric
relation { ::Ci::Build }
operation :count
metric_options do
{
batch_size: 1_000_000
}
end
def initialize(time_frame:, options: {})
super
......
......@@ -33,6 +33,12 @@ module Gitlab
@metric_relation = block
end
def metric_options(&block)
return @metric_options&.call.to_h unless block_given?
@metric_options = block
end
def operation(symbol, column: nil, &block)
@metric_operation = symbol
@column = column
......@@ -54,6 +60,7 @@ module Gitlab
self.class.column,
start: start,
finish: finish,
**self.class.metric_options,
&self.class.metric_operation_block)
end
......
......@@ -36,6 +36,28 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do
expect(Rails.cache.read('metric_instrumentation/special_issue_count_maximum_id')).to eq(nil)
end
context 'with metric options specified with custom batch_size' do
subject do
described_class.tap do |metric_class|
metric_class.relation { Issue }
metric_class.operation :count
metric_class.start { metric_class.relation.minimum(:id) }
metric_class.finish { metric_class.relation.maximum(:id) }
metric_class.metric_options { { batch_size: 12345 } }
end.new(time_frame: 'all')
end
it 'calls metric with customized batch_size' do
expect(subject).to receive(:count).with(any_args, hash_including(batch_size: 12345, start: issues.min_by(&:id).id, finish: issues.max_by(&:id).id)).and_call_original
subject.value
end
it 'calculates a correct result' do
expect(subject.value).to eq(3)
end
end
context 'with start and finish not called' do
subject do
described_class.tap do |metric_class|
......
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