Skip to content

[management] removed legacy network map code#5565

Merged
crn4 merged 8 commits intomainfrom
nmap/cleanup
Apr 27, 2026
Merged

[management] removed legacy network map code#5565
crn4 merged 8 commits intomainfrom
nmap/cleanup

Conversation

@crn4
Copy link
Copy Markdown
Contributor

@crn4 crn4 commented Mar 10, 2026

Describe your changes

removal of an old unused code of legacy network map calculation

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)

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

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

removal of an unused code

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Refactor

    • Network map behavior unified to a single component-based approach; legacy/experimental/compacted modes and related branching removed, simplifying peer/network map generation and update flows.
  • Tests

    • Removed legacy golden tests and benchmarks for the old map builder.
    • Added a comprehensive component-focused test suite covering connectivity, routing, firewall rules, posture checks, DNS, SSH, and related scenarios.

Copilot AI review requested due to automatic review settings March 10, 2026 11:39
Copy link
Copy Markdown
Contributor

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 removes legacy network map generation paths and related comparison tests, standardizing network map calculation on the “components” approach while keeping the experimental cached builder path intact.

Changes:

  • Replaced remaining call sites of the legacy Account.GetPeerNetworkMap with Account.GetPeerNetworkMapFromComponents.
  • Removed legacy network map calculation methods and associated tests/benchmarks that compared legacy vs components.
  • Dropped the unused compacted-network-map env flag path and constant.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
management/server/types/networkmap_golden_test.go Switches golden tests/benchmarks from legacy network map generation to components-based generation.
management/server/types/networkmap_components.go Removes unused env constant related to compacted network maps.
management/server/types/networkmap_comparison_test.go Deletes legacy-vs-components comparison tests/benchmarks tied to removed legacy code.
management/server/types/account_test.go Removes tests that depended on legacy network map/resource-route helper APIs that were deleted.
management/server/types/account.go Removes legacy network map generation and related helper methods no longer referenced in-repo.
management/server/route_test.go Removes tests that depended on deleted legacy route firewall rule helper APIs.
management/server/http/handlers/peers/peers_handler.go Updates accessible-peers handler to use components-based network map generation.
management/server/account_test.go Updates network map test to use components-based network map generation; removes routes-to-sync test tied to deleted API.
management/internals/controllers/network_map/controller/controller.go Removes compacted flag branching and defaults non-experimental path to components-based network map generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 10, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR removes the legacy NetworkMapBuilder, holder/cache and experimental/compacted flags, consolidating all network-map generation to the components-based path; it deletes related types, helpers, and many legacy tests/benchmarks and adds a comprehensive components-focused test suite.

Changes

Cohort / File(s) Summary
Controller simplification
management/internals/controllers/network_map/controller/controller.go, management/internals/controllers/network_map/interface.go
Removed env flags/constants and holder/compacted/experimental fields and helpers; controller now always uses GetPeerNetworkMapFromComponents and simplified update/send flows.
NetworkMapBuilder & cache removed
management/server/types/networkmapbuilder.go, management/server/types/networkmap.go, management/server/types/holder.go
Deleted entire NetworkMapBuilder subsystem, cache lifecycle, incremental update engine, and the Holder type along with all related public types and methods.
Account API pruning
management/server/types/account.go, management/server/types/account_test.go
Removed NetworkMapCache, nmapInitOnce, InitOnce() and legacy GetPeerNetworkMap / routes/firewall/resource/posture helpers; updated Account.Copy and tests accordingly.
Call-site updates
management/server/http/handlers/peers/peers_handler.go, management/server/account_test.go, management/server/peer_test.go, management/server/store/sql_store.go
Replaced calls to legacy map API with GetPeerNetworkMapFromComponents; removed experimental test wrappers/env toggles and removed account.InitOnce() calls at DB load.
Tests removed
management/server/types/networkmap_golden_test.go, management/server/types/networkmap_comparison_test.go, parts of management/server/route_test.go, various deleted test functions
Removed legacy golden/comparison tests, benchmarks, and many routing/posture-related tests and helpers.
New tests added
management/server/types/networkmap_components_test.go
Added extensive components-based test suite covering connectivity, firewall rules, network resources, posture checks, DNS, HA deduplication, SSH, and many scenarios.
Small constants/imports
management/server/types/networkmap_components.go, various files
Removed EnvNewNetworkMapCompacted, EnvNewNetworkMapBuilder, EnvNewNetworkMapAccounts and cleaned up unused imports/constants tied to removed flows.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(200,200,255,0.5)
    participant Client
    end
    rect rgba(200,255,200,0.5)
    participant Controller
    end
    rect rgba(255,200,200,0.5)
    participant RequestBuffer
    participant Account
    participant Components
    end

    Client->>Controller: request/update peers
    Controller->>RequestBuffer: GetAccountWithBackpressure(accountID)
    RequestBuffer-->>Controller: Account
    Controller->>Account: GetPeerNetworkMapFromComponents(peerID, params...)
    Account->>Components: build/derive network map from components
    Components-->>Account: NetworkMap
    Account-->>Controller: NetworkMap
    Controller-->>Client: propagate update
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Suggested reviewers

  • pascal-fischer

"I hopped through code with twitchy feet,
Nibbled flags and pruned old peat.
Components now hop in a neat line,
Legacy crumbs left far behind,
A rabbit cheers: the map's divine! 🐇"

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.13% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is vague and lacks specificity about the scope and impact of changes. It states 'removal of an old unused code of legacy network map calculation' but provides minimal context. Provide more detailed explanation of what legacy code was removed, why it is no longer needed, and ensure the checkbox selection (bug fix vs. refactor) accurately reflects the nature of this cleanup work.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'removed legacy network map code' clearly summarizes the main change: removal of deprecated network map implementation, matching the extensive deletions across multiple files.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nmap/cleanup

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
Contributor

@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

🧹 Nitpick comments (1)
management/server/types/networkmap_golden_test.go (1)

115-123: Precompute account.GetActiveGroupUsers() outside the benchmarked loop.

Rebuilding the group-user map on every inner-loop call inflates the “components builder” timing with setup work that the “new builder” branch doesn’t pay, so this benchmark stops being apples-to-apples. The same cleanup applies to the later components-builder benchmarks in this file.

♻️ Suggested cleanup
  resourcePolicies := account.GetResourcePoliciesMap()
  routers := account.GetResourceRoutersMap()
+ groupIDToUserIDs := account.GetActiveGroupUsers()

  b.ResetTimer()
  b.Run("components builder", func(b *testing.B) {
  	for range b.N {
  		for _, peerID := range peerIDs {
- 			_ = account.GetPeerNetworkMapFromComponents(ctx, peerID, dns.CustomZone{}, []*zones.Zone{}, validatedPeersMap, resourcePolicies, routers, nil, account.GetActiveGroupUsers())
+ 			_ = account.GetPeerNetworkMapFromComponents(ctx, peerID, dns.CustomZone{}, []*zones.Zone{}, validatedPeersMap, resourcePolicies, routers, nil, groupIDToUserIDs)
  		}
  	}
  })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@management/server/types/networkmap_golden_test.go` around lines 115 - 123,
Precompute the group-user map once before the benchmark loop instead of calling
account.GetActiveGroupUsers() inside the inner loop: call
account.GetActiveGroupUsers() (store result in a variable like activeGroupUsers)
prior to b.Run("components builder", ...) and then pass that variable into
account.GetPeerNetworkMapFromComponents(...) in place of the inline call; apply
the same change to the other "components builder" benchmark blocks in this file
so the benchmarked work excludes repeated setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@management/server/http/handlers/peers/peers_handler.go`:
- Line 420: The code calls account.GetPeerNetworkMapFromComponents(...) without
first injecting proxy-generated policies, causing missing peers for
proxy-reliant accounts; update the handler to call
account.InjectProxyPolicies(...) (using the same context and account) to produce
the injected resourcePolicies/resourceRouters before constructing validPeers and
calling GetPeerNetworkMapFromComponents, and then pass the resulting
account.GetResourcePoliciesMap() / account.GetResourceRoutersMap() (or the
injected maps returned by InjectProxyPolicies) into
GetPeerNetworkMapFromComponents so the network map includes proxy-generated
policies/resources.

---

Nitpick comments:
In `@management/server/types/networkmap_golden_test.go`:
- Around line 115-123: Precompute the group-user map once before the benchmark
loop instead of calling account.GetActiveGroupUsers() inside the inner loop:
call account.GetActiveGroupUsers() (store result in a variable like
activeGroupUsers) prior to b.Run("components builder", ...) and then pass that
variable into account.GetPeerNetworkMapFromComponents(...) in place of the
inline call; apply the same change to the other "components builder" benchmark
blocks in this file so the benchmarked work excludes repeated setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9ed676b-8bbe-4cef-9b23-a207f0a34f0a

📥 Commits

Reviewing files that changed from the base of the PR and between 5585adc and 30dbf21.

📒 Files selected for processing (9)
  • management/internals/controllers/network_map/controller/controller.go
  • management/server/account_test.go
  • management/server/http/handlers/peers/peers_handler.go
  • management/server/route_test.go
  • management/server/types/account.go
  • management/server/types/account_test.go
  • management/server/types/networkmap_comparison_test.go
  • management/server/types/networkmap_components.go
  • management/server/types/networkmap_golden_test.go
💤 Files with no reviewable changes (5)
  • management/server/route_test.go
  • management/server/types/networkmap_components.go
  • management/server/types/account_test.go
  • management/server/types/account.go
  • management/server/types/networkmap_comparison_test.go

Comment thread management/server/http/handlers/peers/peers_handler.go
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
management/server/types/networkmap_components_test.go (1)

302-310: Consider explicitly setting GoOS in this subtest for clarity.

The "fails OS posture check" subtest relies on GoOS being "linux" from the account creation defaults (line 686). While this works correctly, explicitly setting it here would make the test self-documenting and resilient to future changes in the test fixture.

💡 Suggested clarification
 	t.Run("fails OS posture check", func(t *testing.T) {
 		account.Peers["peer-src-1"].Meta.WtVersion = "0.35.0"
+		account.Peers["peer-src-1"].Meta.GoOS = "linux"
 		account.Peers["peer-src-1"].Meta.KernelVersion = "4.0.0"
 		nm := networkMapFromComponents(t, account, "peer-src-1", validated)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@management/server/types/networkmap_components_test.go` around lines 302 -
310, The subtest "fails OS posture check" relies on account defaults for OS;
make it explicit by setting account.Peers["peer-src-1"].Meta.GoOS = "linux"
inside that t.Run block so the test is self-documenting and robust to fixture
changes; locate the subtest where Meta.WtVersion and Meta.KernelVersion are set
(the failing OS posture check) and add the explicit GoOS assignment before
calling networkMapFromComponents.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@management/server/types/networkmap_components_test.go`:
- Around line 302-310: The subtest "fails OS posture check" relies on account
defaults for OS; make it explicit by setting
account.Peers["peer-src-1"].Meta.GoOS = "linux" inside that t.Run block so the
test is self-documenting and robust to fixture changes; locate the subtest where
Meta.WtVersion and Meta.KernelVersion are set (the failing OS posture check) and
add the explicit GoOS assignment before calling networkMapFromComponents.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f01f8865-3ff7-4f65-8c24-6b2c2f03a8f1

📥 Commits

Reviewing files that changed from the base of the PR and between 30dbf21 and 710f6a9.

📒 Files selected for processing (1)
  • management/server/types/networkmap_components_test.go

Copy link
Copy Markdown
Contributor

@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.

Caution

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

⚠️ Outside diff range comments (1)
management/internals/controllers/network_map/controller/controller.go (1)

199-202: ⚠️ Potential issue | 🟡 Minor

Use the goroutine parameter p.ID instead of outer loop variable peer.ID.

Inside the goroutine, the peer is passed as parameter p, but line 199 references peer.ID from the outer loop scope. While Go 1.22+ creates per-iteration loop variables (making this safe), using p.ID is consistent with the function signature and the intent of passing the peer as a parameter.

Proposed fix
-			proxyNetworkMap, ok := proxyNetworkMaps[peer.ID]
+			proxyNetworkMap, ok := proxyNetworkMaps[p.ID]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@management/internals/controllers/network_map/controller/controller.go` around
lines 199 - 202, The goroutine is using the outer loop variable peer.ID instead
of the goroutine parameter p.ID; update the lookup to use p.ID when accessing
proxyNetworkMaps and any related references (e.g., change
proxyNetworkMaps[peer.ID] to proxyNetworkMaps[p.ID]) so that the goroutine
consistently uses its parameter and then call
remotePeerNetworkMap.Merge(proxyNetworkMap) as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@management/internals/controllers/network_map/controller/controller.go`:
- Around line 199-202: The goroutine is using the outer loop variable peer.ID
instead of the goroutine parameter p.ID; update the lookup to use p.ID when
accessing proxyNetworkMaps and any related references (e.g., change
proxyNetworkMaps[peer.ID] to proxyNetworkMaps[p.ID]) so that the goroutine
consistently uses its parameter and then call
remotePeerNetworkMap.Merge(proxyNetworkMap) as before.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ec0dc43b-918a-4496-9658-4f9c1f0932c5

📥 Commits

Reviewing files that changed from the base of the PR and between 5e097be and 74a9842.

📒 Files selected for processing (11)
  • management/internals/controllers/network_map/controller/controller.go
  • management/internals/controllers/network_map/interface.go
  • management/server/account_test.go
  • management/server/peer_test.go
  • management/server/store/sql_store.go
  • management/server/types/account.go
  • management/server/types/holder.go
  • management/server/types/networkmap.go
  • management/server/types/networkmap_components.go
  • management/server/types/networkmap_golden_test.go
  • management/server/types/networkmapbuilder.go
💤 Files with no reviewable changes (9)
  • management/internals/controllers/network_map/interface.go
  • management/server/types/networkmap_components.go
  • management/server/types/holder.go
  • management/server/store/sql_store.go
  • management/server/peer_test.go
  • management/server/types/networkmap_golden_test.go
  • management/server/types/networkmapbuilder.go
  • management/server/types/account.go
  • management/server/types/networkmap.go

pascal-fischer
pascal-fischer previously approved these changes Apr 14, 2026
@sonarqubecloud
Copy link
Copy Markdown

@crn4 crn4 merged commit 154b816 into main Apr 27, 2026
43 checks passed
@crn4 crn4 deleted the nmap/cleanup branch April 27, 2026 14:02
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.

3 participants