Skip to content

Conversation

@jajeffries
Copy link
Contributor

This pull request refactors the handling of group memberships in the fleet messaging system to improve management of group subscriptions, especially when receiving a full list of group memberships. The changes introduce a GroupManager to track group state, update the Messaging component to use this manager, and enhance test coverage to account for these changes.

Core logic improvements:

  • The Messaging struct now includes a GroupManager to keep track of current group memberships, allowing for correct subscription and unsubscription when a full list of groups is received. (agent/configmgr/fleet/from_rpc.go [1] [2]
  • The handleGroupMemberships method now unsubscribes from topics that are no longer part of the full group list and removes them from the GroupManager, ensuring that the agent's subscriptions match the authoritative list from the server. (agent/configmgr/fleet/from_rpc.go agent/configmgr/fleet/from_rpc.goL96-R120)

Constructor and dependency updates:

  • The NewMessaging and NewMQTTConnection constructors are updated to require and pass a GroupManager instance, ensuring consistent group state management across the system. (agent/configmgr/fleet/from_rpc.go [1] agent/configmgr/fleet/connection.go [2]

Testing improvements:

  • All relevant tests are updated to initialize and pass a GroupManager to NewMessaging, and to provide mock unsubscribe functions where necessary to fully exercise the new logic. (agent/configmgr/fleet/from_rpc_test.go [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

Refactoring for clarity and maintainability:

  • The signature of handleGroupMemberships is simplified to accept a TopicActions struct containing subscribe, publish, and unsubscribe functions, making the code easier to extend and maintain. (agent/configmgr/fleet/from_rpc.go [1] [2]

Test logic enhancements:

  • Test cases are enhanced to verify correct subscription and unsubscription behavior, including handling of empty and invalid group payloads, and ensuring no panics or unexpected behavior occur. (agent/configmgr/fleet/from_rpc_test.go [1] [2] [3] [4] [5] [6] [7]

These changes collectively improve the robustness and correctness of group membership handling in the agent's messaging system.

@jajeffries jajeffries self-assigned this Oct 14, 2025
@github-actions
Copy link

github-actions bot commented Oct 14, 2025

Go test coverage

STATUS ELAPSED PACKAGE COVER PASS FAIL SKIP
🟢 PASS 0.01s github.com/netboxlabs/orb-agent/agent 0.0% 0 0 0
🟢 PASS 1.11s github.com/netboxlabs/orb-agent/agent/backend 33.3% 30 0 0
🟢 PASS 4.03s github.com/netboxlabs/orb-agent/agent/backend/devicediscovery 79.4% 2 0 0
🟢 PASS 0.01s github.com/netboxlabs/orb-agent/agent/backend/mocks 0.0% 0 0 0
🟢 PASS 4.02s github.com/netboxlabs/orb-agent/agent/backend/networkdiscovery 80.6% 2 0 0
🟢 PASS 4.02s github.com/netboxlabs/orb-agent/agent/backend/opentelemetryinfinity 74.1% 2 0 0
🟢 PASS 4.03s github.com/netboxlabs/orb-agent/agent/backend/pktvisor 71.7% 2 0 0
🟢 PASS 4.02s github.com/netboxlabs/orb-agent/agent/backend/snmpdiscovery 80.2% 2 0 0
🟢 PASS 5.03s github.com/netboxlabs/orb-agent/agent/backend/worker 80.6% 3 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/config 100.0% 6 0 0
🟢 PASS 31.17s github.com/netboxlabs/orb-agent/agent/configmgr 49.8% 14 0 0
🟢 PASS 4.54s github.com/netboxlabs/orb-agent/agent/configmgr/fleet 70.8% 121 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/policies 100.0% 15 0 0
🟢 PASS 1.03s github.com/netboxlabs/orb-agent/agent/policymgr 71.2% 10 0 0
🟢 PASS 26.69s github.com/netboxlabs/orb-agent/agent/secretsmgr 48.9% 54 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/version 100.0% 1 0 0

Total coverage: 63.1%

@jajeffries jajeffries marked this pull request as ready for review October 14, 2025 12:36
Copy link
Contributor

@leoparente leoparente left a comment

Choose a reason for hiding this comment

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

Overall LGTM

@jajeffries jajeffries merged commit fda5878 into develop Oct 14, 2025
5 checks passed
@jajeffries jajeffries deleted the feat/OBS-1489-group-heartbeat branch October 14, 2025 13:25
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

🎉 This PR is included in version 2.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

🎉 This PR is included in version 2.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants