← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~ack/maas-kpi:log-bugs into maas-kpi:master

 

Alberto Donato has proposed merging ~ack/maas-kpi:log-bugs into maas-kpi:master.

Commit message:
log collected bugs to stderr



Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~ack/maas-kpi/+git/maas-kpi/+merge/441932
-- 
Your team MAAS Committers is requested to review the proposed merge of ~ack/maas-kpi:log-bugs into maas-kpi:master.
diff --git a/maaskpi/base.py b/maaskpi/base.py
index fe0de1e..2c023b4 100644
--- a/maaskpi/base.py
+++ b/maaskpi/base.py
@@ -1,4 +1,5 @@
 import argparse
+import sys
 from contextlib import contextmanager
 
 from influxdb.line_protocol import make_lines
@@ -33,21 +34,23 @@ class Collector:
         self.parser.add_argument(
             "-o",
             "--output",
-            default="/dev/stdout",
-            nargs="?",
+            type=argparse.FileType("wb"),
+            default=sys.stdout.buffer,
             help="Path to the file where the metrics are written to",
         )
         self.registry = CollectorRegistry()
 
+    def log(self, msg):
+        print(msg, file=sys.stderr)
+
     def run_collect(self, args):
         return self.collect()
 
     def run(self):
         args = self.parser.parse_args()
-        with open(args.output, "wb") as destination:
-            for series in self.run_collect(args):
-                with get_and_reset(series) as points:
-                    destination.write(make_lines({"points": points}).encode("utf-8"))
+        for series in self.run_collect(args):
+            with get_and_reset(series) as points:
+                args.output.write(make_lines({"points": points}).encode("utf-8"))
 
 
 class LaunchpadCollector(Collector):
diff --git a/maaskpi/bugs.py b/maaskpi/bugs.py
index 0fb1b3a..3bb6de2 100644
--- a/maaskpi/bugs.py
+++ b/maaskpi/bugs.py
@@ -1,5 +1,3 @@
-import sys
-
 from influxdb import SeriesHelper
 
 from .base import LaunchpadCollector
@@ -47,6 +45,7 @@ class BugsCollector(LaunchpadCollector):
     def _collect_bugs(
         self, record_series, lp_project, project_label, ignored_related_projects=()
     ):
+        self.log(f"Tasks for {project_label}:")
         counts = dict.fromkeys(record_series.Meta.fields, 0)
         for task in lp_project.searchTasks():
             ignore = ignored_related_projects and any(
@@ -56,25 +55,25 @@ class BugsCollector(LaunchpadCollector):
             if ignore:
                 continue
 
+            bug = task.bug
             status = task.status
             if status == "Incomplete":
-                if task.date_incomplete < task.bug.date_last_message:
+                if task.date_incomplete < bug.date_last_message:
                     status += "WithResponse"
                 else:
                     status += "WithoutResponse"
             counts[status_to_field(status)] += 1
+            self.log(f"{bug.id} | {status:25} | {bug.title}")
         # influx mutates state in the class via the constructor
         record_series(**counts, project=project_label)
 
     def collect(self, lp):
-        print("Searching maas tasks....", file=sys.stderr)
         self._collect_bugs(
             OpenBugsSeries,
             lp.projects["maas"],
             "core",
             ignored_related_projects=[lp.projects["maas-ui"]],
         )
-        print("Searching maas-ui tasks....", file=sys.stderr)
         self._collect_bugs(OpenBugsSeries, lp.projects["maas-ui"], "ui")
         yield OpenBugsSeries
 

Follow ups