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
c0bb9d07
Commit
c0bb9d07
authored
Apr 15, 2021
by
Quang-Minh Nguyen
Committed by
Bob Van Landuyt
Apr 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add queue to background transaction metrics
parent
66ce587c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
6 deletions
+70
-6
changelogs/unreleased/qmnguyen0711-add-queue-to-background-transaction.yml
...ased/qmnguyen0711-add-queue-to-background-transaction.yml
+5
-0
lib/gitlab/metrics/background_transaction.rb
lib/gitlab/metrics/background_transaction.rb
+18
-2
spec/lib/gitlab/metrics/background_transaction_spec.rb
spec/lib/gitlab/metrics/background_transaction_spec.rb
+47
-4
No files found.
changelogs/unreleased/qmnguyen0711-add-queue-to-background-transaction.yml
0 → 100644
View file @
c0bb9d07
---
title
:
Add queue label to metrics dispatched by background transaction
merge_request
:
59344
author
:
type
:
changed
lib/gitlab/metrics/background_transaction.rb
View file @
c0bb9d07
...
...
@@ -34,8 +34,9 @@ module Gitlab
def
labels
@labels
||=
{
endpoint_id:
current_context
&
.
get_attribute
(
:caller_id
),
feature_category:
current_context
&
.
get_attribute
(
:feature_category
)
endpoint_id:
endpoint_id
,
feature_category:
feature_category
,
queue:
queue
}
end
...
...
@@ -44,6 +45,21 @@ module Gitlab
def
current_context
Labkit
::
Context
.
current
end
def
feature_category
current_context
&
.
get_attribute
(
:feature_category
)
end
def
endpoint_id
current_context
&
.
get_attribute
(
:caller_id
)
end
def
queue
worker_class
=
endpoint_id
.
to_s
.
safe_constantize
return
if
worker_class
.
blank?
||
!
worker_class
.
respond_to?
(
:queue
)
worker_class
.
queue
.
to_s
end
end
end
end
spec/lib/gitlab/metrics/background_transaction_spec.rb
View file @
c0bb9d07
...
...
@@ -29,17 +29,60 @@ RSpec.describe Gitlab::Metrics::BackgroundTransaction do
end
describe
'#labels'
do
it
'provides labels with endpoint_id and feature_category'
do
Gitlab
::
ApplicationContext
.
with_raw_context
(
feature_category:
'projects'
,
caller_id:
'TestWorker'
)
do
expect
(
transaction
.
labels
).
to
eq
({
endpoint_id:
'TestWorker'
,
feature_category:
'projects'
})
context
'when the worker queue is accessible'
do
before
do
test_worker_class
=
Class
.
new
do
def
self
.
queue
'test_worker'
end
end
stub_const
(
'TestWorker'
,
test_worker_class
)
end
it
'provides labels with endpoint_id, feature_category and queue'
do
Gitlab
::
ApplicationContext
.
with_raw_context
(
feature_category:
'projects'
,
caller_id:
'TestWorker'
)
do
expect
(
transaction
.
labels
).
to
eq
({
endpoint_id:
'TestWorker'
,
feature_category:
'projects'
,
queue:
'test_worker'
})
end
end
end
context
'when the worker name does not exist'
do
it
'provides labels with endpoint_id and feature_category'
do
# 123TestWorker is an invalid constant
Gitlab
::
ApplicationContext
.
with_raw_context
(
feature_category:
'projects'
,
caller_id:
'123TestWorker'
)
do
expect
(
transaction
.
labels
).
to
eq
({
endpoint_id:
'123TestWorker'
,
feature_category:
'projects'
,
queue:
nil
})
end
end
end
context
'when the worker queue is not accessible'
do
before
do
stub_const
(
'TestWorker'
,
Class
.
new
)
end
it
'provides labels with endpoint_id and feature_category'
do
Gitlab
::
ApplicationContext
.
with_raw_context
(
feature_category:
'projects'
,
caller_id:
'TestWorker'
)
do
expect
(
transaction
.
labels
).
to
eq
({
endpoint_id:
'TestWorker'
,
feature_category:
'projects'
,
queue:
nil
})
end
end
end
end
RSpec
.
shared_examples
'metric with labels'
do
|
metric_method
|
before
do
test_worker_class
=
Class
.
new
do
def
self
.
queue
'test_worker'
end
end
stub_const
(
'TestWorker'
,
test_worker_class
)
end
it
'measures with correct labels and value'
do
value
=
1
expect
(
prometheus_metric
).
to
receive
(
metric_method
).
with
({
endpoint_id:
'TestWorker'
,
feature_category:
'projects'
},
value
)
expect
(
prometheus_metric
).
to
receive
(
metric_method
).
with
({
endpoint_id:
'TestWorker'
,
feature_category:
'projects'
,
queue:
'test_worker'
},
value
)
Gitlab
::
ApplicationContext
.
with_raw_context
(
feature_category:
'projects'
,
caller_id:
'TestWorker'
)
do
transaction
.
send
(
metric_method
,
:test_metric
,
value
)
...
...
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