[PR #5239] [MERGED] [management] Feature/grpc debounce msgtype #22487

Closed
opened 2026-08-05 06:06:01 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5239
Author: @pappz
Created: 2/2/2026
Status: Merged
Merged: 2/6/2026
Merged by: @pappz

Base: mainHead: feature/grpc-debounce-msgtype


📝 Commits (6)

  • 2111a34 Add gRPC update debouncing mechanism
  • debe65e Enhance unit test to verify peer count synchronization with debouncing and timeout handling
  • bc39a05 Debounce based on type
  • 6346c3c Refactor test to validate timer restart after pending update dispatch
  • f8e12de Simplify timer reset for Go 1.23+ automatic channel draining
  • 4548e0b Merge branch 'main' into feature/grpc-debounce-msgtype

📊 Changes

8 files changed (+818 additions, -22 deletions)

View changed files

📝 management/internals/controllers/network_map/controller/controller.go (+9 -2)
📝 management/internals/controllers/network_map/update_channel/updatechannel_test.go (+14 -8)
📝 management/internals/controllers/network_map/update_message.go (+14 -1)
📝 management/internals/shared/grpc/server.go (+30 -3)
📝 management/internals/shared/grpc/token_mgr.go (+8 -2)
management/internals/shared/grpc/update_debouncer.go (+103 -0)
management/internals/shared/grpc/update_debouncer_test.go (+587 -0)
📝 management/server/management_test.go (+53 -6)

📄 Description

Implements backpressure handling for peer network map updates to efficiently handle rapid changes. The first update is sent immediately; subsequent rapid updates are coalesced, ensuring that only the latest update is sent after a 1-second quiet period.

Intermediate changes do not need to be applied, so the focus is on processing only the final update in the queue.
This also fixes lost network updates on the producer side. The network map producer should not depend on network-related layers. Todo: set the channal size to 1 and set it to blocker.

Describe your changes

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)

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

  • New Features

    • Per-peer update debouncer to coalesce rapid updates and reduce update storms
    • Explicit message-type classification to distinguish network-map vs control/config updates
  • Bug Fixes

    • Ensure update messages consistently include message-type metadata for correct handling
  • Tests

    • Comprehensive debouncer test suite (coalescing, ordering, timers, mixed types)
    • Integration tests updated to track per-peer progress with time‑bounded finalization

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5239 **Author:** [@pappz](https://github.com/pappz) **Created:** 2/2/2026 **Status:** ✅ Merged **Merged:** 2/6/2026 **Merged by:** [@pappz](https://github.com/pappz) **Base:** `main` ← **Head:** `feature/grpc-debounce-msgtype` --- ### 📝 Commits (6) - [`2111a34`](https://github.com/netbirdio/netbird/commit/2111a34470b35188096b05c5663075f950f0bbd7) Add gRPC update debouncing mechanism - [`debe65e`](https://github.com/netbirdio/netbird/commit/debe65e01ef193dfb2400ae61440d64ffd7aa8b1) Enhance unit test to verify peer count synchronization with debouncing and timeout handling - [`bc39a05`](https://github.com/netbirdio/netbird/commit/bc39a053725086c3c5bd4cd55d0dbfb2b5965215) Debounce based on type - [`6346c3c`](https://github.com/netbirdio/netbird/commit/6346c3cea63e21cba7dbb83dc585d6d5022df561) Refactor test to validate timer restart after pending update dispatch - [`f8e12de`](https://github.com/netbirdio/netbird/commit/f8e12de1d553a23e331186f61f7a5cb32c86985c) Simplify timer reset for Go 1.23+ automatic channel draining - [`4548e0b`](https://github.com/netbirdio/netbird/commit/4548e0b4bd39f57decb1264fc323f10f7ac8b902) Merge branch 'main' into feature/grpc-debounce-msgtype ### 📊 Changes **8 files changed** (+818 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `management/internals/controllers/network_map/controller/controller.go` (+9 -2) 📝 `management/internals/controllers/network_map/update_channel/updatechannel_test.go` (+14 -8) 📝 `management/internals/controllers/network_map/update_message.go` (+14 -1) 📝 `management/internals/shared/grpc/server.go` (+30 -3) 📝 `management/internals/shared/grpc/token_mgr.go` (+8 -2) ➕ `management/internals/shared/grpc/update_debouncer.go` (+103 -0) ➕ `management/internals/shared/grpc/update_debouncer_test.go` (+587 -0) 📝 `management/server/management_test.go` (+53 -6) </details> ### 📄 Description Implements backpressure handling for peer network map updates to efficiently handle rapid changes. The first update is sent immediately; subsequent rapid updates are coalesced, ensuring that only the latest update is sent after a 1-second quiet period. Intermediate changes do not need to be applied, so the focus is on processing only the final update in the queue. This also fixes lost network updates on the producer side. The network map producer should not depend on network-related layers. Todo: set the channal size to 1 and set it to blocker. ## Describe your changes ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [x] 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](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) ### 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/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Per-peer update debouncer to coalesce rapid updates and reduce update storms * Explicit message-type classification to distinguish network-map vs control/config updates * **Bug Fixes** * Ensure update messages consistently include message-type metadata for correct handling * **Tests** * Comprehensive debouncer test suite (coalescing, ordering, timers, mixed types) * Integration tests updated to track per-peer progress with time‑bounded finalization <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 06:06:01 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#22487