Skip to content

fix: handle numeric JSON values from Gen2 Miniserver endpoints - #98

Merged
discostu105 merged 2 commits into
mainfrom
fix/json-numeric-values
Mar 22, 2026
Merged

fix: handle numeric JSON values from Gen2 Miniserver endpoints#98
discostu105 merged 2 commits into
mainfrom
fix/json-numeric-values

Conversation

@discostu105

Copy link
Copy Markdown
Owner

Summary

  • Bug: lox status --diag showed blank values for context switches, interrupts, comm interrupts, and ctx switches (idle) on Gen2 Miniservers (firmware 16.x)
  • Root cause: xml_attr JSON branch only matched string values ("value": "text"), but Gen2 returns numeric counters without quotes ("value": 123456)
  • Same bug affected lox otel serve/pushextract_lox_value used as_str() which skips numeric JSON values, so OTLP metrics for these endpoints were silently dropped

Fixed

  • xml_attr: handle both quoted string and unquoted numeric/bool/null JSON values
  • extract_lox_value (OTLP): try as_f64() before as_str() for JSON values
  • Diagnostics display: skip interrupt/ctx-switch rows when endpoint returns no data (instead of printing blank lines)

Regression tests added (12 new)

  • xml_attr: float, negative, zero, bool, null, and a comprehensive test exercising all diagnostic endpoints in both Gen1 XML and Gen2 JSON-numeric formats
  • extract_lox_value: numeric float, numeric zero, and a comprehensive test covering every OTLP-exported endpoint

Total: 287 tests (194 unit + 93 integration)

Test plan

  • cargo fmt --check — clean
  • cargo clippy -- -D warnings — clean
  • cargo build --release — passes
  • cargo test — 287 tests pass
  • Manual: lox status --diag on Gen2 Miniserver shows interrupt/ctx-switch values
  • Manual: lox otel push exports loxone.system.interrupts etc. as metrics

Gen2 Miniservers (firmware 16.x) return numeric values without quotes
for counter endpoints like contextswitches, ints, comints, and
contextswitchesi — e.g. `"value": 123456` instead of `"value": "123"`.

The xml_attr JSON branch only matched string values ("value": "..."),
so these counters silently returned empty strings, causing blank rows
in `lox status --diag` and missing OTLP metrics.

Fixes:
- xml_attr: handle both quoted and unquoted JSON values
- extract_lox_value (OTLP): try as_f64() before as_str() so numeric
  JSON values are picked up for gauge/counter recording
- Diagnostics display: skip interrupt/ctx-switch rows when the
  endpoint returns no data (instead of showing blank lines)

Adds 3 new tests: xml_attr_json_numeric_value,
xml_attr_json_numeric_last_field, extract_lox_value_json_numeric.
Adds 12 new tests to prevent future regressions when the Miniserver
returns non-string JSON values:

xml_attr tests (8 new):
- json_float_value, json_negative_value, json_zero_value
- json_bool_value, json_null_value
- all_diagnostic_response_formats (exercises every diag endpoint in
  both Gen1 XML and Gen2 JSON-numeric format)

extract_lox_value tests (4 new):
- json_numeric_float, json_numeric_zero
- all_diagnostic_formats (covers every OTLP-exported endpoint)
@codecov

codecov Bot commented Mar 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.75000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.97%. Comparing base (55baa72) to head (5f05c5d).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/commands/system.rs 0.00% 18 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #98      +/-   ##
==========================================
+ Coverage   24.88%   24.97%   +0.08%     
==========================================
  Files          16       16              
  Lines        4629     4649      +20     
==========================================
+ Hits         1152     1161       +9     
- Misses       3477     3488      +11     
Files with missing lines Coverage Δ
src/main.rs 44.95% <100.00%> (+0.80%) ⬆️
src/otel.rs 12.19% <100.00%> (+0.53%) ⬆️
src/commands/system.rs 12.90% <0.00%> (-0.24%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@discostu105
discostu105 merged commit 34d2576 into main Mar 22, 2026
7 checks passed
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