From acebff7be1591b40d03acdd4c93c825db9a7409c Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Mon, 21 Mar 2022 11:40:19 -0400 Subject: [PATCH] Fix sync-only operation in async context --- awx/main/analytics/subsystem_metrics.py | 7 +++++-- awx/main/wsbroadcast.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/awx/main/analytics/subsystem_metrics.py b/awx/main/analytics/subsystem_metrics.py index 2e4c8b41c7..a08211b311 100644 --- a/awx/main/analytics/subsystem_metrics.py +++ b/awx/main/analytics/subsystem_metrics.py @@ -136,7 +136,7 @@ class HistogramM(BaseM): 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.conn = redis.Redis.from_url(settings.BROKER_URL) self.last_pipe_execute = time.time() @@ -150,7 +150,10 @@ class Metrics: # the calling function should call .pipe_execute() explicitly self.auto_pipe_execute = auto_pipe_execute 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 METRICSLIST = [ diff --git a/awx/main/wsbroadcast.py b/awx/main/wsbroadcast.py index 47006adc9d..9ed7b47848 100644 --- a/awx/main/wsbroadcast.py +++ b/awx/main/wsbroadcast.py @@ -71,7 +71,7 @@ class WebsocketTask: self.protocol = protocol self.verify_ssl = verify_ssl 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): raise RuntimeError("Implement me")