diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs index e1bc772fb..9d8732799 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs @@ -26,6 +26,8 @@ public static class DataConnectionValidator public const int MaxHistoryValuesPerPageLimit = 1_000_000; /// Largest DataExport.MaxHistoryResponseBytes (64 MiB). public const int MaxHistoryResponseBytesLimit = 64 * 1024 * 1024; + /// Smallest DataExport.MaxHistoryResponseBytes (256 KiB): below it a page of ordinary values cannot fit. + public const int MinHistoryResponseBytesLimit = 256 * 1024; /// Largest RemoteNamespaceMapping.MaxHistoryAssemblyBytesPerRequest (1 GiB). 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; diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor index 2857621c4..f6edf530f 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor @@ -89,7 +89,7 @@ else @Operations(e.AllowedOperations, v => e.AllowedOperations = v) -
Larger answers are sent in bounded chunks.
+
Larger answers are sent in bounded chunks.
@Actions(e, e.DataExportRowId != Guid.Empty) } diff --git a/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataHistoryConfigurationTests.cs b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataHistoryConfigurationTests.cs index aeb274a67..d2f62a5cb 100644 --- a/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataHistoryConfigurationTests.cs +++ b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataHistoryConfigurationTests.cs @@ -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, 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"), }) { diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs index 33051cd8c..a3a464a91 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs @@ -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(); + var request = Raw(I("a", RealOriginRequests.Label)); + var all = new List(); 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()!; @@ -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");