Skip to content

Conversation

@jajeffries
Copy link
Contributor

This pull request refactors the MQTT message handling logic in the Fleet configuration manager to improve modularity, testability, and separation of concerns. The primary change is the introduction of a new Messaging struct that encapsulates all message dispatching and handling logic, decoupling it from the core MQTT connection code. This also results in updated method signatures, improved dependency injection (notably for the policy manager), and more comprehensive unit tests with mock implementations.

Refactoring and Modularity Improvements:

  • Introduced a new Messaging struct in from_rpc.go to handle all MQTT message dispatching and processing, moving logic out of MQTTConnection and improving separation of concerns. The Messaging struct now manages group membership and agent policy messages, and is injected with a PolicyManager dependency for better testability and modularity.
  • Updated MQTTConnection to include a messaging field and delegate message-related logic (capabilities, group memberships, and policy updates) to the Messaging struct. This includes changes to the constructor and method signatures to pass the PolicyManager and agent ID where needed. [1] [2] [3] [4] [5]

API and Interface Changes:

  • Changed the signature of NewMQTTConnection to require a PolicyManager and updated all usages accordingly. The Connect method now also takes the agentID as a separate parameter and passes it through to message handlers. [1] [2] [3]
  • Added new helper methods to MQTTConnection for subscribing and publishing to topics, which are now passed as function parameters to the message handlers for improved decoupling.

Testing Improvements:

  • Added comprehensive mock implementations of the PolicyManager interface in both connection_test.go and from_rpc_test.go, enabling more robust and isolated unit tests for message handling logic. [1] [2]
  • Updated existing tests to use the new Messaging struct and mock dependencies, ensuring that message dispatching and handler logic are properly exercised and validated. [1] [2] [3]

Other Notable Changes:

  • Improved error handling and logging throughout the message dispatching process, including explicit logging for unknown message types and unmarshalling failures.
  • Cleaned up imports and removed unused dependencies, such as encoding/json where no longer needed.

These changes collectively make the Fleet configuration manager's MQTT handling more modular, maintainable, and testable, laying the groundwork for future enhancements.

References:
[1] [2] [3] [4] [5] [6]

@github-actions
Copy link

github-actions bot commented Oct 8, 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 0.01s github.com/netboxlabs/orb-agent/agent/backend 0.0% 0 0 0
🟢 PASS 5.03s github.com/netboxlabs/orb-agent/agent/backend/devicediscovery 76.0% 3 0 0
🟢 PASS 0.01s github.com/netboxlabs/orb-agent/agent/backend/mocks 0.0% 0 0 0
🟢 PASS 8.04s github.com/netboxlabs/orb-agent/agent/backend/networkdiscovery 76.2% 7 0 0
🟢 PASS 4.02s github.com/netboxlabs/orb-agent/agent/backend/opentelemetryinfinity 75.9% 2 0 0
🟢 PASS 3.02s github.com/netboxlabs/orb-agent/agent/backend/pktvisor 65.6% 2 0 0
🟢 PASS 8.04s github.com/netboxlabs/orb-agent/agent/backend/snmpdiscovery 75.8% 7 0 0
🟢 PASS 5.03s github.com/netboxlabs/orb-agent/agent/backend/worker 76.0% 3 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/config 100.0% 6 0 0
🟢 PASS 31.18s github.com/netboxlabs/orb-agent/agent/configmgr 51.5% 13 0 0
🟢 PASS 4.41s github.com/netboxlabs/orb-agent/agent/configmgr/fleet 54.3% 54 0 0
🟢 PASS 1.01s github.com/netboxlabs/orb-agent/agent/policies 100.0% 15 0 0
🟢 PASS 1.02s github.com/netboxlabs/orb-agent/agent/policymgr 70.3% 10 0 0
🟢 PASS 31.77s 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: 58.8%

@jajeffries jajeffries merged commit a8329e1 into develop Oct 9, 2025
5 checks passed
@jajeffries jajeffries deleted the feat/OBS-1449-apply-policies branch October 9, 2025 09:13
@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.

5 participants