Merge pull request #11927 from fosterseth/fix_subsystem_metrics_sync_in_async

Fix subsystem metrics sync-only operation in async context
This commit is contained in:
Seth Foster
2022-03-22 11:55:05 -04:00
committed by GitHub
2 changed files with 6 additions and 3 deletions

View File

@@ -136,7 +136,7 @@ class HistogramM(BaseM):
class Metrics: class Metrics:
def __init__(self, auto_pipe_execute=True): def __init__(self, auto_pipe_execute=True, instance_name=None):
self.pipe = redis.Redis.from_url(settings.BROKER_URL).pipeline() self.pipe = redis.Redis.from_url(settings.BROKER_URL).pipeline()
self.conn = redis.Redis.from_url(settings.BROKER_URL) self.conn = redis.Redis.from_url(settings.BROKER_URL)
self.last_pipe_execute = time.time() self.last_pipe_execute = time.time()
@@ -150,7 +150,10 @@ class Metrics:
# the calling function should call .pipe_execute() explicitly # the calling function should call .pipe_execute() explicitly
self.auto_pipe_execute = auto_pipe_execute self.auto_pipe_execute = auto_pipe_execute
Instance = apps.get_model('main', 'Instance') Instance = apps.get_model('main', 'Instance')
self.instance_name = Instance.objects.me().hostname if instance_name:
self.instance_name = instance_name
else:
self.instance_name = Instance.objects.me().hostname
# metric name, help_text # metric name, help_text
METRICSLIST = [ METRICSLIST = [

View File

@@ -71,7 +71,7 @@ class WebsocketTask:
self.protocol = protocol self.protocol = protocol
self.verify_ssl = verify_ssl self.verify_ssl = verify_ssl
self.channel_layer = None self.channel_layer = None
self.subsystem_metrics = s_metrics.Metrics() self.subsystem_metrics = s_metrics.Metrics(instance_name=name)
async def run_loop(self, websocket: aiohttp.ClientWebSocketResponse): async def run_loop(self, websocket: aiohttp.ClientWebSocketResponse):
raise RuntimeError("Implement me") raise RuntimeError("Implement me")