-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat(metrics): instrument success and failure rates of chunk broadcasting #235
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #235 +/- ##
===========================================
+ Coverage 68.46% 68.50% +0.04%
===========================================
Files 33 33
Lines 8139 8151 +12
Branches 435 435
===========================================
+ Hits 5572 5584 +12
Misses 2565 2565
Partials 2 2 ☔ View full report in Codecov by Sentry. |
📝 WalkthroughWalkthroughThe pull request introduces enhancements to the Changes
Possibly related PRs
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
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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: 1
🧹 Outside diff range and nitpick comments (4)
src/routes/arweave.ts (1)
58-58
: Consider standardizing metric label valuesThe current implementation uses 'success'/'fail' as status labels. Consider using more standard values like 'success'/'failure' or 'succeeded'/'failed' for consistency with common observability practices.
- metrics.arweaveChunkBroadcastCounter.inc({ status: 'success' }); + metrics.arweaveChunkBroadcastCounter.inc({ status: 'succeeded' }); - metrics.arweaveChunkBroadcastCounter.inc({ status: 'fail' }); + metrics.arweaveChunkBroadcastCounter.inc({ status: 'failed' });Also applies to: 61-61
src/metrics.ts (2)
122-126
: LGTM! Consider enhancing the help text.The counter implementation looks good and follows the established patterns. Consider making the help text more specific about what it counts:
- help: 'Counts individual POST request to endpoint', + help: 'Count of chunk POST requests by endpoint and status',
128-132
: Please clarify the help text regarding minimum threshold.The help text mentions "min threshold count" but doesn't specify what this threshold represents. This could make it harder for other developers to understand the metric's purpose.
Consider updating the help text to explicitly state:
- What the minimum threshold represents
- How it affects the counting logic
- help: 'Counts successful broadcast accounting for min threshold count etc', + help: 'Count of chunk broadcasts that meet the minimum peer threshold requirement',src/arweave/composite-client.ts (1)
773-776
: Consider adding error type to failure metrics.While the current implementation tracks failures correctly, adding the error type as a label would improve observability and help diagnose issues more effectively.
Consider updating the metrics to include the error type:
metrics.arweaveChunkPostCounter.inc({ endpoint: url, status: 'fail', + error_type: canceled ? 'canceled' : timedOut ? 'timeout' : 'request_error', });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
src/arweave/composite-client.ts
(2 hunks)src/metrics.ts
(1 hunks)src/routes/arweave.ts
(2 hunks)
🔇 Additional comments (3)
src/routes/arweave.ts (2)
22-22
: LGTM: Clean metrics import addition
The metrics import is properly placed and follows the existing code style.
58-58
: Verify metrics implementation consistency
Let's ensure the metrics implementation is consistent across the codebase.
Also applies to: 61-61
✅ Verification successful
Metrics implementation is correctly defined and used
The metric arweaveChunkBroadcastCounter
is:
- Properly defined in
src/metrics.ts
as a Counter with appropriate name and help text - Consistently used in
src/routes/arweave.ts
with correct status labels ('success'/'fail') - No duplicate or conflicting metric names found in the codebase
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check metrics implementation consistency
# Check metric counter definition
echo "Checking metric counter definition:"
rg -A 2 "arweaveChunkBroadcastCounter.*=.*new Counter"
# Check all usages of this counter
echo -e "\nChecking all counter usages:"
rg "arweaveChunkBroadcastCounter\.inc"
# Check for any similar metric names to avoid confusion
echo -e "\nChecking for similar metric names:"
rg "broadcast.*Counter|chunk.*Counter"
Length of output: 560
Script:
#!/bin/bash
# Let's check the metrics definition in a broader way and also look for the metrics setup
# Check for metrics definition file and its content
echo "Checking metrics setup files:"
fd "metrics" --type f --exec cat {}
# Look for Counter imports and definitions
echo -e "\nChecking Counter imports and definitions:"
rg "Counter.*from.*prom"
rg "new Counter\("
# Check the specific metric initialization
echo -e "\nChecking arweaveChunkBroadcast metric setup:"
rg -B 2 -A 2 "arweaveChunkBroadcastCounter"
Length of output: 13913
src/arweave/composite-client.ts (1)
746-749
: LGTM! Success metrics instrumentation looks good.
The metrics counter for successful chunk broadcasts is correctly placed and includes relevant labels.
metrics.arweaveChunkBroadcastCounter.inc({ status: 'success' }); | ||
res.status(200).send(result); | ||
} else { | ||
metrics.arweaveChunkBroadcastCounter.inc({ status: 'fail' }); | ||
res.status(500).send(result); |
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.
Add missing failure metric in catch block
While the success/fail metrics are properly tracked for partial successes, the catch block doesn't increment the failure counter. This could lead to under-reporting of failures.
Add the metric in the catch block:
} catch (error: any) {
+ metrics.arweaveChunkBroadcastCounter.inc({ status: 'fail' });
log.error('Failed to broadcast chunk', {
message: error?.message,
stack: error?.stack,
});
res.status(500).send('Failed to broadcast chunk');
}
Committable suggestion skipped: line range outside the PR's diff.
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.
maybe it's correct, let me check
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.
@hlolli, sure, please let me know if I can assist further.
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.
no this isn't applicable comment, because of validateStatus attribute of the axios call, all successes are not thrown and vice versa, all failures throw, so this is correct my code
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.
@hlolli, thank you for the clarification. That makes sense. I'll note this for future reviews.
✏️ Learnings added
Learnt from: hlolli
PR: ar-io/ar-io-node#235
File: src/routes/arweave.ts:58-62
Timestamp: 2024-11-15T16:11:12.130Z
Learning: In `src/routes/arweave.ts`, when using Axios with the `validateStatus` attribute set, all failures throw errors, and successes do not. Therefore, incrementing the failure metric in the catch block is unnecessary because failures are already being handled correctly.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
No description provided.