-
Notifications
You must be signed in to change notification settings - Fork 1
[Promotion] Deploy dev to production (PR #34) #35
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
Conversation
…and-resource-cleanup Add subscription to logs metric for EVM chains
WalkthroughThis update introduces the new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant WSLogLatencyMetric
participant WebSocket
participant HTTPNode
Client->>WSLogLatencyMetric: collect_metric()
WSLogLatencyMetric->>WebSocket: Connect & subscribe to USDT Transfer logs
WebSocket-->>WSLogLatencyMetric: Emit first Transfer log event
WSLogLatencyMetric->>HTTPNode: Fetch block timestamp for log's block number
HTTPNode-->>WSLogLatencyMetric: Return block timestamp
WSLogLatencyMetric->>WSLogLatencyMetric: Calculate latency (now - block timestamp)
WSLogLatencyMetric-->>Client: Update metric value
WSLogLatencyMetric->>WebSocket: Unsubscribe & close connection
Possibly related PRs
Poem
✨ 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 (
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 (10)
api/read/arbitrum.py (2)
12-14: Drop commented-out import to keep module cleanKeeping dead code around quickly turns these files into changelog graveyards. Removing the commented line makes the intent explicit and avoids accidental re-enablement during bulk edits.
-from metrics.ethereum import ( - # WSBlockLatencyMetric, - WSLogLatencyMetric, -) +from metrics.ethereum import WSLogLatencyMetric
18-21: Prune leftover entry inMETRICSlistSame reasoning—commented items add noise and can mislead readers/linters.
-METRICS = [ - # (WSBlockLatencyMetric, metric_name), - (WSLogLatencyMetric, metric_name), +METRICS = [ + (WSLogLatencyMetric, metric_name),api/read/ethereum.py (2)
10-12: Remove obsolete import commentMirror the cleanup applied to Arbitrum to stay consistent.
-from metrics.ethereum import ( - # WSBlockLatencyMetric, - WSLogLatencyMetric, -) +from metrics.ethereum import WSLogLatencyMetric
16-19: TidyMETRICS– scrap commented tuple-METRICS = [ - # (WSBlockLatencyMetric, metric_name), - (WSLogLatencyMetric, metric_name), +METRICS = [ + (WSLogLatencyMetric, metric_name),api/read/base.py (2)
11-14: One-liner import is clearer-from metrics.ethereum import ( - # WSBlockLatencyMetric, - WSLogLatencyMetric, -) +from metrics.ethereum import WSLogLatencyMetric
18-21: Trim commented metric entry-METRICS = [ - # (WSBlockLatencyMetric, metric_name), - (WSLogLatencyMetric, metric_name), +METRICS = [ + (WSLogLatencyMetric, metric_name),common/base_metric.py (2)
11-11: Import only what you need
websockets.exceptionsis imported solely to referenceInvalidStatusCode. Import that symbol directly and drop the extra module import to avoid namespace clutter.-import websockets.exceptions +from websockets.exceptions import InvalidStatusCode
114-116: Update reference after scoped importIf applying the previous suggestion, adjust the type check accordingly:
- if isinstance(error, websockets.exceptions.InvalidStatusCode): + if isinstance(error, InvalidStatusCode):metrics/ethereum.py (2)
265-270: AddClassVarannotation to mutable class attribute.The
TOKEN_CONTRACTSdictionary should be annotated withtyping.ClassVarto clarify it's a class-level attribute and prevent accidental instance-level modifications.Add the import at the top of the file:
from typing import ClassVarThen update the attribute declaration:
- TOKEN_CONTRACTS: dict[str, str] = { + TOKEN_CONTRACTS: ClassVar[dict[str, str]] = {🧰 Tools
🪛 Ruff (0.11.9)
265-270: Mutable class attributes should be annotated with
typing.ClassVar(RUF012)
307-330: Improve exception chaining for better error tracking.The timeout helper methods are well-implemented, but exception chaining should be improved for better debugging.
- except asyncio.TimeoutError: - raise TimeoutError( - f"WebSocket message send timed out after {timeout} seconds" - ) + except asyncio.TimeoutError as e: + raise TimeoutError( + f"WebSocket message send timed out after {timeout} seconds" + ) from eAnd similarly for
recv_with_timeout:- except asyncio.TimeoutError: - raise TimeoutError( - f"WebSocket message reception timed out after {timeout} seconds" - ) + except asyncio.TimeoutError as e: + raise TimeoutError( + f"WebSocket message reception timed out after {timeout} seconds" + ) from e🧰 Tools
🪛 Ruff (0.11.9)
307-307: Missing type annotation for function argument
websocket(ANN001)
312-314: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
316-316: Missing type annotation for function argument
websocket(ANN001)
323-323: Line too long (101 > 88)
(E501)
327-329: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
api/read/arbitrum.py(1 hunks)api/read/base.py(1 hunks)api/read/bnbsc.py(1 hunks)api/read/ethereum.py(1 hunks)common/base_metric.py(1 hunks)common/metric_types.py(1 hunks)metrics/ethereum.py(3 hunks)tests/test_api_read.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
api/read/bnbsc.py (1)
metrics/ethereum.py (1)
WSLogLatencyMetric(257-475)
api/read/base.py (1)
metrics/ethereum.py (1)
WSLogLatencyMetric(257-475)
api/read/arbitrum.py (1)
metrics/ethereum.py (1)
WSLogLatencyMetric(257-475)
api/read/ethereum.py (1)
metrics/ethereum.py (1)
WSLogLatencyMetric(257-475)
metrics/ethereum.py (5)
common/metric_config.py (6)
get_prometheus_labels(86-88)MetricLabels(65-111)MetricConfig(37-50)get_label(106-111)MetricLabelKey(8-16)update_label(90-96)common/metric_types.py (8)
WebSocketMetric(19-84)subscribe(37-38)unsubscribe(41-42)listen_for_data(45-46)collect_metric(58-84)collect_metric(98-109)connect(48-56)process_data(233-235)api/read/ethereum.py (1)
handler(28-29)common/base_metric.py (6)
collect_metric(49-50)update_metric_value(82-91)mark_success(93-95)mark_failure(97-102)handle_error(104-131)process_data(53-54)metrics/solana_landing_rate.py (1)
process_data(185-186)
🪛 Ruff (0.11.9)
metrics/ethereum.py
165-165: Line too long (101 > 88)
(E501)
265-270: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
277-277: Missing docstring in __init__
(D107)
283-283: Missing type annotation for **kwargs
(ANN003)
307-307: Missing type annotation for function argument websocket
(ANN001)
312-314: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
316-316: Missing type annotation for function argument websocket
(ANN001)
323-323: Line too long (101 > 88)
(E501)
327-329: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
331-331: Missing type annotation for function argument websocket
(ANN001)
357-357: Missing type annotation for function argument websocket
(ANN001)
378-378: Missing type annotation for function argument websocket
(ANN001)
378-378: Dynamically typed expressions (typing.Any) are disallowed in listen_for_data
(ANN401)
🔇 Additional comments (11)
tests/test_api_read.py (1)
31-33: Import path update looks correctThe switch to
api.read.bnbsc.handleraligns the dev-server script with the new metric implementation. No further issues spotted.api/read/bnbsc.py (1)
12-13: LGTM! Successful migration to log-based latency metrics.The switch from
WSBlockLatencyMetrictoWSLogLatencyMetricis properly implemented with correct import and metric registration.Also applies to: 19-20
common/metric_types.py (1)
178-180: Good addition of explicit timeout configuration.Adding the timeout to the
ClientSessionensures HTTP requests don't hang indefinitely and properly respect the configured timeout value.metrics/ethereum.py (8)
7-9: Imports correctly added for the new functionality.The
Optionaltype hint andaiohttplibrary are properly imported to support the newWSLogLatencyMetricimplementation.
161-167: Useful addition of WebSocket message size logging.The message size logging provides valuable insights for monitoring WebSocket communication overhead.
🧰 Tools
🪛 Ruff (0.11.9)
165-165: Line too long (101 > 88)
(E501)
277-305: Well-structured initialization with proper fallback handling.The constructor properly initializes the WebSocket metric with blockchain-specific token contracts and includes a sensible fallback to Ethereum USDT.
🧰 Tools
🪛 Ruff (0.11.9)
277-277: Missing docstring in
__init__(D107)
283-283: Missing type annotation for
**kwargs(ANN003)
331-377: Robust subscription management with proper error handling.The subscribe/unsubscribe methods correctly implement log subscription for Transfer events with appropriate error handling, especially in the unsubscribe cleanup.
🧰 Tools
🪛 Ruff (0.11.9)
331-331: Missing type annotation for function argument
websocket(ANN001)
357-357: Missing type annotation for function argument
websocket(ANN001)
378-390: Clean implementation for single event collection.The method efficiently captures the first log event using a state flag, which aligns well with the serverless execution model.
🧰 Tools
🪛 Ruff (0.11.9)
378-378: Missing type annotation for function argument
websocket(ANN001)
378-378: Dynamically typed expressions (typing.Any) are disallowed in
listen_for_data(ANN401)
391-419: Excellent resource management and error handling.The method properly manages the WebSocket lifecycle with appropriate error handling and cleanup in the finally block.
420-471: Well-implemented timestamp-based latency calculation.The method correctly calculates latency by fetching block timestamps via HTTP with comprehensive error handling. The approach of capturing current time before the HTTP request ensures accurate latency measurement.
Note: Creating a new
ClientSessionfor each call is acceptable for serverless environments but could be optimized if this metric is collected frequently.
472-475: Appropriate placeholder implementation.The method correctly documents that it's not used in the updated flow, serving only to satisfy the parent class interface.
Promoting to production
This PR promotes all changes from dev to master.
Changes included
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores