Skip to content

[client] Improve dns match trace log #3928

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

Merged
merged 1 commit into from
Jun 5, 2025
Merged

[client] Improve dns match trace log #3928

merged 1 commit into from
Jun 5, 2025

Conversation

lixmal
Copy link
Contributor

@lixmal lixmal commented Jun 5, 2025

Describe your changes

This combines several log lines into one. On a busy machine those could become detached from each other and it was impossible to read.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

@Copilot Copilot AI review requested due to automatic review settings June 5, 2025 09:46
Copy link

sonarqubecloud bot commented Jun 5, 2025

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the DNS handler chain’s trace logging by consolidating per-handler logs into a single formatted block and extracts the matching logic into a new helper.

  • Consolidates individual Tracef calls into a multi-line string logged once
  • Extracts domain-match logic into isHandlerMatch
  • Enhances trace messages with domain context for continue/no-match cases
Comments suppressed due to low confidence (3)

client/internal/dns/handler_chain.go:158

  • [nitpick] The variable name b is generic; consider renaming it to sb or builder for clarity.
var b strings.Builder

client/internal/dns/handler_chain.go:199

  • Consider adding a doc comment above isHandlerMatch to explain its behavior and edge cases (e.g., wildcard and subdomain matching).
func (c *HandlerChain) isHandlerMatch(qname string, entry HandlerEntry) bool {

client/internal/dns/handler_chain.go:199

  • New helper isHandlerMatch encapsulates important logic; consider adding unit tests covering exact, wildcard, and subdomain match scenarios.
func (c *HandlerChain) isHandlerMatch(qname string, entry HandlerEntry) bool {

Comment on lines +159 to +162
b.WriteString(fmt.Sprintf("DNS request domain=%s, handlers (%d):\n", qname, len(handlers)))
for _, h := range handlers {
log.Tracef(" - pattern: domain=%s original: domain=%s wildcard=%v match_subdomain=%v priority=%d",
h.Pattern, h.OrigPattern, h.IsWildcard, h.MatchSubdomains, h.Priority)
b.WriteString(fmt.Sprintf(" - pattern: domain=%s original: domain=%s wildcard=%v match_subdomain=%v priority=%d\n",
h.Pattern, h.OrigPattern, h.IsWildcard, h.MatchSubdomains, h.Priority))
Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

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

Using fmt.Sprintf inside a tight loop can be less efficient; consider using builder.WriteString and string concatenation or builder.WriteByte to avoid repeated formatting calls.

Copilot uses AI. Check for mistakes.

@lixmal lixmal merged commit df82a45 into main Jun 5, 2025
35 of 36 checks passed
@lixmal lixmal deleted the improve-dns-log branch June 5, 2025 10:40
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