Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
b69216f7
Unverified
Commit
b69216f7
authored
6 years ago
by
Amber Brown
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make the metrics less racy (#4061)
parent
6a4d01ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/4061.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/4061.bugfix
synapse/http/request_metrics.py
+18
-13
18 additions, 13 deletions
synapse/http/request_metrics.py
synapse/notifier.py
+3
-3
3 additions, 3 deletions
synapse/notifier.py
with
22 additions
and
16 deletions
changelog.d/4061.bugfix
0 → 100644
+
1
−
0
View file @
b69216f7
Fix some metrics being racy and causing exceptions when polled by Prometheus.
This diff is collapsed.
Click to expand it.
synapse/http/request_metrics.py
+
18
−
13
View file @
b69216f7
...
...
@@ -39,7 +39,8 @@ outgoing_responses_counter = Counter(
)
response_timer
=
Histogram
(
"
synapse_http_server_response_time_seconds
"
,
"
sec
"
,
"
synapse_http_server_response_time_seconds
"
,
"
sec
"
,
[
"
method
"
,
"
servlet
"
,
"
tag
"
,
"
code
"
],
)
...
...
@@ -79,15 +80,11 @@ response_size = Counter(
# than when the response was written.
in_flight_requests_ru_utime
=
Counter
(
"
synapse_http_server_in_flight_requests_ru_utime_seconds
"
,
""
,
[
"
method
"
,
"
servlet
"
],
"
synapse_http_server_in_flight_requests_ru_utime_seconds
"
,
""
,
[
"
method
"
,
"
servlet
"
]
)
in_flight_requests_ru_stime
=
Counter
(
"
synapse_http_server_in_flight_requests_ru_stime_seconds
"
,
""
,
[
"
method
"
,
"
servlet
"
],
"
synapse_http_server_in_flight_requests_ru_stime_seconds
"
,
""
,
[
"
method
"
,
"
servlet
"
]
)
in_flight_requests_db_txn_count
=
Counter
(
...
...
@@ -134,7 +131,7 @@ def _get_in_flight_counts():
# type
counts
=
{}
for
rm
in
reqs
:
key
=
(
rm
.
method
,
rm
.
name
,
)
key
=
(
rm
.
method
,
rm
.
name
)
counts
[
key
]
=
counts
.
get
(
key
,
0
)
+
1
return
counts
...
...
@@ -175,7 +172,8 @@ class RequestMetrics(object):
if
context
!=
self
.
start_context
:
logger
.
warn
(
"
Context have unexpectedly changed %r, %r
"
,
context
,
self
.
start_context
context
,
self
.
start_context
,
)
return
...
...
@@ -192,10 +190,10 @@ class RequestMetrics(object):
resource_usage
=
context
.
get_resource_usage
()
response_ru_utime
.
labels
(
self
.
method
,
self
.
name
,
tag
).
inc
(
resource_usage
.
ru_utime
,
resource_usage
.
ru_utime
)
response_ru_stime
.
labels
(
self
.
method
,
self
.
name
,
tag
).
inc
(
resource_usage
.
ru_stime
,
resource_usage
.
ru_stime
)
response_db_txn_count
.
labels
(
self
.
method
,
self
.
name
,
tag
).
inc
(
resource_usage
.
db_txn_count
...
...
@@ -222,8 +220,15 @@ class RequestMetrics(object):
diff
=
new_stats
-
self
.
_request_stats
self
.
_request_stats
=
new_stats
in_flight_requests_ru_utime
.
labels
(
self
.
method
,
self
.
name
).
inc
(
diff
.
ru_utime
)
in_flight_requests_ru_stime
.
labels
(
self
.
method
,
self
.
name
).
inc
(
diff
.
ru_stime
)
# max() is used since rapid use of ru_stime/ru_utime can end up with the
# count going backwards due to NTP, time smearing, fine-grained
# correction, or floating points. Who knows, really?
in_flight_requests_ru_utime
.
labels
(
self
.
method
,
self
.
name
).
inc
(
max
(
diff
.
ru_utime
,
0
)
)
in_flight_requests_ru_stime
.
labels
(
self
.
method
,
self
.
name
).
inc
(
max
(
diff
.
ru_stime
,
0
)
)
in_flight_requests_db_txn_count
.
labels
(
self
.
method
,
self
.
name
).
inc
(
diff
.
db_txn_count
...
...
This diff is collapsed.
Click to expand it.
synapse/notifier.py
+
3
−
3
View file @
b69216f7
...
...
@@ -186,9 +186,9 @@ class Notifier(object):
def
count_listeners
():
all_user_streams
=
set
()
for
x
in
self
.
room_to_user_streams
.
values
():
for
x
in
list
(
self
.
room_to_user_streams
.
values
()
)
:
all_user_streams
|=
x
for
x
in
self
.
user_to_user_stream
.
values
():
for
x
in
list
(
self
.
user_to_user_stream
.
values
()
)
:
all_user_streams
.
add
(
x
)
return
sum
(
stream
.
count_listeners
()
for
stream
in
all_user_streams
)
...
...
@@ -196,7 +196,7 @@ class Notifier(object):
LaterGauge
(
"
synapse_notifier_rooms
"
,
""
,
[],
lambda
:
count
(
bool
,
self
.
room_to_user_streams
.
values
()),
lambda
:
count
(
bool
,
list
(
self
.
room_to_user_streams
.
values
())
)
,
)
LaterGauge
(
"
synapse_notifier_users
"
,
""
,
[],
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment