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
03f53df3
Commit
03f53df3
authored
Feb 14, 2021
by
Dylan Griffith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert Revert 301146-log-timeouts-from-elasticsearch
This reverts commit
e2c1c148
.
parent
6ade2ca4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
7 deletions
+53
-7
doc/administration/logs.md
doc/administration/logs.md
+2
-0
ee/changelogs/unreleased/301146-log-timeouts-from-elasticsearch.yml
...ogs/unreleased/301146-log-timeouts-from-elasticsearch.yml
+5
-0
ee/spec/lib/gitlab/instrumentation/elasticsearch_transport_spec.rb
...ib/gitlab/instrumentation/elasticsearch_transport_spec.rb
+28
-6
ee/spec/lib/gitlab/instrumentation_helper_spec.rb
ee/spec/lib/gitlab/instrumentation_helper_spec.rb
+1
-0
lib/gitlab/instrumentation/elasticsearch_transport.rb
lib/gitlab/instrumentation/elasticsearch_transport.rb
+14
-1
lib/gitlab/instrumentation_helper.rb
lib/gitlab/instrumentation_helper.rb
+2
-0
spec/lib/gitlab/instrumentation_helper_spec.rb
spec/lib/gitlab/instrumentation_helper_spec.rb
+1
-0
No files found.
doc/administration/logs.md
View file @
03f53df3
...
@@ -93,6 +93,8 @@ which correspond to:
...
@@ -93,6 +93,8 @@ which correspond to:
1.
`elasticsearch_calls`
: total number of calls to Elasticsearch
1.
`elasticsearch_calls`
: total number of calls to Elasticsearch
1.
`elasticsearch_duration_s`
: total time taken by Elasticsearch calls
1.
`elasticsearch_duration_s`
: total time taken by Elasticsearch calls
1.
`elasticsearch_timed_out_count`
: total number of calls to Elasticsearch that
timed out and therefore returned partial results
ActionCable connection and subscription events are also logged to this file and they follow the same
ActionCable connection and subscription events are also logged to this file and they follow the same
format above. The
`method`
,
`path`
, and
`format`
fields are not applicable, and are always empty.
format above. The
`method`
,
`path`
, and
`format`
fields are not applicable, and are always empty.
...
...
ee/changelogs/unreleased/301146-log-timeouts-from-elasticsearch.yml
0 → 100644
View file @
03f53df3
---
title
:
Track elasticsearch_timed_out_count for all ES requests in log
merge_request
:
53955
author
:
type
:
changed
ee/spec/lib/gitlab/instrumentation/elasticsearch_transport_spec.rb
View file @
03f53df3
...
@@ -12,6 +12,12 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransport, :elastic, :req
...
@@ -12,6 +12,12 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransport, :elastic, :req
end
end
end
end
describe
'.increment_timed_out_count'
do
it
'increases the timed out count by 1'
do
expect
{
described_class
.
increment_timed_out_count
}.
to
change
(
described_class
,
:get_timed_out_count
).
by
(
1
)
end
end
describe
'.add_duration'
do
describe
'.add_duration'
do
it
'does not lose precision while adding'
do
it
'does not lose precision while adding'
do
::
Gitlab
::
SafeRequestStore
.
clear!
::
Gitlab
::
SafeRequestStore
.
clear!
...
@@ -46,6 +52,8 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransport, :elastic, :req
...
@@ -46,6 +52,8 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransport, :elastic, :req
end
end
RSpec
.
describe
::
Gitlab
::
Instrumentation
::
ElasticsearchTransportInterceptor
,
:elastic
,
:request_store
do
RSpec
.
describe
::
Gitlab
::
Instrumentation
::
ElasticsearchTransportInterceptor
,
:elastic
,
:request_store
do
let
(
:elasticsearch_url
)
{
Gitlab
::
CurrentSettings
.
elasticsearch_url
[
0
]
}
before
do
before
do
allow
(
::
Gitlab
::
PerformanceBar
).
to
receive
(
:enabled_for_request?
).
and_return
(
true
)
allow
(
::
Gitlab
::
PerformanceBar
).
to
receive
(
:enabled_for_request?
).
and_return
(
true
)
end
end
...
@@ -61,9 +69,6 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransportInterceptor, :el
...
@@ -61,9 +69,6 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransportInterceptor, :el
it
'adds the labkit correlation id as X-Opaque-Id to all requests'
do
it
'adds the labkit correlation id as X-Opaque-Id to all requests'
do
allow
(
Labkit
::
Correlation
::
CorrelationId
).
to
receive
(
:current_or_new_id
).
and_return
(
'new-correlation-id'
)
allow
(
Labkit
::
Correlation
::
CorrelationId
).
to
receive
(
:current_or_new_id
).
and_return
(
'new-correlation-id'
)
elasticsearch_url
=
Gitlab
::
CurrentSettings
.
elasticsearch_url
[
0
]
stub_request
(
:any
,
elasticsearch_url
)
Project
.
__elasticsearch__
.
client
Project
.
__elasticsearch__
.
client
.
perform_request
(
:get
,
'/'
)
.
perform_request
(
:get
,
'/'
)
...
@@ -74,13 +79,30 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransportInterceptor, :el
...
@@ -74,13 +79,30 @@ RSpec.describe ::Gitlab::Instrumentation::ElasticsearchTransportInterceptor, :el
it
'does not override the X-Opaque-Id if it is already present'
do
it
'does not override the X-Opaque-Id if it is already present'
do
allow
(
Labkit
::
Correlation
::
CorrelationId
).
to
receive
(
:current_or_new_id
).
and_return
(
'new-correlation-id'
)
allow
(
Labkit
::
Correlation
::
CorrelationId
).
to
receive
(
:current_or_new_id
).
and_return
(
'new-correlation-id'
)
elasticsearch_url
=
Gitlab
::
CurrentSettings
.
elasticsearch_url
[
0
]
stub_request
(
:any
,
elasticsearch_url
)
Project
.
__elasticsearch__
.
client
Project
.
__elasticsearch__
.
client
.
perform_request
(
:get
,
'/'
,
{},
nil
,
{
'X-Opaque-Id'
:
'original-opaque-id'
})
.
perform_request
(
:get
,
'/'
,
{},
nil
,
{
'X-Opaque-Id'
:
'original-opaque-id'
})
expect
(
a_request
(
:get
,
/
#{
elasticsearch_url
}
/
)
expect
(
a_request
(
:get
,
/
#{
elasticsearch_url
}
/
)
.
with
(
headers:
{
'X-Opaque-Id'
=>
'original-opaque-id'
})).
to
have_been_made
.
with
(
headers:
{
'X-Opaque-Id'
=>
'original-opaque-id'
})).
to
have_been_made
end
end
context
'when the response indicates a server side timeout'
do
it
'increments timeouts'
do
stub_request
(
:any
,
/
#{
elasticsearch_url
}
/
).
to_return
(
body:
+
'{"timed_out": true}'
,
status:
200
,
headers:
{
'Content-Type'
=>
'application/json'
})
Project
.
__elasticsearch__
.
client
.
perform_request
(
:get
,
'/'
)
expect
(
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
get_timed_out_count
).
to
eq
(
1
)
end
end
context
'when the response does not indicate a server side timeout'
do
it
'does not increment timeouts'
do
stub_request
(
:any
,
/
#{
elasticsearch_url
}
/
).
to_return
(
body:
+
'{"timed_out": false}'
,
status:
200
,
headers:
{
'Content-Type'
=>
'application/json'
})
Project
.
__elasticsearch__
.
client
.
perform_request
(
:get
,
'/'
)
expect
(
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
get_timed_out_count
).
to
eq
(
0
)
end
end
end
end
ee/spec/lib/gitlab/instrumentation_helper_spec.rb
View file @
03f53df3
...
@@ -18,6 +18,7 @@ RSpec.describe Gitlab::InstrumentationHelper do
...
@@ -18,6 +18,7 @@ RSpec.describe Gitlab::InstrumentationHelper do
expect
(
payload
[
:elasticsearch_calls
]).
to
be
>
0
expect
(
payload
[
:elasticsearch_calls
]).
to
be
>
0
expect
(
payload
[
:elasticsearch_duration_s
]).
to
be
>
0
expect
(
payload
[
:elasticsearch_duration_s
]).
to
be
>
0
expect
(
payload
[
:elasticsearch_timed_out_count
]).
to
be_kind_of
(
Integer
)
end
end
end
end
end
end
...
...
lib/gitlab/instrumentation/elasticsearch_transport.rb
View file @
03f53df3
...
@@ -9,12 +9,15 @@ module Gitlab
...
@@ -9,12 +9,15 @@ module Gitlab
start
=
Time
.
now
start
=
Time
.
now
headers
=
(
headers
||
{})
headers
=
(
headers
||
{})
.
reverse_merge
({
'X-Opaque-Id'
:
Labkit
::
Correlation
::
CorrelationId
.
current_or_new_id
})
.
reverse_merge
({
'X-Opaque-Id'
:
Labkit
::
Correlation
::
CorrelationId
.
current_or_new_id
})
super
response
=
super
ensure
ensure
if
::
Gitlab
::
SafeRequestStore
.
active?
if
::
Gitlab
::
SafeRequestStore
.
active?
duration
=
(
Time
.
now
-
start
)
duration
=
(
Time
.
now
-
start
)
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
increment_request_count
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
increment_request_count
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
increment_timed_out_count
if
response
&
.
body
&
.
dig
(
'timed_out'
)
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
add_duration
(
duration
)
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
add_duration
(
duration
)
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
add_call_details
(
duration
,
method
,
path
,
params
,
body
)
::
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
add_call_details
(
duration
,
method
,
path
,
params
,
body
)
end
end
...
@@ -25,6 +28,7 @@ module Gitlab
...
@@ -25,6 +28,7 @@ module Gitlab
ELASTICSEARCH_REQUEST_COUNT
=
:elasticsearch_request_count
ELASTICSEARCH_REQUEST_COUNT
=
:elasticsearch_request_count
ELASTICSEARCH_CALL_DURATION
=
:elasticsearch_call_duration
ELASTICSEARCH_CALL_DURATION
=
:elasticsearch_call_duration
ELASTICSEARCH_CALL_DETAILS
=
:elasticsearch_call_details
ELASTICSEARCH_CALL_DETAILS
=
:elasticsearch_call_details
ELASTICSEARCH_TIMED_OUT_COUNT
=
:elasticsearch_timed_out_count
def
self
.
get_request_count
def
self
.
get_request_count
::
Gitlab
::
SafeRequestStore
[
ELASTICSEARCH_REQUEST_COUNT
]
||
0
::
Gitlab
::
SafeRequestStore
[
ELASTICSEARCH_REQUEST_COUNT
]
||
0
...
@@ -49,6 +53,15 @@ module Gitlab
...
@@ -49,6 +53,15 @@ module Gitlab
::
Gitlab
::
SafeRequestStore
[
ELASTICSEARCH_CALL_DURATION
]
+=
duration
::
Gitlab
::
SafeRequestStore
[
ELASTICSEARCH_CALL_DURATION
]
+=
duration
end
end
def
self
.
increment_timed_out_count
::
Gitlab
::
SafeRequestStore
[
ELASTICSEARCH_TIMED_OUT_COUNT
]
||=
0
::
Gitlab
::
SafeRequestStore
[
ELASTICSEARCH_TIMED_OUT_COUNT
]
+=
1
end
def
self
.
get_timed_out_count
::
Gitlab
::
SafeRequestStore
[
ELASTICSEARCH_TIMED_OUT_COUNT
]
||
0
end
def
self
.
add_call_details
(
duration
,
method
,
path
,
params
,
body
)
def
self
.
add_call_details
(
duration
,
method
,
path
,
params
,
body
)
return
unless
Gitlab
::
PerformanceBar
.
enabled_for_request?
return
unless
Gitlab
::
PerformanceBar
.
enabled_for_request?
...
...
lib/gitlab/instrumentation_helper.rb
View file @
03f53df3
...
@@ -15,6 +15,7 @@ module Gitlab
...
@@ -15,6 +15,7 @@ module Gitlab
:rugged_duration_s
,
:rugged_duration_s
,
:elasticsearch_calls
,
:elasticsearch_calls
,
:elasticsearch_duration_s
,
:elasticsearch_duration_s
,
:elasticsearch_timed_out_count
,
*::
Gitlab
::
Memory
::
Instrumentation
::
KEY_MAPPING
.
values
,
*::
Gitlab
::
Memory
::
Instrumentation
::
KEY_MAPPING
.
values
,
*::
Gitlab
::
Instrumentation
::
Redis
.
known_payload_keys
,
*::
Gitlab
::
Instrumentation
::
Redis
.
known_payload_keys
,
*::
Gitlab
::
Metrics
::
Subscribers
::
ActiveRecord
::
DB_COUNTERS
,
*::
Gitlab
::
Metrics
::
Subscribers
::
ActiveRecord
::
DB_COUNTERS
,
...
@@ -79,6 +80,7 @@ module Gitlab
...
@@ -79,6 +80,7 @@ module Gitlab
payload
[
:elasticsearch_calls
]
=
elasticsearch_calls
payload
[
:elasticsearch_calls
]
=
elasticsearch_calls
payload
[
:elasticsearch_duration_s
]
=
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
query_time
payload
[
:elasticsearch_duration_s
]
=
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
query_time
payload
[
:elasticsearch_timed_out_count
]
=
Gitlab
::
Instrumentation
::
ElasticsearchTransport
.
get_timed_out_count
end
end
def
instrument_external_http
(
payload
)
def
instrument_external_http
(
payload
)
...
...
spec/lib/gitlab/instrumentation_helper_spec.rb
View file @
03f53df3
...
@@ -16,6 +16,7 @@ RSpec.describe Gitlab::InstrumentationHelper do
...
@@ -16,6 +16,7 @@ RSpec.describe Gitlab::InstrumentationHelper do
:rugged_duration_s
,
:rugged_duration_s
,
:elasticsearch_calls
,
:elasticsearch_calls
,
:elasticsearch_duration_s
,
:elasticsearch_duration_s
,
:elasticsearch_timed_out_count
,
:mem_objects
,
:mem_objects
,
:mem_bytes
,
:mem_bytes
,
:mem_mallocs
,
:mem_mallocs
,
...
...
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