๐ Bug Summary
Five related bugs found in the top performers metrics panel, discovered during investigation of #3580:
-
build_top_performers() loses 0.0 metric values โ metrics_common.py uses falsy checks (if result.success_rate) which coerce a genuine 0.0 success rate (100% failure) or 0.0 avg response time to None, losing the distinction between "no data" and an actual zero value.
-
Dead != 'N/A' guard in template โ metrics_top_performers_partial.html checks avg_response != 'N/A', but avgResponseTime is Optional[float] and can only be None or a float โ never the string 'N/A'. The branch is unreachable.
-
Dead != 'Never' guard in template โ similarly, the template checks last_exec != 'Never', but lastExecution from jsonable_encoder is either None or an ISO datetime string, never the string 'Never'. The branch is unreachable.
-
Raw ISO datetime display in "Last Used" column โ the template renders {{ last_exec }} verbatim, producing unreadable output like 2024-01-15T10:30:00.000000 in the UI instead of a human-friendly format like 2024-01-15 10:30.
-
successRate: None displays as 0.0% with a red error badge โ the or 0 fallback collapses None (no executions yet) into 0, making a tool with no data look like it has a 100% failure rate. Should display "N/A" with no badge, matching the avgResponseTime treatment.
๐งฉ Affected Component
๐ Steps to Reproduce
- Navigate to the Admin UI โ Metrics tab โ Top Performers panel
- Observe the "Last Used" column โ ISO timestamps are displayed raw (e.g.
2024-01-15T10:30:00.000000)
- Observe the "Success Rate" column for a tool that has never been executed โ it shows
0.0% with a red badge instead of N/A
- For bug 1: register a tool with 0% success rate โ the panel treats it as if it has no metrics at all
๐ค Expected Behavior
- A
success_rate or avg_response_time of 0.0 should be preserved and displayed as 0.0, not treated as missing data.
- The
!= 'N/A' guard should be removed (dead code); None check is sufficient.
- The
!= 'Never' guard should be removed (dead code); falsy check on None is sufficient.
- The "Last Used" column should display a human-readable datetime like
2024-01-15 10:30 instead of a raw ISO string.
- The "Success Rate" column should display
N/A (no badge) for entities with no execution data, not 0.0% with a red error badge.
๐ Logs / Error Output
No stack traces. These are silent display/logic bugs.
๐ง Environment Info
| Key |
Value |
| Version or commit |
main |
| Runtime |
Python 3.11, Gunicorn |
| Platform / OS |
any |
| Container |
any |
๐งฉ Additional Context (optional)
- Affects
mcpgateway/utils/metrics_common.py (build_top_performers function)
- Affects
mcpgateway/templates/metrics_top_performers_partial.html (avg response, success rate, last execution columns)
๐ Bug Summary
Five related bugs found in the top performers metrics panel, discovered during investigation of #3580:
build_top_performers()loses 0.0 metric values โmetrics_common.pyuses falsy checks (if result.success_rate) which coerce a genuine0.0success rate (100% failure) or0.0avg response time toNone, losing the distinction between "no data" and an actual zero value.Dead
!= 'N/A'guard in template โmetrics_top_performers_partial.htmlchecksavg_response != 'N/A', butavgResponseTimeisOptional[float]and can only beNoneor a float โ never the string'N/A'. The branch is unreachable.Dead
!= 'Never'guard in template โ similarly, the template checkslast_exec != 'Never', butlastExecutionfromjsonable_encoderis eitherNoneor an ISO datetime string, never the string'Never'. The branch is unreachable.Raw ISO datetime display in "Last Used" column โ the template renders
{{ last_exec }}verbatim, producing unreadable output like2024-01-15T10:30:00.000000in the UI instead of a human-friendly format like2024-01-15 10:30.successRate: Nonedisplays as0.0%with a red error badge โ theor 0fallback collapsesNone(no executions yet) into0, making a tool with no data look like it has a 100% failure rate. Should display "N/A" with no badge, matching theavgResponseTimetreatment.๐งฉ Affected Component
mcpgateway- UI (admin panel)mcpgateway- API๐ Steps to Reproduce
2024-01-15T10:30:00.000000)0.0%with a red badge instead ofN/A๐ค Expected Behavior
success_rateoravg_response_timeof0.0should be preserved and displayed as0.0, not treated as missing data.!= 'N/A'guard should be removed (dead code);Nonecheck is sufficient.!= 'Never'guard should be removed (dead code); falsy check onNoneis sufficient.2024-01-15 10:30instead of a raw ISO string.N/A(no badge) for entities with no execution data, not0.0%with a red error badge.๐ Logs / Error Output
No stack traces. These are silent display/logic bugs.
๐ง Environment Info
mainPython 3.11, Gunicorn๐งฉ Additional Context (optional)
mcpgateway/utils/metrics_common.py(build_top_performersfunction)mcpgateway/templates/metrics_top_performers_partial.html(avg response, success rate, last execution columns)