Skip to content

Fix metrics chart not rendering (Redis TS 1.8+ QUERYINDEX compatibility)#16

Open
mgodwin wants to merge 1 commit into
mainfrom
claude/heuristic-rubin-a5fbac
Open

Fix metrics chart not rendering (Redis TS 1.8+ QUERYINDEX compatibility)#16
mgodwin wants to merge 1 commit into
mainfrom
claude/heuristic-rubin-a5fbac

Conversation

@mgodwin

@mgodwin mgodwin commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Root cause: Redis TimeSeries 1.8+ requires at least one equality filter (label=value) in TS.QUERYINDEX. The previous code used only existence filters (name!= compaction!=), which raises ERR TSDB: please provide at least one matcher. This error was silently caught, leaving @all_series = [] — which caused the controller to fall back to the wrong default compaction (avg instead of sum for counters), produce no chart data, and render a blank section with no feedback.
  • Two code paths were broken: the index action (chart rendering) and the labels action (group-by options).
  • Dotted metric names (request.count) also failed to route to the labels member endpoint without an explicit constraint.

Changes

File Change
metrics_controller.rb index: add .where(compaction: %w[sum avg min max]) to provide required equality filter; labels: use query_index(metric_name) directly (generates name=value equality filter, more efficient)
metrics/index.html.erb Add explicit "No data for X in the selected time range" message when metric is selected but chart data is empty — previously nothing was rendered
config/routes.rb Add constraints: { name: /[^\/]+/ } so metric names containing dots route correctly to the labels endpoint
metrics_controller_test.rb New: 18 tests covering index (summary stats, chart rendering, data format, stacking, explicit params), autocomplete, and labels endpoints
test/dummy/db/schema.rb Rails version bump artifact (7.1 → 8.1)

Test plan

  • Run bin/rails test test/controllers/rails_observatory/metrics_controller_test.rb — all 18 tests pass
  • Navigate to /observatory/metrics, click the search field, select a metric, verify the chart renders
  • Verify the "No data for X" message appears when selecting a metric with no data in the current time window

…raint

Redis TimeSeries 1.8+ requires at least one equality filter in TS.QUERYINDEX.
The previous code used only existence filters (name!= compaction!=), which
raised "ERR TSDB: please provide at least one matcher". This was silently
caught, leaving @all_series empty, causing the controller to default to the
wrong compaction type and return no chart data.

Fixes:
- index action: add .where(compaction: %w[sum avg min max]) to satisfy the
  equality filter requirement while still returning all metric series
- labels action: use query_index(metric_name) directly, which generates a
  name=<value> equality filter and is more efficient than filtering in Ruby
- routes: add constraints: { name: /[^\/]+/ } so dotted metric names like
  request.count route correctly to the labels member endpoint
- view: add explicit empty state when a metric is selected but has no data
  in the current time range (previously rendered nothing at all)

Adds MetricsControllerTest with 18 tests covering index, autocomplete,
and labels endpoints.
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