Repository navigation
Add configurable storage type to NATS streaming provider - #10028
Conversation
passes StorageType into StreamConfig so operators can target servers configured with only memoryStore (or only fileStore). Requesting a storage type the server has not provisioned otherwise fails with "insufficient storage resources available" at stream creation, since JetStream reports a 0-byte budget for the disabled backend.
|
@dotnet-policy-service agree |
|
@galvesribeiro can you take a look at this? I am aware that this will break horribly if the nats server/cluster falls over, but that seems like a risk you should be able to take. It's the same for redis streaming depending on the server config. |
|
Sorry for the delay. I see the point of the PR but this is very unsafe. Not sure we should support this. The correct approach from NATS perspective for this kind of scenarios where persistence is not required is to use NATS Core, not JetStream. But yeah, if this is wanted, your implementation is correct. |
There was a problem hiding this comment.
Pull request overview
Adds an operator-configurable JetStream stream storage backend selection to the Orleans NATS streaming provider so deployments can target servers provisioned with only file or only memory storage.
Changes:
- Introduces
NatsOptions.StorageType(defaulting toStreamConfigStorage.File) with documentation. - Applies
StorageTypeto the JetStreamStreamConfigduring stream creation/update. - Adds unit/integration tests covering the new default and verifying storage type is applied on the created stream.
Show a summary per file
| File | Description |
|---|---|
| test/Extensions/Orleans.Streaming.NATS.Tests/NatsOptionsTests.cs | Adds tests for default storage type and verifies storage backend is applied in JetStream stream config. |
| src/Orleans.Streaming.NATS/Providers/NatsConnectionManager.cs | Passes configured storage type into StreamConfig when creating/updating the stream. |
| src/Orleans.Streaming.NATS/NatsOptions.cs | Adds StorageType option and documents expected behavior and failure modes. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 3
| /// <summary> | ||
| /// The storage backend used by the NATS JetStream stream. | ||
| /// Use <see cref="StreamConfigStorage.File"/> for durability across NATS | ||
| /// server restarts, or <see cref="StreamConfigStorage.Memory"/> for lower | ||
| /// latency when durability is not required and the NATS server is | ||
| /// configured with a memory store. The NATS server must have the | ||
| /// corresponding storage type enabled; requesting a storage type the | ||
| /// server has not provisioned results in an "insufficient storage | ||
| /// resources available" error at stream creation. | ||
| /// Defaults to <see cref="StreamConfigStorage.File"/>. | ||
| /// </summary> | ||
| public StreamConfigStorage StorageType { get; set; } = StreamConfigStorage.File; |
There was a problem hiding this comment.
StorageType is user-configurable (via config binding) but NatsStreamOptionsValidator does not validate that the value is a defined StreamConfigStorage enum member. This can result in an invalid numeric value being sent to JetStream and failing at runtime. Consider adding a validator check (e.g., Enum.IsDefined) and throwing an OrleansConfigurationException with guidance on valid values (File/Memory).
There was a problem hiding this comment.
Yeah, I agree here on adding the validation.
| var connectionManager = new NatsConnectionManager(providerName, NullLoggerFactory.Instance, options); | ||
| await connectionManager.Initialize(); | ||
|
|
||
| await using var natsConnection = new NatsConnection(); |
There was a problem hiding this comment.
This test uses new NatsConnection() (default URL) even though NATS availability is determined via NatsTestConstants (which pins Url = nats://127.0.0.1:4222). To avoid localhost/IPv6 resolution mismatches and keep tests consistent with the rest of the NATS test suite, use NatsTestConstants.CreateConnection() (or pass NatsTestConstants.NatsClientOptions) for the verification connection/context.
| await using var natsConnection = new NatsConnection(); | |
| await using var natsConnection = new NatsConnection(NatsTestConstants.NatsClientOptions); |
| NumReplicas = 1, | ||
| PartitionCount = 2, | ||
| ProducerCount = 1, | ||
| StorageType = storageType |
There was a problem hiding this comment.
For consistency with the verification connection and NatsTestConstants settings, consider setting options.NatsClientOptions = NatsTestConstants.NatsClientOptions before constructing NatsConnectionManager. That ensures the manager creates the stream against the same server endpoint that the test later queries.
| StorageType = storageType | |
| StorageType = storageType, | |
| NatsClientOptions = NatsTestConstants.NatsClientOptions |
galvesribeiro
left a comment
There was a problem hiding this comment.
Although I think the ideal usage for NATS JetStream in production workloads is for having persistence, there may be legit cases to have ephemeral streams in memory, but for those cases, I'd think it would be better to use NATS Core, but this has a different semantics on the subscriptions which would require another implementation of the provider.
Nonetheless, this change is ok. Just minor comments in terms of consistency on the tests.
Passes StorageType into StreamConfig so operators can target servers configured with only memoryStore (or only fileStore). Requesting a storage type the server has not provisioned otherwise fails with "insufficient storage resources available" at stream creation, since JetStream reports a 0-byte budget for the disabled backend.
Microsoft Reviewers: Open in CodeFlow