Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9dd4cdc2
Commit
9dd4cdc2
authored
Feb 15, 2022
by
Alan (Maciej) Paruszewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update batch size when calculating secure build metrics
parent
8814eae6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
0 deletions
+34
-0
ee/lib/gitlab/usage/metrics/instrumentations/count_ci_builds_metric.rb
.../usage/metrics/instrumentations/count_ci_builds_metric.rb
+5
-0
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
+7
-0
spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
...ab/usage/metrics/instrumentations/database_metric_spec.rb
+22
-0
No files found.
ee/lib/gitlab/usage/metrics/instrumentations/count_ci_builds_metric.rb
View file @
9dd4cdc2
...
@@ -7,6 +7,11 @@ module Gitlab
...
@@ -7,6 +7,11 @@ module Gitlab
class
CountCiBuildsMetric
<
DatabaseMetric
class
CountCiBuildsMetric
<
DatabaseMetric
relation
{
::
Ci
::
Build
}
relation
{
::
Ci
::
Build
}
operation
:count
operation
:count
metric_options
do
{
batch_size:
1_000_000
}
end
def
initialize
(
time_frame
:,
options:
{})
def
initialize
(
time_frame
:,
options:
{})
super
super
...
...
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
View file @
9dd4cdc2
...
@@ -33,6 +33,12 @@ module Gitlab
...
@@ -33,6 +33,12 @@ module Gitlab
@metric_relation
=
block
@metric_relation
=
block
end
end
def
metric_options
(
&
block
)
return
@metric_options
&
.
call
.
to_h
unless
block_given?
@metric_options
=
block
end
def
operation
(
symbol
,
column:
nil
,
&
block
)
def
operation
(
symbol
,
column:
nil
,
&
block
)
@metric_operation
=
symbol
@metric_operation
=
symbol
@column
=
column
@column
=
column
...
@@ -54,6 +60,7 @@ module Gitlab
...
@@ -54,6 +60,7 @@ module Gitlab
self
.
class
.
column
,
self
.
class
.
column
,
start:
start
,
start:
start
,
finish:
finish
,
finish:
finish
,
**
self
.
class
.
metric_options
,
&
self
.
class
.
metric_operation_block
)
&
self
.
class
.
metric_operation_block
)
end
end
...
...
spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
View file @
9dd4cdc2
...
@@ -36,6 +36,28 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do
...
@@ -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
)
expect
(
Rails
.
cache
.
read
(
'metric_instrumentation/special_issue_count_maximum_id'
)).
to
eq
(
nil
)
end
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
context
'with start and finish not called'
do
subject
do
subject
do
described_class
.
tap
do
|
metric_class
|
described_class
.
tap
do
|
metric_class
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment