-
Notifications
You must be signed in to change notification settings - Fork 54
feat: pending sweep metrics #977
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughTwo new Prometheus Gauge metrics were introduced in the Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error Exit handler never called! ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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)
lib/Prometheus.ts (1)
312-346
: Consider optimizing the duplicate service calls and potential precision loss.Both metrics call
service.getPendingSweeps()
independently, which could impact performance if metrics collection happens frequently. Additionally, the BigInt to Number conversion in the amount metric could lose precision for very large values.Optimization approach:
+ // Cache the pending sweeps data for both metrics + let pendingSweepsCache: Map<string, any[]> | null = null; + const getPendingSweepsOnce = () => { + if (pendingSweepsCache === null) { + pendingSweepsCache = service.getPendingSweeps(); + } + return pendingSweepsCache; + }; + this.swapRegistry!.registerMetric( new Gauge({ name: `${Prometheus.metricPrefix}pending_sweep_count`, labelNames: ['symbol'], help: 'number of pending sweeps', collect: function () { - const pendingSweeps = service.getPendingSweeps(); + pendingSweepsCache = null; // Reset cache + const pendingSweeps = getPendingSweepsOnce(); for (const [symbol, swaps] of pendingSweeps.entries()) { this.set({ symbol }, swaps.length); } }, }), ); this.swapRegistry!.registerMetric( new Gauge({ name: `${Prometheus.metricPrefix}pending_sweep_amount`, labelNames: ['symbol'], help: 'amount in pending sweeps', collect: function () { - const pendingSweeps = service.getPendingSweeps(); + const pendingSweeps = getPendingSweepsOnce(); for (const [symbol, swaps] of pendingSweeps.entries()) { this.set( { symbol }, - Number( - swaps.reduce( - (acc, swap) => acc + BigInt(swap.onchainAmount), - 0n, - ), - ), + // Consider adding overflow checking for very large amounts + Math.min( + Number( + swaps.reduce( + (acc, swap) => acc + BigInt(swap.onchainAmount), + 0n, + ), + ), + Number.MAX_SAFE_INTEGER, + ), ); } }, }), );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/Prometheus.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build-rust (ubuntu-latest, 20, stable)
- GitHub Check: build (ubuntu-latest, 20, stable)
- GitHub Check: build-rust (ubuntu-latest, 20, stable)
- GitHub Check: build (ubuntu-latest, 20, stable)
🔇 Additional comments (2)
lib/Prometheus.ts (2)
317-323
: LGTM: Clean implementation for pending sweep count metric.The metric correctly counts pending sweeps per symbol and follows the established patterns in the codebase.
331-344
: LGTM: Correct logic for summing pending sweep amounts.The reduce operation properly accumulates the
onchainAmount
values using BigInt arithmetic before converting to Number for the metric value.
Summary by CodeRabbit