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
649d6cb3
Commit
649d6cb3
authored
Jun 15, 2021
by
Piotr Skorupa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cache_start_and_finish_as and update specs
parent
ba4b88e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
+10
-2
spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
...ab/usage/metrics/instrumentations/database_metric_spec.rb
+32
-0
No files found.
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
View file @
649d6cb3
...
...
@@ -38,7 +38,11 @@ module Gitlab
@column
=
column
end
attr_reader
:metric_operation
,
:metric_relation
,
:metric_start
,
:metric_finish
,
:column
def
cache_start_and_finish_as
(
cache_key
)
@cache_key
=
cache_key
end
attr_reader
:metric_operation
,
:metric_relation
,
:metric_start
,
:metric_finish
,
:column
,
:cache_key
end
def
value
...
...
@@ -87,7 +91,11 @@ module Gitlab
end
def
get_or_cache_batch_ids
key_name
=
"metric_instrumentation/
#{
relation
.
table_name
}
"
key_name
=
if
self
.
class
.
cache_key
.
present?
"metric_instrumentation/
#{
self
.
class
.
cache_key
}
"
else
"metric_instrumentation/
#{
relation
.
table_name
}
"
end
start
=
Rails
.
cache
.
fetch
(
"
#{
key_name
}
_minimum_id"
,
expires_in:
1
.
day
)
do
self
.
class
.
start
...
...
spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
View file @
649d6cb3
...
...
@@ -31,5 +31,37 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do
expect
(
Rails
.
cache
.
read
(
'metric_instrumentation/issues_minimum_id'
)).
to
eq
(
314
)
expect
(
Rails
.
cache
.
read
(
'metric_instrumentation/issues_maximum_id'
)).
to
eq
(
949
)
end
context
'with start and finish not called'
do
subject
do
described_class
.
tap
do
|
m
|
m
.
relation
{
Issue
}
m
.
operation
:count
end
.
new
(
time_frame:
'all'
)
end
it
'calculates a correct result'
do
expect
(
subject
.
value
).
to
eq
(
3
)
end
end
context
'with cache_start_and_finish_as called'
do
subject
do
described_class
.
tap
do
|
m
|
m
.
relation
{
Issue
}
m
.
operation
:count
m
.
start
{
m
.
relation
.
minimum
(
:id
)
}
m
.
finish
{
m
.
relation
.
maximum
(
:id
)
}
m
.
cache_start_and_finish_as
:special_issue_count
end
.
new
(
time_frame:
'all'
)
end
it
'caches using the key name passed'
,
:use_clean_rails_redis_caching
do
subject
.
value
expect
(
Rails
.
cache
.
read
(
'metric_instrumentation/special_issue_count_minimum_id'
)).
to
eq
(
314
)
expect
(
Rails
.
cache
.
read
(
'metric_instrumentation/special_issue_count_maximum_id'
)).
to
eq
(
949
)
end
end
end
end
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