forked from MirrorHub/synapse
Fix incorrect metrics reporting for renew_attestations (#7344)
We need to wait for the renewals to finish, so that the metrics are correctly reported.
This commit is contained in:
parent
036fab5d8a
commit
07337fe30b
2 changed files with 10 additions and 10 deletions
1
changelog.d/7344.bugfix
Normal file
1
changelog.d/7344.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix incorrect metrics reporting for `renew_attestations` background task.
|
|
@ -37,15 +37,16 @@ An attestation is a signed blob of json that looks like:
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
from signedjson.sign import sign_json
|
from signedjson.sign import sign_json
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.errors import HttpResponseException, RequestSendFailed, SynapseError
|
from synapse.api.errors import HttpResponseException, RequestSendFailed, SynapseError
|
||||||
from synapse.logging.context import run_in_background
|
|
||||||
from synapse.metrics.background_process_metrics import run_as_background_process
|
from synapse.metrics.background_process_metrics import run_as_background_process
|
||||||
from synapse.types import get_domain_from_id
|
from synapse.types import get_domain_from_id
|
||||||
|
from synapse.util.async_helpers import yieldable_gather_results
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -162,19 +163,19 @@ class GroupAttestionRenewer(object):
|
||||||
def _start_renew_attestations(self):
|
def _start_renew_attestations(self):
|
||||||
return run_as_background_process("renew_attestations", self._renew_attestations)
|
return run_as_background_process("renew_attestations", self._renew_attestations)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def _renew_attestations(self):
|
||||||
def _renew_attestations(self):
|
|
||||||
"""Called periodically to check if we need to update any of our attestations
|
"""Called periodically to check if we need to update any of our attestations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
now = self.clock.time_msec()
|
now = self.clock.time_msec()
|
||||||
|
|
||||||
rows = yield self.store.get_attestations_need_renewals(
|
rows = await self.store.get_attestations_need_renewals(
|
||||||
now + UPDATE_ATTESTATION_TIME_MS
|
now + UPDATE_ATTESTATION_TIME_MS
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _renew_attestation(group_id, user_id):
|
def _renew_attestation(group_user: Tuple[str, str]):
|
||||||
|
group_id, user_id = group_user
|
||||||
try:
|
try:
|
||||||
if not self.is_mine_id(group_id):
|
if not self.is_mine_id(group_id):
|
||||||
destination = get_domain_from_id(group_id)
|
destination = get_domain_from_id(group_id)
|
||||||
|
@ -207,8 +208,6 @@ class GroupAttestionRenewer(object):
|
||||||
"Error renewing attestation of %r in %r", user_id, group_id
|
"Error renewing attestation of %r in %r", user_id, group_id
|
||||||
)
|
)
|
||||||
|
|
||||||
for row in rows:
|
await yieldable_gather_results(
|
||||||
group_id = row["group_id"]
|
_renew_attestation, ((row["group_id"], row["user_id"]) for row in rows)
|
||||||
user_id = row["user_id"]
|
)
|
||||||
|
|
||||||
run_in_background(_renew_attestation, group_id, user_id)
|
|
||||||
|
|
Loading…
Reference in a new issue