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
c89c6395
Commit
c89c6395
authored
Feb 22, 2022
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add external HTTP request within transactions tracking
parent
d5dfee6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
1 deletion
+42
-1
lib/gitlab/database/transaction/context.rb
lib/gitlab/database/transaction/context.rb
+28
-0
lib/gitlab/database/transaction/observer.rb
lib/gitlab/database/transaction/observer.rb
+1
-0
spec/lib/gitlab/database/transaction/observer_spec.rb
spec/lib/gitlab/database/transaction/observer_spec.rb
+13
-1
No files found.
lib/gitlab/database/transaction/context.rb
View file @
c89c6395
...
...
@@ -43,6 +43,11 @@ module Gitlab
(
@context
[
:backtraces
]
||=
[]).
push
(
cleaned_backtrace
)
end
def
initialize_external_http_tracking
@context
[
:external_http_count_start
]
=
external_http_requests_count_total
@context
[
:external_http_duration_start
]
=
external_http_requests_duration_total
end
def
duration
return
unless
@context
[
:start_time
].
present?
...
...
@@ -61,6 +66,11 @@ module Gitlab
return
false
if
logged_already?
savepoints_threshold_exceeded?
||
duration_threshold_exceeded?
## TODO
#
# External requests duration / count exceeded
#
end
def
commit
...
...
@@ -108,6 +118,8 @@ module Gitlab
savepoints_count:
@context
[
:savepoints
].
to_i
,
rollbacks_count:
@context
[
:rollbacks
].
to_i
,
releases_count:
@context
[
:releases
].
to_i
,
transaction_external_http_requests_count:
external_http_requests_count
,
transaction_external_http_requests_duration:
external_http_requests_duration
,
sql:
queries
,
savepoint_backtraces:
backtraces
}
...
...
@@ -118,6 +130,22 @@ module Gitlab
def
application_info
(
attributes
)
Gitlab
::
AppJsonLogger
.
info
(
attributes
)
end
def
external_http_requests_count
@requests_count
||=
external_http_requests_count_total
-
@context
[
:external_http_count_start
].
to_i
end
def
external_http_requests_duration
@requests_duration
||=
external_http_requests_duration_total
-
@context
[
:external_http_duration_start
].
to_f
end
def
external_http_requests_count_total
::
Gitlab
::
Metrics
::
Subscribers
::
ExternalHttp
.
request_count
.
to_i
end
def
external_http_requests_duration_total
::
Gitlab
::
Metrics
::
Subscribers
::
ExternalHttp
.
duration
.
to_f
end
end
end
end
...
...
lib/gitlab/database/transaction/observer.rb
View file @
c89c6395
...
...
@@ -21,6 +21,7 @@ module Gitlab
context
.
set_start_time
context
.
set_depth
(
0
)
context
.
track_sql
(
event
.
payload
[
:sql
])
context
.
initialize_external_http_tracking
elsif
cmd
.
start_with?
(
'SAVEPOINT'
,
'EXCEPTION'
)
context
.
set_depth
(
manager
.
open_transactions
)
context
.
increment_savepoints
...
...
spec/lib/gitlab/database/transaction/observer_spec.rb
View file @
c89c6395
...
...
@@ -25,7 +25,7 @@ RSpec.describe Gitlab::Database::Transaction::Observer do
User
.
first
expect
(
transaction_context
).
to
be_a
(
::
Gitlab
::
Database
::
Transaction
::
Context
)
expect
(
context
.
keys
).
to
match_array
(
%i(start_time depth savepoints queries backtraces)
)
expect
(
context
.
keys
).
to
match_array
(
%i(start_time depth savepoints queries backtraces
external_http_count_start external_http_duration_start
)
)
expect
(
context
[
:depth
]).
to
eq
(
2
)
expect
(
context
[
:savepoints
]).
to
eq
(
1
)
expect
(
context
[
:queries
].
length
).
to
eq
(
1
)
...
...
@@ -38,6 +38,18 @@ RSpec.describe Gitlab::Database::Transaction::Observer do
expect
(
context
[
:backtraces
].
length
).
to
eq
(
1
)
end
it
'tracks external requests duration'
,
:request_store
do
# TODO add tests!
ActiveRecord
::
Base
.
transaction
do
ActiveRecord
::
Base
.
transaction
(
requires_new:
true
)
do
User
.
first
expect
(
context
[
:external_http_count_start
]).
to
eq
(
0
)
expect
(
context
[
:external_http_duration_start
]).
to
eq
(
0
)
end
end
end
describe
'.extract_sql_command'
do
using
RSpec
::
Parameterized
::
TableSyntax
...
...
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