Skip to content

feat: restore federation metrics lost in native federation migration - #41959

Draft
KevLehman wants to merge 16 commits into
release-9.0.0from
feat/federation-metrics-parity
Draft

feat: restore federation metrics lost in native federation migration#41959
KevLehman wants to merge 16 commits into
release-9.0.0from
feat/federation-metrics-parity

Conversation

@KevLehman

@KevLehman KevLehman commented Aug 26, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Restores the federation statistics that regressed in the migration from the old federation implementations to native federation. Three claims fixed:

  1. externalConnectedServers always reported {quantity: 0, servers: []}. Its backing query, Rooms.countDistinctFederationRoomsExcluding, was a // TODO implement stub returning []. It now counts remote homeservers from rocketchat_federation_servers (the federation-sdk signing-key cache — one doc per remote homeserver we verified), excluding Federation_Service_Domain. The dead stub and its IRoomsModel typing are removed.

  2. Federation event volume was dropped entirely. The old federation reported federationOverviewData.numberOfEvents (lifetime event-store count); the native stack persists a full PDU store in rocketchat_federation_events but never reported it. New amountOfFederationEvents field on matrixFederation statistics, fed by estimatedDocumentCount() (collection metadata, no scan).

  3. amountOfExternalUsers over-counted on upgraded workspaces. Users.countFederatedExternalUsers counted {federated: true}, which includes stale users created by the removed matrix bridge (federated: true with no federation subdoc — verified against 6.9.7's FederatedUser.getStorageRepresentation). The query now also requires federation.version, which only native federation writes. LDAP-provisioned federated users keep being counted: they get the full native subdoc and are genuinely remote (getFederationHomeServer only fires when the mapped homeserver differs from the local domain).

Missing-collection safety: distinct/estimatedDocumentCount on nonexistent collections return []/0, so workspaces that never federated report zeros.

Issue(s)

Follow-up to #37059 and #41940 (old federation removals).

Steps to test or reproduce

  1. Run two federated workspaces (native federation enabled) and exchange messages in a federated room.
  2. Call POST /api/v1/statistics.generate (or wait for the usage report cron) on one of them.
  3. matrixFederation.externalConnectedServers lists the peer homeserver, amountOfFederationEvents > 0, and amountOfExternalUsers counts only users with a native federation subdoc.

Further comments

The raw db.collection() reads in the statistics adapter are deliberate: rocketchat_federation_servers and rocketchat_federation_events are owned by @rocket.chat/federation-sdk (no model exists on the Rocket.Chat side), and creating models for two read-only counts wasn't worth the ceremony.

Review in cubic

ggazzo and others added 16 commits August 25, 2026 11:55
Co-authored-by: Julio Araujo <julio.araujo@rocket.chat>
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
@dionisio-bot

dionisio-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release-9.0.0@2b359ff). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##             release-9.0.0   #41959   +/-   ##
================================================
  Coverage                 ?   69.52%           
================================================
  Files                    ?     4224           
  Lines                    ?   167736           
  Branches                 ?    29864           
================================================
  Hits                     ?   116616           
  Misses                   ?    45977           
  Partials                 ?     5143           
Flag Coverage Δ
e2e 59.16% <ø> (?)
e2e-api 46.16% <66.66%> (?)
unit 71.21% <ø> (?)

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KevLehman KevLehman added this to the 9.0.0 milestone Aug 26, 2026
@tassoevan
tassoevan force-pushed the release-9.0.0 branch 2 times, most recently from 438d65b to 6152fca Compare August 27, 2026 18:53
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.

6 participants