Skip to content

Work to improve the minimizer - #262

Draft
byKryptogram wants to merge 6 commits into
mainfrom
mattias/next
Draft

Work to improve the minimizer#262
byKryptogram wants to merge 6 commits into
mainfrom
mattias/next

Conversation

@byKryptogram

@byKryptogram byKryptogram commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

NOT FOR MERGING!

The goal is to improve the maintainability and performance of the minimiser one step at a time.

Upgrading to newer version of go to enable some new go apis.

Some parts may have impact on the statistics, see commit messages

Also one commit adds comments of potential bugs from before...

Builds on #243

Summary by CodeRabbit

  • Improvements
    • Updated the application’s build environment to Go 1.26.
    • Improved DNS query parsing and handling across supported workflows.
    • Enhanced normalization and matching of domain names, including suffix-based lookups.
    • Improved reliability of background processing, reloads, data collection, and message delivery.
    • Strengthened handling of DNS metadata, network values, and malformed or out-of-range data.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce2c2f69-baf7-4307-8bbd-a94b37f081b8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is too generic and does not clearly describe the main changes, such as DNS library migration, Go version bump, and waitgroup refactors. Use a concise title that names the primary change, e.g. "Refactor minimizer and migrate to codeberg.org/miekg/dns".
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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.

@byKryptogram
byKryptogram force-pushed the mattias/next branch 2 times, most recently from d2b6250 to eec93a4 Compare July 13, 2026 12:19

@zluudg zluudg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So far I've identified three seemingly unrelated changes in this PR: migration of miekgs lib to a new version, change of golang version and formatting error strings. Maybe some things can be made into their own PRs to make reviewing easier. Like changing miekgs lib and the language version.

"time"

"github.com/miekg/dns"
"codeberg.org/miekg/dns"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this switch? I'm not sure v2 of Miekg's lib is considered stable yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reason see elsewhere. In the README of the new library it states

  • "Complete and usable DNS library."
  • "We try to keep the "main" branch as sane as possible and at the bleeding edge of standards, avoiding breaking changes wherever reasonable. But because this version is young, we allow ourselves some more headroom for making backwards incompatible changes."
  • "This new version will not soon see a v1.0.0 release because I want to be able to still make changes. In a year or two (2028?) when things have stabilized it will be blessed with a v1.0.0."

While the old version's README states "The version here will only see specific fixes and nothing else. At some point this repo will be archived."

Comment thread pkg/runner/wkd.go

"github.com/miekg/dns"
"codeberg.org/miekg/dns"
dnsv1 "github.com/miekg/dns"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using two versions of the same lib? Do we really want to go there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a temporary measure, some of the helper functions have changed slightly and I've not verified that they don't impose a problem for us. Therefore I've left then on the v1 version for the moment. I'm trying to do an incremental switch.

Comment thread go.mod
go 1.26

require (
codeberg.org/miekg/dns v0.6.83

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not think we are ready for this migration of a core component. A strong motivation is needed.

@byKryptogram byKryptogram Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have an issue of the EDM being slow, or in other words; using a lot of resources. Switching to the new version of miekg's dns library does help with that. Moreover the new version lets us do partial parsing of the dns message if we choose to. Today we don't use the Answers/Authorities/Additionals sections in the analysis.

Some benchmark of this example msg, the three first are comparable parsing the message fully. If we skip everything after the Questions section we can improve it even further(the last two lines). The third library is golang.org/x/net/dns/dnsmessage

BenchmarkMiekgV1-32                      	  524742	      2108 ns/op	     672 B/op	      22 allocs/op
BenchmarkMiekgV2-32                      	  745074	      1604 ns/op	     520 B/op	      16 allocs/op
BenchmarkGoDnsMessage-32                 	  601540	      1964 ns/op	    2160 B/op	       8 allocs/op

BenchmarkMiekgV2OnlyQuestions-32         	 2418212	       509.7 ns/op	     184 B/op	       6 allocs/op
BenchmarkGoDnsMessageOnlyQuestions-32    	 2112134	       560.2 ns/op	     864 B/op	       2 allocs/op

@byKryptogram

Copy link
Copy Markdown
Contributor Author

So far I've identified three seemingly unrelated changes in this PR: migration of miekgs lib to a new version, change of golang version and formatting error strings. Maybe some things can be made into their own PRs to make reviewing easier. Like changing miekgs lib and the language version.

Sorry for the confusion! I'm using this draft PR to help myself keep track of things and trigger the GitHub actions. Not sure if there are better ways to do it.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/runner/wkd.go (1)

174-186: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use Question.Qtype here
msg.Question[0] is a dns.Question struct, so msg.Question[0].(type) cannot match *dns.A/*dns.AAAA/*dns.MX/*dns.NS. MsgOptionUnpackQuestion only parses the question section; it does not produce typed RR values there.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/runner/wkd.go` around lines 174 - 186, The question-type counting logic
should use msg.Question[0].Qtype instead of a type switch on msg.Question[0].
Update the switch in the ClassINET branch to match the corresponding dns.TypeA,
dns.TypeAAAA, dns.TypeMX, and dns.TypeNS constants, while retaining
OtherTypeCount for all unmatched types.
🧹 Nitpick comments (2)
pkg/runner/session.go (2)

195-196: 🎯 Functional Correctness | 🔵 Trivial

// BUG? comment documents a potential pre-existing bug.

The comment notes that msg.Question[0].Name is not normalized at this point in newSession. This aligns with the PR objective of documenting potential bugs. If the normalization is expected to happen elsewhere (per the "Normalizing query names only once" commit), consider clarifying in the comment where normalization occurs and whether this gap has downstream impact on label splitting. Would you like help investigating the normalization flow?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/runner/session.go` around lines 195 - 196, Clarify the BUG comment beside
newSession’s edm.setLabels call by documenting where msg.Question[0].Name is
normalized, or explicitly stating that no normalization occurs before
dnsv1.SplitDomainName and noting the downstream label-splitting impact. Keep the
comment focused on the normalization flow without changing behavior.

13-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer dns.SplitDomainName here Use the codeberg.org/miekg/dns helper instead of dnsv1.SplitDomainName; it avoids keeping the extra github.com/miekg/dns import around during the migration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/runner/session.go` around lines 13 - 15, Update the domain-name parsing
call in the relevant session logic to use SplitDomainName from the already
imported codeberg.org/miekg/dns package instead of dnsv1.SplitDomainName, then
remove the now-unneeded github.com/miekg/dns alias import while preserving
existing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/runner/session_test.go`:
- Line 451: Update the test message setup to instantiate a dns.Msg with
new(dns.Msg), then initialize its question using SetQuestion for “example.com.”
and dns.TypeA. Replace the invalid dns.NewMsg call while preserving the existing
query values and subsequent test behavior.
- Line 451: Update the test setup around the dns message construction to replace
the nonexistent dns.NewMsg call with a dns.Msg instance initialized via
SetQuestion using the same domain and record type.

In `@pkg/runner/wkd_test.go`:
- Line 302: Keep the rcode test-case field used by the relevant test as int, or
explicitly convert it to int when assigning to dns.MsgHdr.Rcode; update the
assignment involving tc.rcode while preserving the existing dns.Rcode*
constants.

---

Outside diff comments:
In `@pkg/runner/wkd.go`:
- Around line 174-186: The question-type counting logic should use
msg.Question[0].Qtype instead of a type switch on msg.Question[0]. Update the
switch in the ClassINET branch to match the corresponding dns.TypeA,
dns.TypeAAAA, dns.TypeMX, and dns.TypeNS constants, while retaining
OtherTypeCount for all unmatched types.

---

Nitpick comments:
In `@pkg/runner/session.go`:
- Around line 195-196: Clarify the BUG comment beside newSession’s edm.setLabels
call by documenting where msg.Question[0].Name is normalized, or explicitly
stating that no normalization occurs before dnsv1.SplitDomainName and noting the
downstream label-splitting impact. Keep the comment focused on the normalization
flow without changing behavior.
- Around line 13-15: Update the domain-name parsing call in the relevant session
logic to use SplitDomainName from the already imported codeberg.org/miekg/dns
package instead of dnsv1.SplitDomainName, then remove the now-unneeded
github.com/miekg/dns alias import while preserving existing behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 222a06af-1527-4cf3-b7bf-a6d6c3ac8330

📥 Commits

Reviewing files that changed from the base of the PR and between a94780f and eec93a4.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (30)
  • .github/workflows/container.yml
  • go.mod
  • pkg/protocols/protocols.go
  • pkg/protocols/protocols_test.go
  • pkg/runner/atomic_reload_test.go
  • pkg/runner/config_reload_test.go
  • pkg/runner/data_collector.go
  • pkg/runner/data_collector_test.go
  • pkg/runner/disk_cleaner.go
  • pkg/runner/disk_cleaner_test.go
  • pkg/runner/dnstap_input.go
  • pkg/runner/histogram.go
  • pkg/runner/histogram_test.go
  • pkg/runner/ignore.go
  • pkg/runner/ignore_bench_test.go
  • pkg/runner/ignore_test.go
  • pkg/runner/manual_parquet_rotation_test.go
  • pkg/runner/minimiser.go
  • pkg/runner/minimiser_test.go
  • pkg/runner/mqtt.go
  • pkg/runner/mqtt_test.go
  • pkg/runner/qname_seen.go
  • pkg/runner/qname_seen_bench_test.go
  • pkg/runner/qname_seen_test.go
  • pkg/runner/service.go
  • pkg/runner/session.go
  • pkg/runner/session_test.go
  • pkg/runner/test_helpers_test.go
  • pkg/runner/wkd.go
  • pkg/runner/wkd_test.go

Comment thread pkg/runner/session_test.go
Comment thread pkg/runner/wkd_test.go
@byKryptogram
byKryptogram force-pushed the mattias/next branch 2 times, most recently from d3871b5 to 16c0b3e Compare July 13, 2026 16:37
improve performance by only calling strings.ToLower once per qname

Expected impact: none
…s package

Expected impact: since they are different versions, they may come with
                 different idiosyncrasies that may impact statistics
only unpack until and including the question section of the
dns message, ie. not the answers

Expected impact: changing statistics, since this will allow through DNS
                 messages which are not fully parsable compared to
                 before when these were rejected
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