Browse Source

Make statsd key look like the keys from shade

openstacksdk produces task names that look like compute.DELETE.servers,
which are {service_type}.{METHOD}.{url}.{parts} but shade and nodepool
have been reporting to statsd with {Service_type}{Method}{Url}{Parts}.

Translate the task.name produced by sdk into the key nodepool expects to
report as.

Also, emit 'Manager ran task' log lines

The super class emits these, but on the openstacksdk logger. We don't
really want to turn that on at debug level for normal usage, so rather
than calling super(post_run_task) just straight-up override it.

Make sure we log using the transformed name in all cases.

Change-Id: I7f21aefc204366f7621643fdba76b7e70ce4caf5
Monty Taylor 9 months ago
parent
commit
67824d8e64
No account linked to committer's email address
1 changed files with 17 additions and 3 deletions
  1. 17
    3
      nodepool/task_manager.py

+ 17
- 3
nodepool/task_manager.py View File

@@ -26,6 +26,14 @@ from openstack import task_manager as openstack_task_manager
26 26
 from nodepool import stats
27 27
 
28 28
 
29
+def _transform_task_name(task_name):
30
+    # openstacksdk sets task.name to something like "compute.DELETE.servers"
31
+    # We want ComputeDeleteServers
32
+    return "".join(
33
+        [part.lower().capitalize() for part in task_name.split('.')]
34
+    )
35
+
36
+
29 37
 class ManagerStoppedException(Exception):
30 38
     pass
31 39
 
@@ -68,7 +76,9 @@ class TaskManager(openstack_task_manager.TaskManager):
68 76
                         break
69 77
                     time.sleep(self.rate - delta)
70 78
                 self.log.debug("Manager %s running task %s (queue %s)" %
71
-                               (self.name, task.name, self.queue.qsize()))
79
+                               (self.name,
80
+                                _transform_task_name(task.name),
81
+                                self.queue.qsize()))
72 82
                 self.run_task(task)
73 83
                 self.queue.task_done()
74 84
         except Exception:
@@ -76,10 +86,14 @@ class TaskManager(openstack_task_manager.TaskManager):
76 86
             raise
77 87
 
78 88
     def post_run_task(self, elapsed_time, task):
79
-        super(TaskManager, self).post_run_task(elapsed_time, task)
89
+        task_name = _transform_task_name(task.name)
90
+        self.log.debug(
91
+            "Manager %s ran task %s in %ss" %
92
+            (self.name, task_name, elapsed_time))
93
+
80 94
         if self.statsd:
81 95
             # nodepool.task.PROVIDER.TASK_NAME
82
-            key = 'nodepool.task.%s.%s' % (self.name, task.name)
96
+            key = 'nodepool.task.%s.%s' % (self.name, task_name)
83 97
             self.statsd.timing(key, int(elapsed_time * 1000))
84 98
             self.statsd.incr(key)
85 99
 

Loading…
Cancel
Save