feat: populate dnslookup timing with actual DNS resolution time#743
feat: populate dnslookup timing with actual DNS resolution time#743
Conversation
…ockets Captures DNS lookup time via Socket.prototype.emit monkey-patch for the 'lookup' event. When the first request is sent on a socket, the DNS lookup time is calculated relative to the request start time and stored in the timing object. Closes #577 Agent-Logs-Url: https://github.com/node-modules/urllib/sessions/efde376e-b12f-42f6-9490-2ce39519fe7c Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #743 +/- ##
==========================================
+ Coverage 94.60% 94.65% +0.05%
==========================================
Files 10 10
Lines 723 730 +7
Branches 226 228 +2
==========================================
+ Hits 684 691 +7
Misses 36 36
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot 只有这种 patch 方案吗? |
….prototype.emit monkey-patch Replace the global Socket.prototype.emit monkey-patch with a subscription to Node.js's net.client.socket diagnostics channel. This channel fires when a new TCP/IPC connection is initiated, giving us access to the socket before the 'lookup' event fires, so we can attach a targeted per-socket one-time listener instead of patching the global prototype. Agent-Logs-Url: https://github.com/node-modules/urllib/sessions/d5603429-8e76-46db-bd88-7a315ea660ba Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
已替换为更好的方案。不再 patch Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot 在 readme 增加一下 timing 字段的含义,并且通过文本图方式展示一下每个字段之间的关系,让用户可以一眼就能看懂。 |
|
@codex review |
Agent-Logs-Url: https://github.com/node-modules/urllib/sessions/7bc7fa06-09b7-40ca-aec2-e897a34a4933 Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
已在 README 中添加 Timing 章节,包含文本图展示各字段在请求生命周期中的位置,以及每个字段的含义说明表格。commit |
There was a problem hiding this comment.
Pull request overview
This PR makes the Timing.dnslookup field meaningful by capturing DNS lookup completion time on new sockets and translating it into a request-relative timing value, with accompanying test assertions.
Changes:
- Add a new socket symbol (
kSocketDnsLookupTime) to store DNS lookup completion timestamps. - Subscribe to
net.client.socketand attach a per-socketlookuplistener to recordperformance.now(), then computetiming.dnslookupfor the first request on a socket. - Extend timing tests to validate
dnslookupbehavior on first request vs. reused sockets.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/symbols.ts |
Adds a symbol used to stash DNS lookup timing data on sockets. |
src/diagnosticsChannel.ts |
Captures DNS lookup completion time and computes timing.dnslookup on first request per socket. |
test/options.timing.test.ts |
Adds assertions for dnslookup being set on first request and remaining 0 on socket reuse. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…itDiagnosticsChannel, use explicit undefined check, relax dnslookup assertion Agent-Logs-Url: https://github.com/node-modules/urllib/sessions/5980bc15-0896-428f-8709-7929c8055eb5 Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
已修复。README 表格格式化问题已通过 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
kSocketDnsLookupTimesymbol insrc/symbols.tsnet.client.socketdiagnostics channel insrc/diagnosticsChannel.tsdnslookuptiming indiagnosticsChannel.tswhen first request is sent on sockettest/options.timing.test.tsto verifydnslookuptiming is populatednet.client.socketsubscription intoinitDiagnosticsChannel()under init guard!== undefinedcheck forkSocketDnsLookupTime(avoids false negative on timestamp0)dnslookup > 0to>= 0to avoid flaky test on fast localhost DNS resolution