Skip to content

feat: track DNS request source in metrics and logs#122

Merged
rm-hull merged 2 commits into
mainfrom
feat/dispatcher-source
May 31, 2026
Merged

feat: track DNS request source in metrics and logs#122
rm-hull merged 2 commits into
mainfrom
feat/dispatcher-source

Conversation

@rm-hull
Copy link
Copy Markdown
Owner

@rm-hull rm-hull commented May 31, 2026

Introduce DNSSource and RequestContext to differentiate between UDP, TCP, and DoT requests throughout the dispatching lifecycle.

  • Update DNSDispatcher to accept the request source.
  • Enhance dns_request_count metric with a source label.
  • Consolidate logging context to include source and metadata.

Introduce `DNSSource` and `RequestContext` to differentiate between
UDP, TCP, and DoT requests throughout the dispatching lifecycle.

- Update `DNSDispatcher` to accept the request source.
- Enhance `dns_request_count` metric with a `source` label.
- Consolidate logging context to include source and metadata.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 31, 2026

TestsPassed ✅SkippedFailed
JUnit Test Report28 ran28 passed0 skipped0 failed
TestResult
JUnit Test Report
com/rm-hull/dot-block/internal/blocklist.TestIsBlocked_ApexDomain_PublicSuffix✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_HandleDNSRequest_Allowed✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_HandleDNSRequest_Blocked✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_HandleDNSRequest_MultipleQuestions✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_HandleDNSRequest_CacheHit✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_ResolveUpstream_BadRCode✅ passed
com/rm-hull/dot-block/internal/forwarder.TestNewDNSDispatcher_NegativeCacheTtlFloor✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_QueryLogging/Logging_at_INFO_level_(should_not_contain_debug_logs)✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_QueryLogging/Logging_at_DEBUG_level✅ passed
com/rm-hull/dot-block/internal/forwarder.TestDNSDispatcher_QueryLogging✅ passed
com/rm-hull/dot-block/internal/metrics.TestNewSpaceSaverStatsCallback/eviction_case✅ passed
com/rm-hull/dot-block/internal/metrics.TestNewSpaceSaverStatsCallback/topK_smaller_than_items✅ passed
com/rm-hull/dot-block/internal/metrics.TestNewSpaceSaverStatsCallback/empty_space_saver✅ passed
com/rm-hull/dot-block/internal/metrics.TestNewSpaceSaverStatsCallback✅ passed
com/rm-hull/dot-block/internal/metrics.TestNewSpaceSaver✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverAdd/Case3_ReplacementDetails✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverAdd✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverTopN/TopN_WithReplacements✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverTopN✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverConcurrency✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverMinKeyCaching/MinKeyInitialization✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverMinKeyCaching/MinKeyAfterFirstAdd✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverMinKeyCaching/MinKeyAddingItemsWithSameCount✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverMinKeyCaching/MinKeyAfterIncrementingMinKeyItem✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverMinKeyCaching/MinKeyAfterReplacement✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverMinKeyCaching/MinKeyInvalidationAndRecomputation✅ passed
com/rm-hull/dot-block/internal/metrics.TestSpaceSaverMinKeyCaching✅ passed
com/rm-hull/dot-block/internal/mobileconfig.TestHandler✅ passed

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the DNS request handling to track and report the source of DNS requests (UDP, TCP, or DoT) in metrics and logs. It introduces a DNSSource type and a RequestContext struct to pass contextual information through the dispatcher. The review feedback suggests several improvements: removing the unused StartTime field from RequestContext, and skipping both the geolocation lookup and client count updates when the client IP address is resolved as "unknown" to avoid redundant operations and duplicate warning logs.

Comment thread internal/forwarder/dispatcher.go
Comment thread internal/forwarder/dispatcher.go
Comment thread internal/forwarder/dispatcher.go
Comment thread internal/forwarder/dispatcher.go Outdated
@coveralls
Copy link
Copy Markdown

coveralls commented May 31, 2026

Coverage Report for CI Build 26707628692

Coverage increased (+0.2%) to 39.922%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 19 uncovered changes across 2 files (61 of 80 lines covered, 76.25%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
internal/forwarder/dispatcher.go 75 59 78.67%
internal/app.go 3 0 0.0%
Total (3 files) 80 61 76.25%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
internal/forwarder/dispatcher.go 1 84.26%

Coverage Stats

Coverage Status
Relevant Lines: 1280
Covered Lines: 511
Line Coverage: 39.92%
Coverage Strength: 0.43 hits per line

💛 - Coveralls

- Refactored `RequestContext` to use `time.Time` instead of
`*time.Time`.
- Moved client tracking logic directly into `HandleDNSRequest` to reduce
  function call overhead and improve readability.
- Removed redundant `updateClientCount` helper method.
@rm-hull rm-hull merged commit d84af67 into main May 31, 2026
3 checks passed
@rm-hull rm-hull deleted the feat/dispatcher-source branch May 31, 2026 08:38
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.

2 participants