fix(grpc-data): H2 review2-7c - MaxHistoryResponseBytes minimum 256 KiB (validator + AdminUI min)
Wire tests that relied on a 1-byte response cap now exercise chunking with wide string values at the minimum.
This commit is contained in:
@@ -26,6 +26,8 @@ public static class DataConnectionValidator
|
||||
public const int MaxHistoryValuesPerPageLimit = 1_000_000;
|
||||
/// <summary>Largest <c>DataExport.MaxHistoryResponseBytes</c> (64 MiB).</summary>
|
||||
public const int MaxHistoryResponseBytesLimit = 64 * 1024 * 1024;
|
||||
/// <summary>Smallest <c>DataExport.MaxHistoryResponseBytes</c> (256 KiB): below it a page of ordinary values cannot fit.</summary>
|
||||
public const int MinHistoryResponseBytesLimit = 256 * 1024;
|
||||
/// <summary>Largest <c>RemoteNamespaceMapping.MaxHistoryAssemblyBytesPerRequest</c> (1 GiB).</summary>
|
||||
public const int MaxHistoryAssemblyBytesLimit = 1024 * 1024 * 1024;
|
||||
|
||||
@@ -303,7 +305,7 @@ public static class DataConnectionValidator
|
||||
if (export.MaxBatchItems <= 0 || export.MaxPageItems <= 0 || export.MaxMonitoredItems <= 0 || export.MaxStreams <= 0 ||
|
||||
export.MaxConcurrentHistoryReads <= 0 || export.MaxConcurrentHistoryReads > MaxConcurrentHistoryReadsLimit ||
|
||||
export.MaxHistoryValuesPerPage <= 0 || export.MaxHistoryValuesPerPage > MaxHistoryValuesPerPageLimit ||
|
||||
export.MaxHistoryResponseBytes <= 0 || export.MaxHistoryResponseBytes > MaxHistoryResponseBytesLimit)
|
||||
export.MaxHistoryResponseBytes < MinHistoryResponseBytesLimit || export.MaxHistoryResponseBytes > MaxHistoryResponseBytesLimit)
|
||||
Add("DataExportLimitInvalid", id, "Export limits must be positive.");
|
||||
}
|
||||
return errors;
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ else
|
||||
@Operations(e.AllowedOperations, v => e.AllowedOperations = v)
|
||||
<label class="form-label" for="export-history-reads">Concurrent history reads per peer</label><input id="export-history-reads" type="number" min="1" max="@DataConnectionValidator.MaxConcurrentHistoryReadsLimit" class="form-control mb-2" @bind="e.MaxConcurrentHistoryReads" />
|
||||
<label class="form-label" for="export-history-page">History values per page</label><input id="export-history-page" type="number" min="1" max="@DataConnectionValidator.MaxHistoryValuesPerPageLimit" class="form-control mb-2" @bind="e.MaxHistoryValuesPerPage" />
|
||||
<label class="form-label" for="export-history-bytes">History response bytes</label><input id="export-history-bytes" type="number" min="1" max="@DataConnectionValidator.MaxHistoryResponseBytesLimit" class="form-control mb-2" @bind="e.MaxHistoryResponseBytes" /><div class="form-text">Larger answers are sent in bounded chunks.</div>
|
||||
<label class="form-label" for="export-history-bytes">History response bytes</label><input id="export-history-bytes" type="number" min="@DataConnectionValidator.MinHistoryResponseBytesLimit" max="@DataConnectionValidator.MaxHistoryResponseBytesLimit" class="form-control mb-2" @bind="e.MaxHistoryResponseBytes" /><div class="form-text">Larger answers are sent in bounded chunks.</div>
|
||||
<label><input type="checkbox" @bind="e.Enabled" /> Enabled in next deployment</label>@Actions(e, e.DataExportRowId != Guid.Empty)
|
||||
</div></section>
|
||||
}
|
||||
|
||||
+2
@@ -73,6 +73,7 @@ public sealed class GrpcDataHistoryConfigurationTests
|
||||
DataConnectionValidator.MaxConcurrentHistoryReadsLimit.ShouldBe(64);
|
||||
DataConnectionValidator.MaxHistoryValuesPerPageLimit.ShouldBe(1_000_000);
|
||||
DataConnectionValidator.MaxHistoryResponseBytesLimit.ShouldBe(64 * 1024 * 1024);
|
||||
DataConnectionValidator.MinHistoryResponseBytesLimit.ShouldBe(256 * 1024);
|
||||
DataConnectionValidator.MaxHistoryAssemblyBytesLimit.ShouldBe(1024 * 1024 * 1024);
|
||||
foreach (var (set, code) in new (Action<DraftSnapshot>, string)[]
|
||||
{
|
||||
@@ -80,6 +81,7 @@ public sealed class GrpcDataHistoryConfigurationTests
|
||||
(d => d.DataExports[0].MaxConcurrentHistoryReads = 65, "DataExportLimitInvalid"),
|
||||
(d => d.DataExports[0].MaxHistoryValuesPerPage = 1_000_001, "DataExportLimitInvalid"),
|
||||
(d => d.DataExports[0].MaxHistoryResponseBytes = 64 * 1024 * 1024 + 1, "DataExportLimitInvalid"),
|
||||
(d => d.DataExports[0].MaxHistoryResponseBytes = 256 * 1024 - 1, "DataExportLimitInvalid"),
|
||||
(d => d.RemoteNamespaceMappings[0].MaxHistoryAssemblyBytesPerRequest = int.MaxValue, "DataMappingLimitInvalid"),
|
||||
})
|
||||
{
|
||||
|
||||
+20
-15
@@ -27,6 +27,8 @@ public sealed class GrpcDataHistoryWireTests
|
||||
|
||||
private static DataHistoryReadItem I(string id, DataView view) => new(id, view);
|
||||
|
||||
private static string Wide(int i) => i.ToString(System.Globalization.CultureInfo.InvariantCulture).PadRight(5000, 'x');
|
||||
|
||||
private static W.HistoryReadRequest Raw(params DataHistoryReadItem[] items) => DataHistoryProtoMapper.EncodeRequest(
|
||||
new DataHistoryReadRequest(new DataHistoryRawDetails(T0, T0.AddHours(1), 0, false), items, Budget));
|
||||
|
||||
@@ -192,25 +194,27 @@ public sealed class GrpcDataHistoryWireTests
|
||||
[Fact]
|
||||
public async Task An_answer_larger_than_the_response_cap_is_chunked_and_a_lost_chunk_is_ContinuationPointInvalid()
|
||||
{
|
||||
await using var origin = new RealOrigin(responseBytes: 1);
|
||||
origin.History!.Samples = Enumerable.Range(0, 2000).Select(i => new OriginHistorySample((double)i, 0, T0.AddSeconds(i).UtcDateTime, null)).ToArray();
|
||||
await using var origin = new RealOrigin(responseBytes: 256 * 1024);
|
||||
origin.History!.AlsoHistorized.Add("Plant/Modbus/dev1/Label");
|
||||
var expected = Enumerable.Range(0, 300).Select(Wide).ToArray(); // ~1.5 MB: far above the 192 KiB effective budget
|
||||
origin.History.Samples = expected.Select((v, i) => new OriginHistorySample(v, 0, T0.AddSeconds(i).UtcDateTime, null)).ToArray();
|
||||
origin.History.Continuation = Enumerable.Repeat((byte)7, 16).ToArray();
|
||||
var request = Raw(I("a", RealOriginRequests.Flow));
|
||||
var all = new List<double>();
|
||||
var request = Raw(I("a", RealOriginRequests.Label));
|
||||
var all = new List<string>();
|
||||
var page = (await origin.HistoryAsync(request, History)).Items.Single();
|
||||
var chunks = 1;
|
||||
page.ChunkContinues.ShouldBeTrue();
|
||||
var firstToken = page.Continuation.ToByteArray();
|
||||
while (page.ChunkContinues)
|
||||
{
|
||||
all.AddRange(page.Samples.Select(s => s.Value.DoubleValue));
|
||||
all.AddRange(page.Samples.Select(s => s.Value.StringValue));
|
||||
var next = request.Clone(); next.Items[0].Continuation = page.Continuation;
|
||||
page = (await origin.HistoryAsync(next, History)).Items.Single();
|
||||
chunks++;
|
||||
}
|
||||
all.AddRange(page.Samples.Select(s => s.Value.DoubleValue));
|
||||
all.AddRange(page.Samples.Select(s => s.Value.StringValue));
|
||||
chunks.ShouldBeGreaterThan(1);
|
||||
all.ShouldBe(Enumerable.Range(0, 2000).Select(i => (double)i));
|
||||
all.ShouldBe(expected);
|
||||
page.Continuation.ToByteArray().ShouldBe(origin.History.Continuation, "the last chunk carries the page continuation");
|
||||
origin.History.Calls.ShouldBe(1, "chunks are served from the transport remainder, not re-read");
|
||||
// The first chunk token was consumed: replaying it (a page lost in transit) is invalid, never a skipped page.
|
||||
@@ -225,9 +229,10 @@ public sealed class GrpcDataHistoryWireTests
|
||||
[Fact]
|
||||
public async Task Release_continuations_drops_the_tokens_without_reading()
|
||||
{
|
||||
await using var origin = new RealOrigin(responseBytes: 1);
|
||||
origin.History!.Samples = Enumerable.Range(0, 2000).Select(i => new OriginHistorySample((double)i, 0, T0.AddSeconds(i).UtcDateTime, null)).ToArray();
|
||||
var request = Raw(I("a", RealOriginRequests.Flow));
|
||||
await using var origin = new RealOrigin(responseBytes: 256 * 1024);
|
||||
origin.History!.AlsoHistorized.Add("Plant/Modbus/dev1/Label");
|
||||
origin.History.Samples = Enumerable.Range(0, 300).Select(i => new OriginHistorySample(Wide(i), 0, T0.AddSeconds(i).UtcDateTime, null)).ToArray();
|
||||
var request = Raw(I("a", RealOriginRequests.Label));
|
||||
var chunk = (await origin.HistoryAsync(request, History)).Items.Single();
|
||||
chunk.ChunkContinues.ShouldBeTrue();
|
||||
var release = request.Clone(); release.Items[0].Continuation = chunk.Continuation; release.ReleaseContinuations = true;
|
||||
@@ -241,7 +246,7 @@ public sealed class GrpcDataHistoryWireTests
|
||||
[Fact]
|
||||
public async Task Direct_runtime_consumer_reads_history_through_the_local_connection_unchunked()
|
||||
{
|
||||
await using var origin = new RealOrigin(responseBytes: 1);
|
||||
await using var origin = new RealOrigin();
|
||||
origin.History!.Samples = Enumerable.Range(0, 500).Select(i => new OriginHistorySample((double)i, 0, T0.AddSeconds(i).UtcDateTime, null)).ToArray();
|
||||
await using var connection = origin.Connect();
|
||||
var history = connection.ShouldBeAssignableTo<IDataHistoryService>()!;
|
||||
@@ -377,9 +382,9 @@ public sealed class GrpcDataHistoryWireTests
|
||||
[Fact]
|
||||
public async Task A_single_value_larger_than_the_response_limit_is_answered_per_item()
|
||||
{
|
||||
await using var origin = new RealOrigin(responseBytes: 1);
|
||||
await using var origin = new RealOrigin(responseBytes: 256 * 1024);
|
||||
origin.History!.AlsoHistorized.Add("Plant/Modbus/dev1/Label");
|
||||
origin.History.Samples = [new(new string('x', 40_000), 0, T0.UtcDateTime, null)];
|
||||
origin.History.Samples = [new(new string('x', 300_000), 0, T0.UtcDateTime, null)];
|
||||
var response = await origin.HistoryAsync(Raw(I("label", RealOriginRequests.Label)), History);
|
||||
var item = response.Items.Single();
|
||||
item.StatusCode.ShouldBe(0x80100000u);
|
||||
@@ -390,10 +395,10 @@ public sealed class GrpcDataHistoryWireTests
|
||||
[Fact]
|
||||
public async Task A_refused_node_releases_the_page_cursor_it_was_just_given()
|
||||
{
|
||||
await using var origin = new RealOrigin(responseBytes: 1);
|
||||
await using var origin = new RealOrigin(responseBytes: 256 * 1024);
|
||||
origin.History!.AlsoHistorized.Add("Plant/Modbus/dev1/Label");
|
||||
origin.History.RealCursors = true; // the fake saves a REAL page cursor in the session's store and returns its token
|
||||
origin.History.Samples = [new(new string('x', 40_000), 0, T0.UtcDateTime, null)];
|
||||
origin.History.Samples = [new(new string('x', 300_000), 0, T0.UtcDateTime, null)];
|
||||
var item = (await origin.HistoryAsync(Raw(I("label", RealOriginRequests.Label)), History)).Items.Single();
|
||||
item.StatusCode.ShouldBe(0x80100000u);
|
||||
origin.History.LastCursors.ShouldNotBeNull().Count.ShouldBe(0, "the refused node's page cursor is not left behind");
|
||||
|
||||
Reference in New Issue
Block a user