-
Notifications
You must be signed in to change notification settings - Fork 13k
chore(apps): add new metric to observe experimental API bridge #37302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(apps): add new metric to observe experimental API bridge #37302
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
WalkthroughInstruments 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 Changes
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
4e12aa0 to
e35bca9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
e35bca9 to
8aaddd2
Compare
There was a problem hiding this 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
appBridgeMethodsSummary 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_idlabel 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
finallyblock ensuresstopTimer()is called even when errors occur, guaranteeing accurate metrics collection. The labels correctly match the metric definition.Minor simplification: The intermediate
resultvariable (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.
📒 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.
b1972b2 to
5c84ec1
Compare
There was a problem hiding this 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_idlabel 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 useuser_idorconnection_idlabels 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.
📒 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
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