Skip to content

adding query time#968

Merged
Mzack9999 merged 1 commit intodevfrom
feature/query-time-870
Mar 21, 2026
Merged

adding query time#968
Mzack9999 merged 1 commit intodevfrom
feature/query-time-870

Conversation

@Mzack9999
Copy link
Copy Markdown
Member

@Mzack9999 Mzack9999 commented Mar 21, 2026

Closes #870

Summary by CodeRabbit

  • New Features
    • DNS queries now include timing information. Query results now display the duration of each DNS query measured in milliseconds, providing insight into query performance.

@neo-by-projectdiscovery-dev
Copy link
Copy Markdown

neo-by-projectdiscovery-dev bot commented Mar 21, 2026

Neo - PR Security Review

No security issues found

Highlights

  • Adds query timing measurement using Go's standard time package
  • Records DNS query duration in milliseconds and includes it in JSON/CSV output
  • No user input or external data involved in time calculation

Comment @pdneo help for available commands. · Open in Neo

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 21, 2026

Walkthrough

Added query time tracking to DNS operations. The runner now measures elapsed duration for each DNS query and stores the result in the response data structure with JSON and CSV serialization support.

Changes

Cohort / File(s) Summary
Query Timing Implementation
internal/runner/runner.go
Added time.Now() measurement before QueryMultiple() call and populated dnsData.QueryTime with elapsed duration rounded to milliseconds.
Response Data Structure
libs/dnsx/dnsx.go
Added exported QueryTime string field to ResponseData struct with query-time JSON and CSV tags; reformatted existing struct fields for alignment.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

A rabbit hops through DNS requests fast,
Now timing each query to track the past—
Milliseconds flowing like carrots in line,
Performance revealed, domain by divine! 🐰⏱️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'adding query time' directly and concisely summarizes the main change in the pull request—the addition of query time measurement to DNS query results.
Linked Issues check ✅ Passed The PR successfully implements the feature request from issue #870 by adding query time tracking to DNS queries and including it in response data alongside timestamps.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing query time tracking as specified in issue #870; no unrelated or out-of-scope modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/query-time-870

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a 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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/runner/runner.go`:
- Around line 628-630: The DNS query timing (dnsData.QueryTime) is being
assigned after calling r.dnsx.QueryMultiple(domain) but wildcard-mode storage
only serializes retryabledns.DNSData, so the QueryTime string is never
persisted; update the representation that gets stored/loaded (the
retryabledns.DNSData type or the code paths that serialize it) to include
QueryTime and ensure you set that field immediately after QueryMultiple returns
(locations around the dnsData assignment in runner.go and the other noted spots:
~533-547, ~628-630, ~737-742, ~922-944). Concretely, modify the
retryabledns.DNSData struct to have a QueryTime field (string or duration) or
wrap the stored payload so QueryTime is included, and set that field right after
dnsx.QueryMultiple(domain) before any save/serialize operations so wildcard runs
emit the timing in JSON.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8f98c090-f672-4620-8da7-5714d5430c90

📥 Commits

Reviewing files that changed from the base of the PR and between be2e639 and 06a5919.

📒 Files selected for processing (2)
  • internal/runner/runner.go
  • libs/dnsx/dnsx.go

Comment on lines +628 to +630
queryStart := time.Now()
dnsData.DNSData, _ = r.dnsx.QueryMultiple(domain)
dnsData.QueryTime = time.Since(queryStart).Round(time.Millisecond).String()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Query time is dropped in wildcard-filtering output path.

dnsData.QueryTime is set at Line 630, but wildcard mode stores/loads only retryabledns.DNSData, so JSON emitted later cannot include the new field. This makes query-time output incomplete for wildcard runs.

💡 Suggested patch direction
+type storedDNSData struct {
+	DNSData   *retryabledns.DNSData `json:"dns_data"`
+	QueryTime string                `json:"query-time,omitempty"`
+}

- if err := r.storeDNSData(dnsData.DNSData); err != nil {
+ if err := r.storeDNSData(&dnsData); err != nil {
    gologger.Debug().Msgf("Failed to store DNS data for %s: %v\n", domain, err)
  }

-func (r *Runner) storeDNSData(dnsdata *retryabledns.DNSData) error {
-	dnsdata.RawResp = nil
-	data, err := dnsdata.JSON()
+func (r *Runner) storeDNSData(resp *dnsx.ResponseData) error {
+	resp.RawResp = nil
+	data, err := json.Marshal(storedDNSData{
+		DNSData:   resp.DNSData,
+		QueryTime: resp.QueryTime,
+	})
 	if err != nil {
 		return err
 	}
-	return r.hm.Set(dnsdata.Host, []byte(data))
+	return r.hm.Set(resp.Host, data)
 }

-func (r *Runner) loadStoredDNSData(host string) (*retryabledns.DNSData, error) {
+func (r *Runner) loadStoredDNSData(host string) (*storedDNSData, error) {
 	data, ok := r.hm.Get(host)
 	if !ok {
 		return nil, errors.New("dns data not found")
 	}
-
-	var dnsdata retryabledns.DNSData
-	if err := json.Unmarshal(data, &dnsdata); err != nil {
+	var stored storedDNSData
+	if err := json.Unmarshal(data, &stored); err != nil {
 		return nil, err
 	}
-
-	return &dnsdata, nil
+	return &stored, nil
 }

Also applies to: 737-742, 533-547, 922-944

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/runner/runner.go` around lines 628 - 630, The DNS query timing
(dnsData.QueryTime) is being assigned after calling r.dnsx.QueryMultiple(domain)
but wildcard-mode storage only serializes retryabledns.DNSData, so the QueryTime
string is never persisted; update the representation that gets stored/loaded
(the retryabledns.DNSData type or the code paths that serialize it) to include
QueryTime and ensure you set that field immediately after QueryMultiple returns
(locations around the dnsData assignment in runner.go and the other noted spots:
~533-547, ~628-630, ~737-742, ~922-944). Concretely, modify the
retryabledns.DNSData struct to have a QueryTime field (string or duration) or
wrap the stored payload so QueryTime is included, and set that field right after
dnsx.QueryMultiple(domain) before any save/serialize operations so wildcard runs
emit the timing in JSON.

@Mzack9999 Mzack9999 merged commit d3b8586 into dev Mar 21, 2026
13 checks passed
@Mzack9999 Mzack9999 deleted the feature/query-time-870 branch March 21, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Add query time to results

1 participant