#425 Fix formatting of metrics code
Merged 3 years ago by lsedlar. Opened 3 years ago by lsedlar.
lsedlar/odcs black-followup  into  master

file modified
+11 -4
@@ -36,6 +36,7 @@ 

      from odcs.server.celery_tasks import celery_app

      from celery.utils.objects import FallbackContext

      import amqp.exceptions

+ 

      CELERY_AVAILABLE = True

  except ImportError:

      CELERY_AVAILABLE = False
@@ -116,6 +117,7 @@ 

      - celery_workers_totals - Number of alive workers.

      - celery_workers[worker_name] - 1 if worker is online, 0 if offline.

      """

+ 

      def __init__(self, registry=None):

          super(WorkerCountThread, self).__init__()

          self.daemon = True
@@ -124,8 +126,10 @@ 

          )

          self.workers_total.set(0)

          self.workers = Gauge(

-             "celery_workers", "Number of alive workers", ["worker_name"],

-             registry=registry

+             "celery_workers",

+             "Number of alive workers",

+             ["worker_name"],

+             registry=registry,

          )

          self.worker_names = set()

  
@@ -163,12 +167,15 @@ 

  

      - celery_queue_length[queue_name] - Number of tasks waiting in the queue.

      """

+ 

      def __init__(self, registry=None):

          super(QueueLengthThread, self).__init__()

          self.daemon = True

          self.queue_length = Gauge(

-             "celery_queue_length", "Number of tasks in the queue.",

-             ["queue_name"], registry=registry

+             "celery_queue_length",

+             "Number of tasks in the queue.",

+             ["queue_name"],

+             registry=registry,

          )

  

          # Get all the possible queue names from the config.

file modified
+6 -10
@@ -26,9 +26,7 @@ 

  from odcs.server.models import Compose

  from odcs.common.types import COMPOSE_RESULTS

  from odcs.server.pungi import PungiSourceType

- from odcs.server.metrics import (

-     ComposesCollector, QueueLengthThread, WorkerCountThread

- )

+ from odcs.server.metrics import ComposesCollector, QueueLengthThread, WorkerCountThread

  from .utils import ModelsBaseTest

  

  
@@ -95,7 +93,6 @@ 

  

  

  class TestQueueLengthThread(ModelsBaseTest):

- 

      @patch("odcs.server.metrics.celery_app")

      def test_update_metrics(self, celery_app):

          conn = celery_app.connection_or_acquire.return_value
@@ -110,21 +107,20 @@ 

              for sample in metric.samples:

                  queues.add(sample.labels["queue_name"])

                  self.assertEqual(sample.value, 10)

-             self.assertEqual(queues, set(["cleanup", "pungi_composes", "pulp_composes"]))

+             self.assertEqual(

+                 queues, set(["cleanup", "pungi_composes", "pulp_composes"])

+             )

  

  

  class TestWorkerCountThread(ModelsBaseTest):

- 

      @patch("odcs.server.metrics.celery_app")

      def test_update_metrics(self, celery_app):

          celery_app.control.ping.side_effect = [

              [

                  {"worker-1@localhost": {"ok": "pong"}},

-                 {"worker-2@localhost": {"ok": "pong"}}

-             ],

-             [

-                 {"worker-1@localhost": {"ok": "pong"}}

+                 {"worker-2@localhost": {"ok": "pong"}},

              ],

+             [{"worker-1@localhost": {"ok": "pong"}}],

          ]

  

          # Both workers online.

This code was merged around the big formatting update and was missed.

Pull-Request has been merged by lsedlar

3 years ago