-
Notifications
You must be signed in to change notification settings - Fork 715
feat: add event storage configuration and update queue creation logic #8875
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
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
Added configurable event storage type for NATS coordinator streams, allowing users to choose between memory-based or file-based storage via the ZO_NATS_EVENT_STORAGE environment variable.
Key Changes:
- Added new config field
event_storage(default: "memory") to control NATS JetStream storage type - Refactored queue creation API from multiple specialized methods to a unified builder pattern using
QueueConfigBuilder - Introduced
StorageTypeenum withMemoryandFilevariants - Updated coordinator event stream creation to use configurable storage based on environment settings
Impact:
- Simplifies queue configuration API with cleaner builder pattern
- Provides flexibility for production deployments to choose appropriate storage based on durability vs performance requirements
- Backward compatible - default behavior uses memory storage as before
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The changes follow clean refactoring principles with a builder pattern that improves code maintainability. The removed methods are not used elsewhere in the codebase, ensuring no breaking changes. The new configuration is well-designed with sensible defaults (memory storage), and the implementation correctly handles both memory and file storage types
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/config/src/config.rs | 5/5 | Added new configuration field event_storage to control NATS event stream storage type (memory vs file) |
| src/infra/src/queue/mod.rs | 5/5 | Refactored queue creation API by removing multiple methods and introducing builder pattern with QueueConfig and QueueConfigBuilder |
| src/infra/src/queue/nats.rs | 5/5 | Updated NATS implementation to use new builder-based configuration, added StorageType conversion |
| src/infra/src/coordinator/events.rs | 5/5 | Updated stream creation to use new builder pattern and configurable storage type based on environment variable |
Sequence Diagram
sequenceDiagram
participant App as Application
participant Config as config::get_config()
participant Events as coordinator::events
participant QueueBuilder as QueueConfigBuilder
participant Queue as queue::get_queue()
participant NATS as NATS JetStream
App->>Events: create_stream()
Events->>Config: get event_max_age
Events->>Config: get event_storage
alt event_storage == "memory"
Events->>Events: storage = StorageType::Memory
else event_storage != "memory"
Events->>Events: storage = StorageType::File
end
Events->>Queue: get_queue().await
Events->>QueueBuilder: new()
Events->>QueueBuilder: .max_age(max_age_secs)
Events->>QueueBuilder: .retention_policy(Limits)
Events->>QueueBuilder: .storage_type(storage)
Events->>QueueBuilder: .build()
QueueBuilder-->>Events: QueueConfig
Events->>Queue: create_with_config(COORDINATOR_STREAM, config)
Queue->>NATS: get_or_create_stream(stream_config)
NATS-->>Queue: Stream created/exists
Queue-->>Events: Result<()>
Events-->>App: Stream ready
4 files reviewed, no comments
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 344 | 0 | 19 | 2 | 94% | 4m 38s |
User description
Support storage type for nat queue.
New env:
Default is
memory, supportmemoryorfile.Why we need this?
Summary
Benchmark by tools: https://github.com/openobserve/nats-benchmark
Storage with file:
Storage with memory:
Storage with file
Storage with memory:
PR Type
Enhancement
Description
Add
ZO_NATS_EVENT_STORAGEconfig optionIntroduce queue storage type enum
Replace create APIs with config builder
Configure coordinator stream via builder
Diagram Walkthrough
File Walkthrough
config.rs
Add event storage config to NATS settingssrc/config/src/config.rs
ZO_NATS_EVENT_STORAGEenv config.memory.events.rs
Coordinator stream uses configurable storage and buildersrc/infra/src/coordinator/events.rs
QueueConfigwith max age and retention.create_with_configAPI.mod.rs
Introduce queue configuration builder and storage typesrc/infra/src/queue/mod.rs
StorageType,QueueConfig, and builder.create_with_config.nats.rs
NATS impl supports unified config and storage mappingsrc/infra/src/queue/nats.rs
StorageTypeto JetStream storage.create_with_configusing builder values.