Skip to content

feat: custom metric units display and formatting - #790

Open
123FLO321 wants to merge 35 commits into
rajnandan1:mainfrom
123FLO321:feature/custom-metric-units
Open

feat: custom metric units display and formatting#790
123FLO321 wants to merge 35 commits into
rajnandan1:mainfrom
123FLO321:feature/custom-metric-units

Conversation

@123FLO321

@123FLO321 123FLO321 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Custom metric units

Monitors aren't always about latency (e.g. a worker queue length).
You can now configure per monitor how its value is displayed.

  • Display name: replaces "Latency" in all labels (e.g. "Queue length")
  • Unit: any suffix (items, %, ppl, …), none for a bare number; empty keeps the default ms with the usual ms -> s/m/h auto-scaling
  • Decimals: 0–4 fixed, or auto

Display-only: values still arrive as latency through the existing paths (API monitor eval, PATCH /api/v4/monitors/[tag]/data), nothing changes in storage or the public API. Existing monitors render exactly as before. For custom units, 0 is a valid reading instead of "no data".

Applied everywhere the value shows up: status page, charts/tooltips, day detail, badges, embeds, admin tables.

image image image

For next major (potentially)

  • Rename latencyvalue (DB column, MonitoringResult, v4 API)
  • Potentially multiple metrics per monitor

requires #789

Summary by CodeRabbit

  • New Features
    • Added configurable “Metric Display” settings (custom name, unit, decimals) to relabel and reformat latency/value across dashboards, charts, badges, embeds, and monitoring logs/tables.
  • Bug Fixes
    • Improved missing-translation placeholder interpolation so %name variables resolve more consistently.
    • Updated custom-unit behavior so zero readings display correctly where applicable.
  • Documentation
    • Added v4 documentation for Metric Display settings, including examples.
  • Tests / CI
    • Expanded automated test suites (client/server) and added CI to run checks, browser tests, and type checking.

123FLO321 added 26 commits July 13, 2026 20:51
…superpowers

Shell scripts checked out with CRLF on Windows (core.autocrlf=true) broke
the Docker entrypoint at container start. Force LF for all text files at
the git layer, matching the existing .editorconfig and Prettier settings.
Whitespace-only line-wrap fixes found by prettier --check during Task 7
verification; no logic changes.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c0a8d39e-65f3-428f-b46b-53ad7403a100

📥 Commits

Reviewing files that changed from the base of the PR and between 575d7f7 and 2292df1.

📒 Files selected for processing (1)
  • .github/workflows/test.yml

📝 Walkthrough

Walkthrough

Adds configurable metric names, units, and decimal formatting across monitor storage, APIs, management screens, charts, embeds, and badges. It also adds Vitest browser/server projects, tests, CI execution, documentation, and translation support.

Changes

Configurable metric display

Layer / File(s) Summary
Formatting and aggregation
src/lib/server/types/db.ts, src/lib/clientTools.ts, src/lib/server/tool.ts, src/lib/server/db/repositories/monitoring.ts
Adds value-display types, custom-unit formatting, latency sample counts, zero-value handling, and updated uptime aggregation.
Server propagation and API responses
src/lib/server/api-server/..., src/lib/server/controllers/..., src/routes/(kener)/...
Carries display settings and latency counts through monitor responses, day-latency results, badges, and page data.
Metric display configuration
src/routes/(manage)/manage/app/monitors/..., src/routes/(manage)/manage/app/monitoring-data/+page.svelte
Adds configuration editing, validation, persistence, parsing, dynamic labels, and unit-aware monitoring data output.
Monitor and embed views
src/lib/components/*, src/routes/(embed)/*, src/routes/(kener)/*, src/lib/locales/en.json
Applies custom names and formatting to charts, calendars, tooltips, badges, embeds, statistics, and empty states.
Validation, CI, and documentation
.github/workflows/test.yml, vite.config.ts, *test.ts, CLAUDE.md, src/routes/(docs)/*
Adds Vitest projects, browser/server tests, CI execution, development commands, translation interpolation coverage, and metric-display documentation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MonitorAPI
  participant MonitorOverview
  participant StatusBarCalendar
  participant LatencyTrendChart
  MonitorAPI->>MonitorOverview: monitor data and valueDisplay
  MonitorOverview->>StatusBarCalendar: status data and valueDisplay
  MonitorOverview->>LatencyTrendChart: chart data and valueDisplay
  StatusBarCalendar-->>MonitorOverview: formatted tooltip values
  LatencyTrendChart-->>MonitorOverview: formatted trend values
Loading

Possibly related PRs

  • rajnandan1/kener#789: Adds related repository-wide testing setup and overlapping component/server test coverage.

Poem

A rabbit hops through metrics bright,
With custom names and units light.
Zeroes now can bloom and stay,
Charts and badges dance away.
Tests guard every burrowed byte.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: custom metric units display and formatting.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds custom display settings for monitor metric values. The main changes are:

  • Configurable metric name, unit, and decimal formatting for monitors.
  • Shared value formatting across charts, badges, embeds, status pages, and admin views.
  • Reading-count tracking so null metric rows are not shown as real zero samples.
  • Tests and CI coverage for the new formatting and component behavior.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
src/lib/server/db/repositories/monitoring.ts Adds non-null reading counts to monitor aggregate queries.
src/lib/server/tool.ts Updates value aggregation to use custom unit formatting and reading-count gates.
src/lib/clientTools.ts Adds shared helpers for custom unit detection, reading detection, and value formatting.
src/lib/components/StatusBarCalendar.svelte Updates calendar tooltips and day detail wiring for custom metric display.
src/lib/components/MonitorOverview.svelte Updates overview labels, chart data, and summary values for custom metric display.
src/lib/components/MonitorDayDetail.svelte Updates day detail chart labels and filters for custom metric values.
src/lib/server/api-server/monitor-bar/shared.ts Passes metric display settings into monitor bar response aggregation.
src/lib/server/api-server/monitor-day-latency/post.ts Updates minute-level metric filtering and formatting for custom units.

Reviews (4): Last reviewed commit: "style: fix indents" | Re-trigger Greptile

Comment thread src/lib/server/tool.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/test.yml:
- Around line 9-11: Update the workflow containing the test job to explicitly
set the default GITHUB_TOKEN permissions to read-only, preferably with a
top-level permissions block granting contents: read; preserve the existing
jobs.test configuration and avoid granting broader permissions.

In `@src/routes/`(embed)/embed/monitor-[tag]/+page.svelte:
- Around line 80-86: Extract the trimmed value-display name into a derived
variable named customName alongside the existing derived declarations,
defaulting to an empty string when unavailable. Update the template condition
and translated label to use customName instead of repeating
overviewData?.valueDisplay?.name?.trim(), while preserving the “Avg Latency”
fallback.

In
`@src/routes/`(manage)/manage/app/monitors/[tag]/components/ModifyDataCard.svelte:
- Around line 22-23: Remove the duplicated displayName and unitSuffix
derivations from ModifyDataCard.svelte and reuse the shared derivation
introduced by the consolidated implementation, preserving the existing fallback
values and valueDisplay behavior.

In
`@src/routes/`(manage)/manage/app/monitors/[tag]/components/MonitorRecentLogs.svelte:
- Around line 23-24: Remove the duplicate displayName and unitSuffix derivations
from MonitorRecentLogs.svelte and reuse the existing shared derivation or
consolidated implementation established with ModifyDataCard.svelte, preserving
the current Latency and ms defaults.
- Around line 25-26: Update the recent-log latency rendering to use
FormatValue(log.latency, valueDisplay) instead of appending valueSuffix
directly, while preserving the existing valueDisplay configuration and
surrounding log layout.

In
`@src/routes/`(manage)/manage/app/monitors/[tag]/components/MonitorTypeCard.svelte:
- Around line 46-55: Update the testResultLabel derivation in MonitorTypeCard to
recognize the unit suffix case-insensitively, so any capitalization of “ms”
renders as “milliseconds” while preserving custom-unit text unchanged. Align
this display logic with the existing IsCustomUnit behavior used by
clientTools.ts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f5f64751-f944-4804-8e2c-f82a25f63386

📥 Commits

Reviewing files that changed from the base of the PR and between e5b745e and 78b903c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (46)
  • .gitattributes
  • .github/workflows/test.yml
  • .gitignore
  • CLAUDE.md
  • migrations/20250111153517_init.ts
  • package.json
  • src/lib/clientTools.test.ts
  • src/lib/clientTools.ts
  • src/lib/components/BadgesMenu.svelte
  • src/lib/components/CopyButton.svelte.test.ts
  • src/lib/components/EmbedMenu.svelte
  • src/lib/components/LatencyTrendChart.svelte
  • src/lib/components/MonitorBar.svelte
  • src/lib/components/MonitorDayDetail.svelte
  • src/lib/components/MonitorOverview.svelte
  • src/lib/components/StatusBarCalendar.svelte
  • src/lib/components/StatusBarCalendar.svelte.test.ts
  • src/lib/components/ThemePlus.svelte
  • src/lib/locales/en.json
  • src/lib/server/api-server/monitor-bar/get.ts
  • src/lib/server/api-server/monitor-bar/shared.ts
  • src/lib/server/api-server/monitor-day-latency/post.ts
  • src/lib/server/controllers/monitorsController.ts
  • src/lib/server/tool.test.ts
  • src/lib/server/tool.ts
  • src/lib/server/types/db.ts
  • src/lib/server/types/monitor.ts
  • src/lib/stores/i18n.test.ts
  • src/lib/stores/i18n.ts
  • src/routes/(api)/api/v4/monitors/[monitor_tag]/data/+server.ts
  • src/routes/(api)/api/v4/monitors/[monitor_tag]/data/[timestamp]/+server.ts
  • src/routes/(docs)/docs/content/v4/monitors.md
  • src/routes/(embed)/embed/latency-[tag]/+page.svelte
  • src/routes/(embed)/embed/monitor-[tag]/+page.svelte
  • src/routes/(kener)/monitors/[monitor_tag]/+page.server.ts
  • src/routes/(kener)/monitors/[monitor_tag]/+page.svelte
  • src/routes/(manage)/manage/app/monitoring-data/+page.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/+page.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/components/MetricDisplayCard.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/components/MetricDisplayCard.svelte.test.ts
  • src/routes/(manage)/manage/app/monitors/[tag]/components/ModifyDataCard.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/components/MonitorRecentLogs.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/components/MonitorTypeCard.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/types/monitor-group.svelte
  • vite.config.ts
  • vitest-setup-client.ts

Comment thread .github/workflows/test.yml
Comment thread src/routes/(embed)/embed/monitor-[tag]/+page.svelte
Comment thread src/routes/(manage)/manage/app/monitors/[tag]/components/ModifyDataCard.svelte Outdated
Comment thread src/routes/(manage)/manage/app/monitors/[tag]/components/MonitorRecentLogs.svelte Outdated
123FLO321 and others added 3 commits July 14, 2026 18:24
Day-level aggregates for custom-unit monitors treated buckets whose readings
were all NULL as real 0 samples: SQL AVG/MIN/MAX correctly ignore per-row
NULLs, but an all-NULL bucket collapses to a NULL aggregate that the JS
mapping coerced to 0, and the custom-unit gate (DayHasData) only checked
status counts, which stayed true. Carry a non-NULL latency reading count
(latencyCount, via COUNT(latency)) through the aggregate pipeline and gate
on it instead (DayHasReading), matching how the minute-level endpoint
already excludes no-reading samples.
@123FLO321 123FLO321 changed the title feat: custom metric units feat: custom metric units display and formatting Jul 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/routes/(kener)/monitors/[monitor_tag]/+page.server.ts (1)

61-68: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Simplify assignment logic using optional chaining and nullish coalescing.

While functionally correct (since a falsy 0 latency safely falls back to 0), relying on number truthiness checks can be slightly confusing. You can clean this up and make it more idiomatic by using the ?. and ?? operators.

♻️ Proposed refactor
-    countOfUp: lastStatus && lastStatus.status === GC.UP ? 1 : 0,
-    countOfDown: lastStatus && lastStatus.status === GC.DOWN ? 1 : 0,
-    countOfDegraded: lastStatus && lastStatus.status === GC.DEGRADED ? 1 : 0,
-    countOfMaintenance: lastStatus && lastStatus.status === GC.MAINTENANCE ? 1 : 0,
-    avgLatency: lastStatus && lastStatus.latency ? lastStatus.latency : 0,
-    maxLatency: lastStatus && lastStatus.latency ? lastStatus.latency : 0,
-    minLatency: lastStatus && lastStatus.latency ? lastStatus.latency : 0,
-    latencyCount: lastStatus && lastStatus.latency !== null ? 1 : 0,
+    countOfUp: lastStatus?.status === GC.UP ? 1 : 0,
+    countOfDown: lastStatus?.status === GC.DOWN ? 1 : 0,
+    countOfDegraded: lastStatus?.status === GC.DEGRADED ? 1 : 0,
+    countOfMaintenance: lastStatus?.status === GC.MAINTENANCE ? 1 : 0,
+    avgLatency: lastStatus?.latency ?? 0,
+    maxLatency: lastStatus?.latency ?? 0,
+    minLatency: lastStatus?.latency ?? 0,
+    latencyCount: lastStatus?.latency != null ? 1 : 0,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/routes/`(kener)/monitors/[monitor_tag]/+page.server.ts around lines 61 -
68, In the monitor status aggregation object, simplify the lastStatus property
accessors using optional chaining and nullish coalescing: update countOfUp,
countOfDown, countOfDegraded, countOfMaintenance, and the latency fields so
absent values default to 0 without truthiness checks, while preserving
latencyCount’s null-handling behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/routes/`(kener)/monitors/[monitor_tag]/+page.server.ts:
- Around line 61-68: In the monitor status aggregation object, simplify the
lastStatus property accessors using optional chaining and nullish coalescing:
update countOfUp, countOfDown, countOfDegraded, countOfMaintenance, and the
latency fields so absent values default to 0 without truthiness checks, while
preserving latencyCount’s null-handling behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cd42256b-8dc1-4792-8a28-74aac6caf84b

📥 Commits

Reviewing files that changed from the base of the PR and between 78b903c and 935617c.

📒 Files selected for processing (21)
  • .github/workflows/test.yml
  • src/lib/clientTools.ts
  • src/lib/components/MonitorOverview.svelte
  • src/lib/components/StatusBarCalendar.svelte
  • src/lib/components/StatusBarCalendar.svelte.test.ts
  • src/lib/server/api-server/monitor-bar/shared.ts
  • src/lib/server/api-server/monitor-bars/get.ts
  • src/lib/server/api-server/monitor-day-status/post.ts
  • src/lib/server/controllers/dashboardController.ts
  • src/lib/server/db/repositories/monitoring.ts
  • src/lib/server/tool.test.ts
  • src/lib/server/tool.ts
  • src/lib/server/types/db.ts
  • src/routes/(docs)/docs/content/v4/monitors.md
  • src/routes/(embed)/embed/latency-[tag]/+page.svelte
  • src/routes/(embed)/embed/monitor-[tag]/+page.svelte
  • src/routes/(kener)/monitors/[monitor_tag]/+page.server.ts
  • src/routes/(manage)/manage/app/monitoring-data/+page.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/components/ModifyDataCard.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/components/MonitorRecentLogs.svelte
  • src/routes/(manage)/manage/app/monitors/[tag]/components/MonitorTypeCard.svelte

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.

1 participant