56bb4855bb
M1: the time-weighted family (incl. Total, formerly a pushed-down SUM) streams raw window rows into the C# evaluator. New shared knob ServerHistorian:MaxTimeWeightedRawRows (default 1,000,000; <=0 unbounded with a Validate warning) flows through HistorianBackendRegistry into both providers. The window query is capped at cap+1 (SQL Server TOP (@maxRows), QuestDB LIMIT $4); one row past the cap throws the new Core.Abstractions HistoryReadLimitExceededException, which the node manager maps to BadTooManyOperations for that node. Not counted as a backend health failure; bound rows are not counted; per-sample aggregates are not capped. M2: reverse Interpolative is anchored at the later time (Part 13): points at End - i*interval, emitted latest first. 10:00->09:00 @1h yields 10:00. L1: Partial bit (0x4, = Opc.Ua.AggregateBits.Partial) on non-Bad results of a truncated last interval (time-weighted family; per-sample family is a follow-up). L2/L3: aligned with the SDK AggregateCalculator.GetTimeBasedStatusCode (decompiled from Opc.Ua.Server 1.5.378.106): TreatUncertainAsBad=false counts Uncertain time (Uncertain samples, held-into-outage, extrapolation) as Good time; data but no non-Bad time => generic Bad (0x80000000); BadNoData only when there is no data at all. Consequence: a live tag's latest interval reads Good (documented). L5: release note no longer claims Total matches the Gateway Integral exactly (AVEVA's divisor is unverified); it notes Total is now evaluated in C# and subject to the cap. Tests: unit (reverse Interpolative x3, Partial, Bad vs BadNoData incl. an open-ended outage, cap helpers, SDK bit oracles); conformance (reverse Interpolative, raw-row cap at/over/0, bounds not counted, health unaffected); node manager BadTooManyOperations; options default + warning. Each new behaviour falsified by mutation (aggregator x9, data-source cap checks on both backends against the real DBs, node-manager catch).
67 lines
3.5 KiB
C#
67 lines
3.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Options;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Historian.QuestDb;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Historian.SqlServer;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Host.Configuration;
|
|
|
|
/// <summary>
|
|
/// Maps <c>ServerHistorian:Backend</c> to an <see cref="IHistorianBackendProvider"/>. Names are
|
|
/// case-insensitive. To add a backend, add one entry to <see cref="Factories"/>.
|
|
/// <see cref="Resolve"/> only constructs the provider; option validation belongs to
|
|
/// <see cref="ServerHistorianOptionsValidator"/>.
|
|
/// </summary>
|
|
public static class HistorianBackendRegistry
|
|
{
|
|
/// <summary>Backend name for the SQL Server historian.</summary>
|
|
public const string SqlServerBackendName = "SqlServer";
|
|
|
|
/// <summary>Binds the <c>ServerHistorian:SqlServer</c> section (shared by the registry and the validator).</summary>
|
|
public static SqlServerHistorianOptions BindSqlServer(IConfiguration configuration)
|
|
{
|
|
var o = new SqlServerHistorianOptions();
|
|
configuration.GetSection($"{ServerHistorianOptions.SectionName}:SqlServer").Bind(o);
|
|
return o;
|
|
}
|
|
|
|
/// <summary>Backend name for the QuestDB historian.</summary>
|
|
public const string QuestDbBackendName = "QuestDb";
|
|
|
|
/// <summary>Binds the <c>ServerHistorian:QuestDb</c> section (shared by the registry and the validator).</summary>
|
|
public static QuestDbHistorianOptions BindQuestDb(IConfiguration configuration)
|
|
{
|
|
var o = new QuestDbHistorianOptions();
|
|
configuration.GetSection($"{ServerHistorianOptions.SectionName}:QuestDb").Bind(o);
|
|
return o;
|
|
}
|
|
|
|
private static readonly IReadOnlyDictionary<string, Func<ServerHistorianOptions, IConfiguration, IHistorianBackendProvider>> Factories =
|
|
new Dictionary<string, Func<ServerHistorianOptions, IConfiguration, IHistorianBackendProvider>>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
[ServerHistorianOptions.GatewayBackendName] = (o, _) => new GatewayHistorianProvider(o),
|
|
[SqlServerBackendName] = (o, c) => new SqlServerHistorianProvider(BindSqlServer(c), o.MaxTimeWeightedRawRows),
|
|
[QuestDbBackendName] = (o, c) => new QuestDbHistorianProvider(BindQuestDb(c), o.MaxTimeWeightedRawRows),
|
|
};
|
|
|
|
/// <summary>The registered backend names, for validation messages.</summary>
|
|
public static IReadOnlyCollection<string> KnownBackends { get; } = Factories.Keys.ToArray();
|
|
|
|
/// <summary>True when <paramref name="backend"/> names a registered backend.</summary>
|
|
public static bool IsKnown(string? backend) =>
|
|
!string.IsNullOrWhiteSpace(backend) && Factories.ContainsKey(backend.Trim());
|
|
|
|
/// <summary>Builds the provider for <c>options.Backend</c>; throws <see cref="OptionsValidationException"/> if unknown.</summary>
|
|
public static IHistorianBackendProvider Resolve(ServerHistorianOptions options, IConfiguration configuration)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(options);
|
|
ArgumentNullException.ThrowIfNull(configuration);
|
|
if (!IsKnown(options.Backend))
|
|
throw new OptionsValidationException(
|
|
ServerHistorianOptions.SectionName, typeof(ServerHistorianOptions),
|
|
[$"ServerHistorian:Backend '{options.Backend}' is not a known historian backend. Allowed values: {string.Join(", ", KnownBackends)}."]);
|
|
return Factories[options.Backend.Trim()](options, configuration);
|
|
}
|
|
}
|