This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix replication metrics when using redis #7325
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for running replication over Redis when using workers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,10 +50,7 @@ | |||||
import fcntl | ||||||
import logging | ||||||
import struct | ||||||
from collections import defaultdict | ||||||
from typing import TYPE_CHECKING, DefaultDict, List | ||||||
|
||||||
from six import iteritems | ||||||
from typing import TYPE_CHECKING, List | ||||||
|
||||||
from prometheus_client import Counter | ||||||
|
||||||
|
@@ -86,6 +83,18 @@ | |||||
"synapse_replication_tcp_protocol_close_reason", "", ["reason_type"] | ||||||
) | ||||||
|
||||||
tcp_inbound_commands_counter = Counter( | ||||||
"synapse_replication_tcp_protocol_inbound_commands", | ||||||
"Number of commands received from replication", | ||||||
["command", "name"], | ||||||
) | ||||||
|
||||||
tcp_outbound_commands_counter = Counter( | ||||||
"synapse_replication_tcp_protocol_outbound_commands", | ||||||
"Number of commands sent to replication", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
["command", "name"], | ||||||
) | ||||||
|
||||||
# A list of all connected protocols. This allows us to send metrics about the | ||||||
# connections. | ||||||
connected_connections = [] | ||||||
|
@@ -151,9 +160,6 @@ def __init__(self, clock: Clock, handler: "ReplicationCommandHandler"): | |||||
# The LoopingCall for sending pings. | ||||||
self._send_ping_loop = None | ||||||
|
||||||
self.inbound_commands_counter = defaultdict(int) # type: DefaultDict[str, int] | ||||||
self.outbound_commands_counter = defaultdict(int) # type: DefaultDict[str, int] | ||||||
|
||||||
def connectionMade(self): | ||||||
logger.info("[%s] Connection established", self.id()) | ||||||
|
||||||
|
@@ -224,9 +230,7 @@ def lineReceived(self, line: bytes): | |||||
|
||||||
self.last_received_command = self.clock.time_msec() | ||||||
|
||||||
self.inbound_commands_counter[cmd.NAME] = ( | ||||||
self.inbound_commands_counter[cmd.NAME] + 1 | ||||||
) | ||||||
tcp_inbound_commands_counter.labels(cmd.NAME, self.name).inc() | ||||||
|
||||||
# Now lets try and call on_<CMD_NAME> function | ||||||
run_as_background_process( | ||||||
|
@@ -292,9 +296,8 @@ def send_command(self, cmd, do_buffer=True): | |||||
self._queue_command(cmd) | ||||||
return | ||||||
|
||||||
self.outbound_commands_counter[cmd.NAME] = ( | ||||||
self.outbound_commands_counter[cmd.NAME] + 1 | ||||||
) | ||||||
tcp_outbound_commands_counter.labels(cmd.NAME, self.name).inc() | ||||||
|
||||||
string = "%s %s" % (cmd.NAME, cmd.to_line()) | ||||||
if "\n" in string: | ||||||
raise Exception("Unexpected newline in command: %r", string) | ||||||
|
@@ -546,26 +549,3 @@ def transport_kernel_read_buffer_size(protocol, read=True): | |||||
for p in connected_connections | ||||||
}, | ||||||
) | ||||||
|
||||||
|
||||||
tcp_inbound_commands = LaterGauge( | ||||||
"synapse_replication_tcp_protocol_inbound_commands", | ||||||
"", | ||||||
["command", "name"], | ||||||
lambda: { | ||||||
(k, p.name): count | ||||||
for p in connected_connections | ||||||
for k, count in iteritems(p.inbound_commands_counter) | ||||||
}, | ||||||
) | ||||||
|
||||||
tcp_outbound_commands = LaterGauge( | ||||||
"synapse_replication_tcp_protocol_outbound_commands", | ||||||
"", | ||||||
["command", "name"], | ||||||
lambda: { | ||||||
(k, p.name): count | ||||||
for p in connected_connections | ||||||
for k, count in iteritems(p.outbound_commands_counter) | ||||||
}, | ||||||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're not connection IDs, they're what they're connected to, will change