Skip to content

Refactor: right align metrics email#1943

Open
MarceloRobert wants to merge 3 commits into
kernelci:mainfrom
MarceloRobert:refactor/right-align-metrics
Open

Refactor: right align metrics email#1943
MarceloRobert wants to merge 3 commits into
kernelci:mainfrom
MarceloRobert:refactor/right-align-metrics

Conversation

@MarceloRobert

@MarceloRobert MarceloRobert commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Readjusts the email formatting so that the larger number sections have a right-aligned text.

Changes

  • Turned left-aligned text in metrics email's sections "COVERAGE" and "TEST LAB ACTIVITY" into right-aligned text;
  • Adjusted spacing for some columns;
  • Changed double space before change percentage into a single space (that's 123 (+99%) into 123 (+99%));
  • Removed percentage sign if the metric diff is 0. This was done because many labs don't have tests, so the (+0%) can clutter the change column.
  • Used dynamic spacing on Coverage and Test Labs Activity in order to avoid large empty spaces on all-small numbers and also avoid lack of space for larger-than-usual numbers

How to test

  • Have data in the database, I used /backend/tests_submissions/submissions.zip for testing
  • Run poetry run python3 manage.py notifications --action metrics_summary and compare with the older version

Visual Reference

Example of new format:

KernelCI Metrics Summary
========================
Period: 2026-06-13 17:33 UTC to 2026-06-20 17:33 UTC


  COVERAGE
  --------
                   This week  Last week   Change
                   ─────────  ─────────  ───────
  Trees monitored          4          0       +4
  Checkouts               32          0      +32
  Builds                 103          0     +103
  Tests               15,720          0  +15,720


  BUILD REGRESSIONS
  -----------------
  A "regression" is defined as a reported problem affecting 0 or multiple builds.

  Origin    Regressions       Affected           Affected builds by top issues
            (known + new)     Builds (total)     #1      #2      #3
  ─────────────────────────────────────────────────────────────────────────
  maestro   0   + 1   = 1     1                  1       
  ─────────────────────────────────────────────────────────────────────────
  Total     0   + 1   = 1     1


  TOP REGRESSIONS PER ORIGIN
  --------------------------
  maestro:
    #1 (1 occurrences) -  in vmlinux (Makefile:1220) [logspec:kbuild,kbuild.other]
      Dashboard: https://d.kernelci.org/issue/maestro:5dd754a8374e1b44291f37f6a3510603dcbc6348?iv=1
  

  TEST LABS ACTIVITY
  ------------------
  13 labs reported results this week (13 more than last week).

  Labs marked with an asterisk (*) are new.

  Lab                    Covered builds   Boots    Tests   Change (tests)
  ───────────────────────────────────────────────────────────────────────
  lava-baylibre *                     1       1        0                0
  lava-broonie *                     41       8    3,467           +3,467
  lava-cip *                          1       1        0                0
  lava-clabbe *                       3       3        0                0
  lava-collabora *                   82      29    1,805           +1,805
  lava-foundriesio *                  2       2        0                0
  lava-kci-qualcomm *                 1       0        1               +1
  lava-pengutronix *                  3       3        0                0
  linaro *                          174     229   10,119          +10,119
  maestro *                           1       0        2               +2
  microsoft *                         1       0        3               +3
  opentest-ti *                       2       2        0                0
  redhat *                            1       0       45              +45
  ───────────────────────────────────────────────────────────────────────
  Total                             313     278   15,442          +15,442

--
This is an experimental report format. Please send feedback in!
Talk to us at kernelci@lists.linux.dev

Made with love by the KernelCI team - https://kernelci.org

Closes #1938

@MarceloRobert MarceloRobert marked this pull request as ready for review June 20, 2026 17:34
@MarceloRobert MarceloRobert changed the title [WIP] Refactor: right align metrics email Refactor: right align metrics email Jun 20, 2026
@MarceloRobert MarceloRobert force-pushed the refactor/right-align-metrics branch from a1270f2 to fb68cfd Compare June 20, 2026 17:59

@alanpeixinho alanpeixinho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are the G.O.A.T. Nice work

diff = cur - prev
if diff == 0:
return "0 (0%)"
return "0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: is there any reason we are not just following the show_percentage parameter here? to decide if we should show or not?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we return a tuple of int instead? Then the template can align them separately, and we further separate data processing from templating

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure tbh, but even still the lab changes are currently using percentages but they would be better off if the zeroes didn't have the percentage IMO

percentage = round((diff / prev) * 100)
percentage_sign = "+" if percentage > 0 else ""
return f"{signed_diff} ({percentage_sign}{percentage}%)"
return f"{signed_diff} ({percentage_sign}{percentage}%)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: perhaps we could use f"{diff:+} {percentage:+}" here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get it. The difference between f"{signed_diff} ({percentage_sign}{percentage}%)" and f"{diff:+} {percentage:+}" would be from +100 (+200%) to +100 +200 for diff = 100 and prev = 50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only meant to use '+' format modifier, but is not necessary.

@mentonin mentonin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this. I like that you included dynamic field spacing too! I left some comments for improvements, but they are not blockers

{{ "{:>{width}}".format("Change", width=change_space) }}
{#-#}
{{ "{:<{width}}".format("", width=label_space) -}}
{{ "{:>{width}}".format("─" * (current_week_space-static_spacing), width=current_week_space) -}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make this horizontal rule consistent with the other tables'?

{{ "{:>{width}}".format(deltas.n_tests, width=change_space) }}


BUILD REGRESSIONS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILD REGRESSIONS should also be right aligned for consistency

@MarceloRobert MarceloRobert Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not needed to change build regressions since the scale there is smaller, eg. https://groups.io/g/kernelci-results/message/61332

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave the auto-width out, but align the numbers right? the report you linked to still spans 3 orders of magnitude on Affected Builds

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works, done.

Comment on lines +126 to +128
{%- set lab_builds_space = [ns.lab_builds_len, "Covered builds"|length] | max + static_spacing -%}
{%- set lab_boots_space = [ns.lab_boots_len, "Boots"|length] | max + static_spacing -%}
{%- set lab_tests_space = [ns.lab_tests_len, "Tests"|length] | max + static_spacing -%}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can drop these if you initialize ns with the label lengths instead of 0

{%- set lab_change_len = deltas.labs.values() | map('length') | max -%}
{%- set lab_change_space = [lab_change_len, "Change (tests)"|length] | max + static_spacing -%}

{%- set separator_length = lab_names_space + lab_builds_space + lab_boots_space + lab_tests_space + lab_change_space - 2 -%}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is often called an horizontal rule (or rule, hrule, or hr) instead of the more generic "separator"

{#- Compute the text spacing in jinja instead of python to consider the `fmt` macro -#}
{%- set static_spacing = 3 -%}
{%- set lab_names_len = lab_maps.keys() | map('length') | max -%}
{%- set lab_names_space = [lab_names_len, "Lab"|length ] | max + static_spacing + 2 -%} {#- +2 for the possible ` *` -#}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: group all *_space for a table together

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdym by grouping? just remove the empty lines between the variables? I think it helps to discern which steps are happening and which order they'll appear

diff = cur - prev
if diff == 0:
return "0 (0%)"
return "0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we return a tuple of int instead? Then the template can align them separately, and we further separate data processing from templating

{{ "{:>{width}}".format(fmt(0), width=lab_tests_space) -}}
{{ "{:>{width}}".format(deltas.labs.get(lab_key, ""), width=lab_change_space) }}
{% endfor %}
{{- " " + "─" * separator_length}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting - can (should) we add jinja template formatting to the project?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it's hard to get a good formatting here because if I just remove the " " it will be misaligned, if I add a space before {{"─" * separator_length}} it will contain the line break after {% endfor %}, and if I add the space there but add a -%} at the endfor to ignore the line break it will also ignore the space which will make it misaligned anyway.

I could of course keep it the way it was ({% endfor %} {{ "─" * separator_length}}) but IMO it looks worse having both commands in the same line

@MarceloRobert MarceloRobert force-pushed the refactor/right-align-metrics branch from fb68cfd to 6ffa3e6 Compare June 24, 2026 12:22
@mentonin

Copy link
Copy Markdown
Contributor

LGTM

Readjusts the email formatting so that the larger number sections have a right-aligned text

Part of kernelci#1938

Signed-off-by: Marcelo Robert Santos <4mrSantos@gmail.com>
Calculates the space required for the data and labels within jinja to avoid empty spaces or crammed values in the Coverage and Test Labs Activity sections

It is possible to do it in Python but then we would need the fmt macro outside as well. A value such as 1000 might count as 4 chars in python but it is displayed as a 5-char 1,000 in jinja. Also, these spaces only make sense for the jinja template anyway, so I think it is correct to keep them within it.

Signed-off-by: Marcelo Robert Santos <4mrSantos@gmail.com>
Closes kernelci#1938

Signed-off-by: Marcelo Robert Santos <4mrSantos@gmail.com>
@MarceloRobert MarceloRobert force-pushed the refactor/right-align-metrics branch from 6ffa3e6 to 381f98a Compare June 25, 2026 12:11
@MarceloRobert

Copy link
Copy Markdown
Contributor Author

@mentonin I refactored the build regressions section to right align there too, but I'm using static spacing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Right-align number columns on plaintext reports

3 participants