← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~andersson123/autopkgtest-cloud:fix-bad-metrics-math into autopkgtest-cloud:master

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:fix-bad-metrics-math into autopkgtest-cloud:master.

Commit message:
fix: worker: fix bad math in tools/metrics

I recently made an MP that introduced a new metric - the cloud worker
active unit percentage.

I noticed this morning on the KPI that there were some negative values,
and realised that the math in the previous implementation was only valid
under certain circumstances, so I've modified it in this MP.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/469807

I did some very silly math in the previous implementation here, causing negative values when the number of units in error were greater than that of the active units. I fixed this with a better calculation.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:fix-bad-metrics-math into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/metrics b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/metrics
index fadd7b5..759efba 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/metrics
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/metrics
@@ -51,7 +51,7 @@ def make_submission(counts, measurement, send_percentage=False):
         }
         out.append(m)
         if send_percentage:
-            active_percentage = int(100 - ((error / active) * 100))
+            active_percentage = int((active / (error + active)) * 100)
             m = {
                 "measurement": f"{measurement}_active_percentage",
                 "fields": {"percentage": active_percentage},