Skip to content

refactor: endpoint broker l1 tests #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Apr 18, 2025
Merged

Conversation

brendanobra
Copy link
Contributor

@brendanobra brendanobra commented Mar 28, 2025

  • Chores

    • Updated the version of the tokio dependency for enhanced performance and stability.
    • Added a new development dependency for improved testing capabilities.
    • Removed deprecated and unused modules related to advertising, metrics, discovery, and app catalog.
    • Cleaned up imports and removed unused code across multiple modules.
    • Adjusted logging initialization to support module-specific log levels.
  • New Features

    • Enhanced error handling and response processing in service interactions.
    • Improved rule matching and management for more flexible request routing.
    • Introduced advanced asynchronous handling for broker requests, elevating overall responsiveness.
    • Added new fluent methods for modifying RpcRequest instances.
    • Introduced default implementations and methods for managing capabilities in FireboltPermissions.
    • Added logging functionality during the boot process for better monitoring.
    • Added new methods for managing mock responses in tests, enhancing test coverage.
    • Introduced a new rules configuration file for structured device interactions.
    • Added internal RPC interface for telemetry and app event management.
    • Added new modules for default storage properties, ripple cache, and storage management.
    • Added telemetry event sending in app event and capability state emissions.
  • Refactor

    • Streamlined message formatting and request updating to boost maintainability and clarity.
    • Simplified event handling by removing unnecessary complexity in session management.
    • Enhanced clarity of control flow in session initialization and request processing.
    • Removed legacy metrics and behavioral telemetry processing, replacing with operational metrics.
    • Refactored broker and provider request handling to improve modularity and error awareness.
    • Simplified device info and event processing by removing less-used cached fields and events.
    • Reworked mock Thunder controller for asynchronous subscription handling.
    • Consolidated persistent store request processing with improved error handling.
    • Refined internal request processing to support context propagation and app-specific requests.
    • Removed redundant or deprecated RPC methods and event listeners across multiple handlers.
    • Simplified storage manager with comprehensive async get/set methods and error handling.
    • Replaced metrics state with operational telemetry state for improved API stats tracking.
    • Cleaned up ripple context by removing metrics context and related update paths.

Walkthrough

The changes enhance multiple modules across the project. A new development dependency is added to provide deterministic behavior for monotonic counters. The endpoint broker now features new error enums, methods, and refined error handling with stricter atomic ordering and richer logging. The provider broker separates message formatting into its own method, while the rules engine receives additional methods and enums for rule retrieval and classification. The workflow broker updates error mapping and brokerage dispatch via an asynchronous function. A minor non-functional comment is also added in the firebolt gateway.

Changes

File(s) Change Summary
core/main/Cargo.toml - Added serial_test = "3" under [dev-dependencies] with accompanying comments on deterministic monotonic counter generation.
core/main/src/broker/endpoint_broker.rs - Introduced new error enum: HandleBrokerageError.
- Added methods: update_request, get_rule, get_broker_rule, handle_brokerage_workflow.
- Updated get_next_id atomic ordering from Relaxed to SeqCst with enhanced logging.
core/main/src/broker/provider_broker_state.rs - Refactored send_to_provider to leverage a new format_provider_message method for constructing JSON-RPC messages.
core/main/src/broker/rules_engine.rs - Added method get in RuleSet.
- Extended Rule with a new RuleType enum and a rule_type method.
- Introduced methods add_rules, add_rule, and get_rule in RuleEngine.
- Added enums RuleRetrieved and RuleRetrievalError.
- Modified context application methods for fluent chaining.
core/main/src/broker/workflow_broker.rs - Implemented a From conversion from HandleBrokerageError to SubBrokerErr.
- Added new async function subbroker_call replacing the previous brokerage call logic with improved error handling.
core/main/src/firebolt/firebolt_gateway.rs - Inserted a commented-out debug line (//.is_ok();) in the handle method; no functional changes were made.
Cargo.toml - Updated tokio dependency version from 1.43.0 to 1.44.1.
core/main/src/broker/test/mod.rs - Removed #[cfg(test)] from mock_thunder_lite_server module declaration, making it available in all builds.
core/sdk/src/api/firebolt/fb_capabilities.rs - Added Default implementations for FireboltCap and CapabilityRole enums.
- Updated FireboltPermission and FireboltPermissions structs to derive Default.
- Introduced methods add_capability and add_capabilities in FireboltPermissions.
core/sdk/src/api/gateway/rpc_gateway_api.rs - Added methods: with_method, with_context, and with_cid to RpcRequest for fluent modification of its fields.

Sequence Diagram(s)

sequenceDiagram
    participant WB as WorkflowBroker
    participant EB as EndpointBroker
    participant RE as RulesEngine
    WB->>EB: subbroker_call(rpc_request, source)
    EB->>RE: get_rule/get_rule_new(rpc_request)
    RE-->>EB: Return rule or error
    EB->>WB: Return BrokerResponse or error (HandleBrokerageError)
Loading
sequenceDiagram
    participant PS as ProvideBrokerState
    participant Sess as Session
    PS->>PS: format_provider_message(rpc_request, id)
    PS->>Sess: send_json_rpc(ApiMessage)
    Sess-->>PS: JSON-RPC response
Loading

Poem

In the realm of code, where logic does flow,
New dependencies rise, and error types grow.
With brokers and rules, our structure is tight,
We forge ahead boldly, into the night.
Each function refined, each method a gem,
Together we thrive, as a well-oiled system!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

pahearn73
pahearn73 previously approved these changes Apr 11, 2025
@brendanobra brendanobra requested a review from nnaveen979 April 14, 2025 15:08
@brendanobra brendanobra changed the title WIP: Feat/endpoint broker l1 tests refactor: endpoint broker l1 tests Apr 16, 2025
satlead
satlead previously approved these changes Apr 17, 2025
@Rajanika Rajanika requested a review from a team April 18, 2025 14:03
Rajanika
Rajanika previously approved these changes Apr 18, 2025
@brendanobra brendanobra dismissed stale reviews from Rajanika and satlead via e7de84c April 18, 2025 15:32
@brendanobra brendanobra removed the request for review from nnaveen979 April 18, 2025 17:12
@brendanobra brendanobra self-assigned this Apr 18, 2025
Copy link

github-actions bot commented Apr 18, 2025

Code Coverage

Package Line Rate Health
device.thunder_ripple_sdk.src.events 4%
core.sdk.src.api.device 77%
core.sdk.src.api.observability 58%
device.thunder_ripple_sdk.src.bootstrap 0%
core.main.src.service 36%
device.thunder.src 0%
core.main.src.bootstrap 0%
device.thunder_ripple_sdk.src 17%
core.sdk.src.extn 79%
core.sdk.src.extn.client 86%
device.thunder.src.bootstrap 0%
core.main.src.processor 0%
distributor.general.src 3%
core.tdk.src.gateway 100%
core.main.src.broker.test 90%
core.main.src.firebolt 2%
core.main.src.state 32%
core.sdk.src.api 49%
device.thunder_ripple_sdk.src.processors.events 0%
core.main.src.bootstrap.manifest 0%
core.sdk.src.api.distributor 70%
core.main.src.bootstrap.extn 0%
core.sdk.src.utils 48%
core.sdk.src.api.manifest 89%
core.main.src.broker.thunder 37%
device.thunder_ripple_sdk.src.processors 11%
core.sdk.src.api.firebolt 79%
core.sdk.src.manifest 0%
core.main.src.broker 72%
core.main.src.firebolt.handlers 11%
core.sdk.src.framework 74%
core.main.src.service.extn 30%
core.main.src 0%
core.main.src.state.cap 43%
core.sdk.src.api.gateway 69%
core.sdk.src.processor 0%
device.thunder_ripple_sdk.src.client 67%
openrpc_validator.src 67%
device.mock_device.src 54%
core.tdk.src.utils 0%
core.main.src.utils 30%
core.main.src.service.apps 28%
core.sdk.src.extn.ffi 80%
core.main.src.processor.storage 0%
Summary 49% (19408 / 39722)

Minimum allowed line rate is 46%

Current coverage:49% exceeds coverage threshold. Coverage threshold will be updated automatically to reflect to the latest coverage when this pr is merged to main branch.

@brendanobra brendanobra merged commit 55f49f1 into main Apr 18, 2025
7 checks passed
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.

5 participants