Skip to content

[Server] Add Support for Sampling Groups to CustomNodeManager #3075

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

romanett
Copy link
Contributor

@romanett romanett commented May 16, 2025

Proposed changes

This PR introduces a MonitoredItemManager that manages MonitoredItems for the CustomNodeManager this IMonitoredItemManager abstraction has two default implementations, the MonitoredNodeMonitoredItemManager and the SamplingGroupMonitoredItemManager. These allow the CustomNodeManger to manage DataChangeMonitoredItems using the Sampling Group mechanism instead of using the MonitoredNode functionality.

This PR is a first step to allow to obsolete the CoreNodeManager having it´s own implementation of the INodeManager Interface, but instead relying on the proven mechanims of the CustomNodeManager.

This PR also allows to increase the test coverage of the SamplingGroup implementation, that is not covered by tests yet.

The CustomNodeManger has a new constructor overload, that allows to specify if the sampling group mechanism shall be used.

The Reference Server is extended with a new Property UseSamplingGroupsInReferenceNodeManager that allows to enable the use of Sampling Groups in the Reference Node Manager so CTT tests can be carried out with the Sampling Groups.

The Parameter is also enabled in the Reference Server Test to verify the implementation of the sampling group.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

Copy link

codecov bot commented May 16, 2025

Codecov Report

Attention: Patch coverage is 74.60938% with 65 lines in your changes missing coverage. Please review.

Project coverage is 57.97%. Comparing base (2a7de7d) to head (32b07eb).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...MonitoredItem/SamplingGroupMonitoredItemManager.cs 47.87% 43 Missing and 6 partials ⚠️
...MonitoredItem/MonitoredNodeMonitoredItemManager.cs 89.13% 5 Missing and 5 partials ⚠️
...ies/Opc.Ua.Server/Diagnostics/CustomNodeManager.cs 91.42% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3075      +/-   ##
==========================================
+ Coverage   57.33%   57.97%   +0.63%     
==========================================
  Files         357      359       +2     
  Lines       69012    69176     +164     
  Branches    14164    14184      +20     
==========================================
+ Hits        39571    40105     +534     
+ Misses      25195    24784     -411     
- Partials     4246     4287      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@romanett romanett marked this pull request as ready for review May 26, 2025 04:56
@mregen mregen requested a review from Copilot May 27, 2025 16:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces support for sampling groups to the CustomNodeManager by abstracting monitored item management into an IMonitoredItemManager interface with two implementations: one for sampling groups and one for the traditional monitored node mechanism. Key changes include adding new methods (e.g., SetMonitoringMode) to both server and client test services, updating the CustomNodeManager to use the new abstraction, and enabling sampling groups via the ReferenceServer and related configuration.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Tests/Opc.Ua.Server.Tests/ServerTestServices.cs Added SetMonitoringMode method to forward calls to the underlying server, aligning with the new sampling group support.
Tests/Opc.Ua.Server.Tests/ServerFixture.cs Added a sampling groups flag and integrated a call to enable sampling groups in the ReferenceServer during startup.
Tests/Opc.Ua.Server.Tests/ReferenceServerTest.cs Updated tests to set UseSamplingGroupsInReferenceNodeManager and added a delay when sampling groups are active.
Tests/Opc.Ua.Client.Tests/ClientTestServices.cs Added a SetMonitoringMode method in the client test services to complement server changes.
Libraries/Opc.Ua.Server/NodeManager/MonitoredItem/SamplingGroupMonitoredItemManager.cs New implementation for managing monitored items when using sampling groups, including adjustments for zero sampling intervals.
Libraries/Opc.Ua.Server/Diagnostics/CustomNodeManager.cs Refactored to delegate monitored item management to the new IMonitoredItemManager and updated event subscription and restoration code.
Applications/Quickstarts.Servers/ReferenceServer/* Updated the ReferenceServer and related utilities to respect the sampling groups flag and pass it to the CustomNodeManager.

Comment on lines +546 to +549
//If sampling groups are used, samplingInterval needs to be waited before values are queued
if (m_fixture.UseSamplingGroupsInReferenceNodeManager)
{
Thread.Sleep((int)(100.0 * 1.1));
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a fixed Thread.Sleep in tests may lead to flaky behavior; consider replacing it with a more robust waiting or polling mechanism that ensures the sampling interval delay is properly met.

Suggested change
//If sampling groups are used, samplingInterval needs to be waited before values are queued
if (m_fixture.UseSamplingGroupsInReferenceNodeManager)
{
Thread.Sleep((int)(100.0 * 1.1));
// If sampling groups are used, wait for the sampling interval to elapse before queuing values
if (m_fixture.UseSamplingGroupsInReferenceNodeManager)
{
var samplingInterval = TimeSpan.FromMilliseconds(100.0 * 1.1);
var timeout = TimeSpan.FromSeconds(5); // Set a reasonable timeout
var startTime = DateTime.UtcNow;
while (DateTime.UtcNow - startTime < timeout)
{
if (HasSamplingIntervalElapsed(samplingInterval))
{
break;
}
Thread.Sleep(10); // Polling interval
}

Copilot uses AI. Check for mistakes.

Func<ISystemContext, NodeHandle, NodeState, NodeState> AddNodeToComponentCache)
{
// set min sampling interval if 0
if(samplingInterval.CompareTo(0.0) == 0)
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider validating that the samplingInterval is not only equal to zero but also not negative, ensuring adherence to a proper minimum sampling interval requirement.

Suggested change
if(samplingInterval.CompareTo(0.0) == 0)
if (samplingInterval <= 0.0)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant