Skip to content

Conversation

@d-gubert
Copy link
Member

@d-gubert d-gubert commented Oct 24, 2025

Proposed changes (including videos or screenshots)

Gives us more observability to the experimental API bridge.

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Chores
    • Added timing around application bridge method execution; timers are ensured to stop even if errors occur.
    • Introduced a new summary metric to track bridge method call counts and durations, with bridge/method/app labels for improved observability.
    • No changes to public/exported API signatures.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 24, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2025

⚠️ No Changeset found

Latest commit: 5c84ec1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2025

Walkthrough

Instruments the experimental app bridge's getUserRoomIds with a timing Summary: starts a timer before work and stops it in a finally block; adds a new metrics Summary appBridgeMethods to record bridge, method, and app_id labels.

Changes

Cohort / File(s) Summary
App bridge instrumentation
apps/meteor/app/apps/server/bridges/experimental.ts
Added metrics import, started a timer via metrics.appBridgeMethods.startTimer(...) before core work, wrapped logic in try/finally and ensured timer.stop() in finally, and maps Subscriptions to a local result array before returning.
Metrics registry
apps/meteor/app/metrics/server/lib/metrics.ts
Added exported appBridgeMethods Summary metric (rocketchat_apps_bridge_methods) with labels bridge, method, app_id, using existing percentiles.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as App code
  participant Bridge as AppExperimentalBridge.getUserRoomIds
  participant Metrics as metrics.appBridgeMethods
  participant DB as Subscriptions DB

  Note over Caller,Bridge: Caller invokes getUserRoomIds(userId, app)
  Caller->>Bridge: getUserRoomIds(userId, app)
  Bridge->>Metrics: startTimer({bridge, method, app_id})  %%{bg: #E7F3FF}%%
  activate Bridge
  alt fetch subscriptions
    Bridge->>DB: query Subscriptions by userId
    DB-->>Bridge: subscriptions[]
    Bridge->>Bridge: map subscriptions -> result[]
    Bridge-->>Caller: return result[]
  end
  Bridge->>Metrics: timer.stop()  %%{bg: #FFF4E6}%%
  deactivate Bridge
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check metric name, label names, and integration into existing registry.
  • Verify timer is started and always stopped (finally block) and that original error propagation is preserved.
  • Confirm mapping change doesn't alter returned values or introduce performance regressions.

Possibly related PRs

Poem

🐇 I timed my hops on bridge and trail,

Subscriptions counted without fail,
Timers started, timers still,
Results mapped with careful skill,
A rabbit cheers — metrics prevail.

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "chore(apps): add new metric to observe experimental API bridge" directly and accurately describes the main changes. The PR adds a new metric named appBridgeMethods in the metrics registry and instruments the experimental API bridge in experimental.ts to use this metric for observability. The title is specific, concise (62 characters), and clearly conveys the primary purpose of the changeset without ambiguity or vague language.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/experimental-bride-metrics

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 and usage tips.

@d-gubert d-gubert force-pushed the chore/experimental-bride-metrics branch from 4e12aa0 to e35bca9 Compare October 24, 2025 19:51
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.56%. Comparing base (038948e) to head (5c84ec1).
⚠️ Report is 1 commits behind head on release-7.12.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-7.12.0   #37302      +/-   ##
==================================================
- Coverage           67.57%   67.56%   -0.01%     
==================================================
  Files                3338     3338              
  Lines              113708   113708              
  Branches            20647    20654       +7     
==================================================
- Hits                76838    76830       -8     
- Misses              34188    34197       +9     
+ Partials             2682     2681       -1     
Flag Coverage Δ
e2e 57.39% <ø> (+0.02%) ⬆️
unit 71.51% <ø> (-0.02%) ⬇️

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.

@d-gubert d-gubert marked this pull request as ready for review October 24, 2025 20:40
@d-gubert d-gubert requested a review from a team as a code owner October 24, 2025 20:40
@d-gubert d-gubert added this to the 7.12.0 milestone Oct 24, 2025
@d-gubert d-gubert force-pushed the chore/experimental-bride-metrics branch from e35bca9 to 8aaddd2 Compare October 24, 2025 20:43
@d-gubert d-gubert requested review from a team as code owners October 24, 2025 20:43
@d-gubert d-gubert changed the base branch from develop to release-7.12.0 October 24, 2025 20:44
Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
apps/meteor/app/metrics/server/lib/metrics.ts (1)

202-207: LGTM! Metric definition follows established patterns.

The new appBridgeMethods Summary metric is well-defined and consistent with existing metrics in the file. The label names (bridge, method, app_id) provide good granularity for observability.

Note on cardinality: The app_id label could potentially create high cardinality if many apps are installed, as Prometheus creates a separate time series for each unique label combination. Monitor the number of installed apps and the resulting metric cardinality in production. If cardinality becomes an issue, consider aggregating by bridge and method only, with app_id as an optional dimension.

apps/meteor/app/apps/server/bridges/experimental.ts (1)

13-29: Excellent metrics instrumentation with proper error handling.

The timer wraps the entire method execution and the finally block ensures stopTimer() is called even when errors occur, guaranteeing accurate metrics collection. The labels correctly match the metric definition.

Minor simplification: The intermediate result variable (line 24) is unnecessary. Consider returning directly:

-		const subscriptions = await Subscriptions.findByUserId(userId, { projection: { rid: 1 } }).toArray();
-
-		const result = subscriptions.map((subscription) => subscription.rid);
-
-		return result;
+		const subscriptions = await Subscriptions.findByUserId(userId, { projection: { rid: 1 } }).toArray();
+		return subscriptions.map((subscription) => subscription.rid);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f94a415 and e35bca9.

📒 Files selected for processing (2)
  • apps/meteor/app/apps/server/bridges/experimental.ts (1 hunks)
  • apps/meteor/app/metrics/server/lib/metrics.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
PR: RocketChat/Rocket.Chat#37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings (mapping subscription documents to room IDs), never undefined, even when user has no room subscriptions.

Applied to files:

  • apps/meteor/app/apps/server/bridges/experimental.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
PR: RocketChat/Rocket.Chat#37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings by mapping subscription documents to room IDs, never undefined, even when user has no room subscriptions.

Applied to files:

  • apps/meteor/app/apps/server/bridges/experimental.ts
🧬 Code graph analysis (1)
apps/meteor/app/apps/server/bridges/experimental.ts (1)
apps/meteor/app/metrics/server/lib/metrics.ts (1)
  • metrics (5-249)
🔇 Additional comments (1)
apps/meteor/app/apps/server/bridges/experimental.ts (1)

5-5: LGTM! Metrics module imported correctly.

@d-gubert d-gubert removed request for a team October 24, 2025 20:45
@d-gubert d-gubert added the stat: QA assured Means it has been tested and approved by a company insider label Oct 27, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Oct 27, 2025
@d-gubert d-gubert changed the title chore: add new metric to observe experimental API bridge chore(apps): add new metric to observe experimental API bridge Oct 27, 2025
@d-gubert d-gubert force-pushed the chore/experimental-bride-metrics branch from b1972b2 to 5c84ec1 Compare October 27, 2025 22:17
Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
apps/meteor/app/metrics/server/lib/metrics.ts (1)

202-207: LGTM! New metric follows established patterns.

The implementation is correct and consistent with other Summary metrics in the file. The metric name, help text, and label naming conventions align with existing patterns.

One consideration: the app_id label may lead to high cardinality if many apps are installed, which can impact Prometheus performance and storage. This appears to be an intentional design choice for detailed observability of the experimental bridge, similar to how other metrics use user_id or connection_id labels for granular tracking.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b1972b2 and 5c84ec1.

📒 Files selected for processing (2)
  • apps/meteor/app/apps/server/bridges/experimental.ts (1 hunks)
  • apps/meteor/app/metrics/server/lib/metrics.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/app/apps/server/bridges/experimental.ts
⏰ 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). (7)
  • GitHub Check: 🔨 Test Unit / Unit Tests
  • GitHub Check: 🔨 Test Storybook / Test Storybook
  • GitHub Check: 🔎 Code Check / Code Lint
  • GitHub Check: 🔎 Code Check / TypeScript
  • GitHub Check: 📦 Meteor Build - coverage
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build

@sampaiodiego sampaiodiego merged commit 6d1dad3 into release-7.12.0 Oct 28, 2025
69 of 71 checks passed
@sampaiodiego sampaiodiego deleted the chore/experimental-bride-metrics branch October 28, 2025 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants