⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@alco
Copy link
Member

@alco alco commented Jan 16, 2026

Summary

  • Restore mode and median fields to CallHomeReporter summary metrics payload
  • Add schema validation test to prevent future regressions

Problem

PR #3422 optimized CallHomeReporter memory usage and removed mode and median from summary statistics as a side-effect since calculating those would have interfered with the optimization effort and they weren't used in reporting analytics anyway. However, the remote telemetry server requires these fields for validation, causing all reports to be rejected silently.

Solution

Add placeholder values (median: 0, mode: nil) to satisfy the remote schema validation without reverting the memory-efficient running-tally approach. I have chosen to make these changes instead of changing the remote server's validation because the latter is not actively maintained and was last deployed 7 months ago. I deemed making changes to it too risky.

Regression Prevention

Added a test that validates the payload against a copy of the remote server's JSON schema. If the payload structure changes in a way that would break remote validation, this test will fail.

Summary by CodeRabbit

  • New Features

    • Telemetry summaries now include median and mode alongside min, max, and mean.
    • Telemetry reports are validated against a new strict remote schema to ensure payload compliance.
  • Tests

    • Added tests validating telemetry payloads against the remote schema and asserting median/mode presence in summaries.
  • Chores

    • Updated test/dev configuration and added a patch changelog entry.

✏️ Tip: You can customize this high-level summary in your review settings.

alco added 4 commits January 16, 2026 14:55
…y payload

The remote telemetry server requires 'mode' and 'median' fields in summary
metrics for validation. These were removed in commit 6a64347 as part of
memory optimization work.

This adds placeholder values (median: 0, mode: nil) to satisfy the remote
schema validation without reverting the memory-efficient running-tally
approach for computing statistics.
…tests

This dependency will be used to validate CallHomeReporter payloads against
the remote server's JSON schema, guarding against validation regressions.
This schema is a copy of the one used by the remote telemetry server to
validate incoming CallHomeReporter payloads. If either schema changes,
both must be kept in sync to prevent validation failures.
This test validates that StackTelemetry report data conforms to the remote
server's JSON schema, preventing regressions where payload changes break
remote validation.

The test uses @external_resource to track the schema file, ensuring the
test recompiles when the schema changes.
@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

Default Summary metric payloads now include median and mode; a JSON Schema for call-home telemetry was added; tests updated to validate reports against that schema and to expect the new summary fields; test dependencies for JSON and schema validation were added.

Changes

Cohort / File(s) Summary
Summary Metric Structure Enhancement
packages/electric-telemetry/lib/electric/telemetry/call_home_reporter.ex, packages/electric-telemetry/lib/electric/telemetry/measurement.ex
Default summary metric payloads now include median: 0 and mode: nil in addition to min, max, and mean for :summary paths; documentation updated to reflect shape.
Build / Dev/Test Dependencies
packages/electric-telemetry/mix.exs
Added ex_json_schema ~> 0.10 for tests and jason ~> 1.4 to dev/test deps.
Remote Schema
packages/electric-telemetry/test/support/call_home_remote_schema.json
New JSON Schema defining the call-home payload, including Summary objects that require max, mean, median, min, and mode.
Call Home Reporter Tests
packages/electric-telemetry/test/electric/telemetry/call_home_reporter_test.exs
Load remote schema from test support file; add schema-conformance test using ExJsonSchema.Validator; switch payload decoding to Jason.decode!; update test setup for remote schema.
Measurement Tests
packages/electric-telemetry/test/electric/telemetry/measurement_test.exs
Tests extended to assert median == 0 and mode == nil on summary results across relevant cases.
Changelog / Changeset
.changeset/pink-pumpkins-switch.md
Added patch changeset describing reinstatement of median and mode fields in CallHomeReporter summaries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibbled through the metrics heap,

Restored median and mode from sleep,
A schema gate now checks each byte,
Tests applaud — the payloads right,
Hooray, the telemetry's complete! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the pull request: fixing a payload validation failure in CallHomeReporter by restoring missing median and mode fields.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 70be42c and 1fbfa3f.

📒 Files selected for processing (2)
  • .changeset/pink-pumpkins-switch.md
  • packages/electric-telemetry/lib/electric/telemetry/measurement.ex
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
.changeset/pink-pumpkins-switch.md

5-5: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test packages/react-hooks w/ sync-service
  • GitHub Check: Test packages/y-electric w/ sync-service
  • GitHub Check: Test packages/start w/ sync-service
  • GitHub Check: Test packages/typescript-client w/ sync-service
  • GitHub Check: Test packages/experimental w/ sync-service
  • GitHub Check: Run Lux integration tests
🔇 Additional comments (3)
packages/electric-telemetry/lib/electric/telemetry/measurement.ex (2)

21-32: Documentation accurately describes the new summary shape.

The moduledoc now clearly documents:

  • The actual summary map shape including median and mode
  • That only min, max, and mean are calculated from actual measurements
  • That median and mode are placeholders for downstream compatibility

This addresses the previous review comment about updating the documentation.


157-170: Implementation correctly adds placeholder fields for schema compatibility.

The median: 0 and mode: nil placeholders align with the documented behavior and satisfy the remote telemetry server's JSON schema requirements. The approach is sound given the ETS-based design constraints explained in the moduledoc.

.changeset/pink-pumpkins-switch.md (1)

1-5: Changeset entry is well-written and comprehensive.

The description correctly identifies:

  • The scope of the change (Summary metrics in CallHomeReporter)
  • All affected metrics (used_memory, run_queue_total, run_queue_cpu, run_queue_io, wal_size)
  • The root cause (remote collector server rejecting reports)

The static analysis MD041 warning is a false positive—changeset files intentionally use YAML frontmatter (---) at the start rather than a Markdown heading.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.94%. Comparing base (5a767e6) to head (1fbfa3f).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3727      +/-   ##
==========================================
- Coverage   84.01%   82.94%   -1.08%     
==========================================
  Files          44       35       -9     
  Lines        2834     2380     -454     
  Branches      534      529       -5     
==========================================
- Hits         2381     1974     -407     
+ Misses        451      404      -47     
  Partials        2        2              
Flag Coverage Δ
electric-telemetry 58.80% <100.00%> (?)
elixir 58.80% <100.00%> (-17.02%) ⬇️
elixir-client ?
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/typescript-client 93.47% <ø> (ø)
packages/y-electric 56.05% <ø> (ø)
typescript 87.36% <ø> (ø)
unit-tests 82.94% <100.00%> (-1.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blacksmith-sh

This comment has been minimized.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/electric-telemetry/lib/electric/telemetry/measurement.ex`:
- Around line 153-159: Update the moduledoc in the Measurement module to reflect
the new summary shape that now includes median and mode placeholders: modify the
documentation in
packages/electric-telemetry/lib/electric/telemetry/measurement.ex (the moduledoc
for the Measurement module) to list min, max, mean, median, and mode in the
summary structure and update any examples and descriptive text to mention that
median defaults to 0 and mode to nil (or their intended types/semantics); ensure
the documented shape matches the actual map returned in the code snippets around
the summary construction (the map containing min, max, mean, median, mode).
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f10e5a4 and 76f9167.

⛔ Files ignored due to path filters (1)
  • packages/electric-telemetry/mix.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • packages/electric-telemetry/lib/electric/telemetry/call_home_reporter.ex
  • packages/electric-telemetry/lib/electric/telemetry/measurement.ex
  • packages/electric-telemetry/mix.exs
  • packages/electric-telemetry/test/electric/telemetry/call_home_reporter_test.exs
  • packages/electric-telemetry/test/electric/telemetry/measurement_test.exs
  • packages/electric-telemetry/test/support/call_home_remote_schema.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test packages/typescript-client w/ sync-service
  • GitHub Check: Test packages/experimental w/ sync-service
  • GitHub Check: Test packages/react-hooks w/ sync-service
  • GitHub Check: Test packages/y-electric w/ sync-service
  • GitHub Check: Test packages/start w/ sync-service
  • GitHub Check: Run Lux integration tests
🔇 Additional comments (6)
packages/electric-telemetry/lib/electric/telemetry/call_home_reporter.ex (1)

204-207: Default summary payload now aligns with schema.

Line 206 adds median/mode placeholders to the default summary map, keeping payloads consistent with the updated summary shape. Looks good.

packages/electric-telemetry/test/electric/telemetry/measurement_test.exs (2)

285-479: Summary tests aligned with placeholder median/mode fields.

The added assertions (Line 293-478) consistently cover the new median and mode placeholders. This keeps the summary test suite aligned with the updated payload shape.


561-565: Multi-metric interaction test updated correctly.

The additional median/mode assertions (Line 564-565) align with the new summary structure. Looks good.

packages/electric-telemetry/test/electric/telemetry/call_home_reporter_test.exs (1)

4-14: The current validation is correct; no changes needed.

The schema (call_home_remote_schema.json) is designed for the data payload contents, not the full report envelope. Its root properties (electric_version, environment, resources, usage) and required fields match the structure within report["data"]. Validating report["data"] against @remote_schema at line 126 is the intended behavior.

Likely an incorrect or invalid review comment.

packages/electric-telemetry/mix.exs (1)

39-41: No action needed. The JSON schema uses draft-06, which is supported by ex_json_schema "~> 0.10".

packages/electric-telemetry/test/support/call_home_remote_schema.json (1)

1-177: LGTM! Schema correctly captures the remote validation requirements.

The schema is well-structured and aligns with the PR objectives:

  • The Summary definition (lines 109-138) correctly requires median and mode fields
  • The mode field uses anyOf: [number, null] (lines 126-133) which properly supports the mode: nil placeholder value
  • Using additionalProperties: false on nested definitions ensures strict validation that mirrors the remote server's behavior

This schema will effectively catch payload regressions in tests before they reach the remote telemetry server.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.changeset/pink-pumpkins-switch.md:
- Line 5: Update the changeset description to reflect that the restored median
and mode fields apply to all Summary metrics in CallHomeReporter (not just
wal_size); edit the message in .changeset/pink-pumpkins-switch.md so it states
something like: "Bring back previously removed median and mode fields to Summary
metrics in CallHomeReporter’s default payload (applies to run_queue_total,
run_queue_cpu, run_queue_io, wal_size); their absence caused the remote
collector to reject reports." Reference CallHomeReporter (call_home_reporter.ex)
and the Summary metric defaults so the scope is clear.
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76f9167 and 70be42c.

📒 Files selected for processing (1)
  • .changeset/pink-pumpkins-switch.md
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
.changeset/pink-pumpkins-switch.md

5-5: First line in a file should be a top-level heading

(MD041, first-line-heading, first-line-h1)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

alco added 2 commits January 16, 2026 15:57
Document that summaries now include median and mode placeholder fields
(defaulting to 0 and nil respectively) for compatibility with downstream
consumers that expect these fields in the summary structure.
@alco alco force-pushed the alco/call-home-reporter-payload-fix branch from 70be42c to 1fbfa3f Compare January 16, 2026 14:58
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.

2 participants