Skip to content
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

feat: add license controller + process termination support #239

Open
wants to merge 74 commits into
base: main
Choose a base branch
from

Conversation

abdullah-cognite
Copy link
Collaborator

@abdullah-cognite abdullah-cognite commented Feb 20, 2025

Why is this PR needed?

This package (dotnet-simulator-utils) is used by the PROSPER connector to integrate the PROSPER simulator with CDF. Recently we were having issues with a customer where the PROSPER connector would not be able to run simulations (at random) because the connector was unable to acquire a license for starting the simulator, we came up with an approach where the connector would acquire a license at startup and keep holding on to it for a user defined period of time. We also noticed that occasionally when we shut down the PROSPER simulator, the license would still keep on being consumed unless the simulator process was killed.

This PR adds

  • LicenseController : To help PROSPER (or any other connector) keep track of holding the license and releasing it after a timeout
  • ProcessUtils : To help PROSPER (or any other connector) find processes belonging to the current user and terminating them. This part also caused us to modify our Github action, since the tests for this only run on Windows.

This PR removes:

  • Previous process termination logic, which unfortunately didnt work as we wanted it to. Now termination is handled by each connector since there can be different error codes at which we want to terminate the process, depending upon the simulator.

@abdullah-cognite abdullah-cognite requested a review from a team as a code owner February 20, 2025 06:49
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 73.70690% with 61 lines in your changes missing coverage. Please review.

Project coverage is 72.87%. Comparing base (800ef10) to head (cfbcc5e).

Files with missing lines Patch % Lines
Cognite.Simulator.Utils/LicenseController.cs 80.26% 25 Missing and 5 partials ⚠️
...nite.Simulator.Utils/Automation/AutomationUtils.cs 0.00% 14 Missing ⚠️
Cognite.Simulator.Utils/ProcessUtils.cs 83.01% 7 Missing and 2 partials ⚠️
Cognite.Simulator.Utils/CommonUtils.cs 33.33% 3 Missing and 3 partials ⚠️
...Simulator.Utils/DefaultClasses/DefaultConnector.cs 50.00% 1 Missing ⚠️
...or.Utils/DefaultClasses/DefaultConnectorRuntime.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   71.83%   72.87%   +1.04%     
==========================================
  Files          33       35       +2     
  Lines        3554     3742     +188     
  Branches      422      437      +15     
==========================================
+ Hits         2553     2727     +174     
- Misses        844      854      +10     
- Partials      157      161       +4     
Files with missing lines Coverage Δ
Cognite.Simulator.Utils/Configuration.cs 76.00% <ø> (+3.84%) ⬆️
Cognite.Simulator.Utils/RoutineRunnerBase.cs 83.53% <100.00%> (ø)
...Simulator.Utils/DefaultClasses/DefaultConnector.cs 84.93% <50.00%> (ø)
...or.Utils/DefaultClasses/DefaultConnectorRuntime.cs 53.04% <0.00%> (+0.60%) ⬆️
Cognite.Simulator.Utils/CommonUtils.cs 72.67% <33.33%> (-2.04%) ⬇️
Cognite.Simulator.Utils/ProcessUtils.cs 83.01% <83.01%> (ø)
...nite.Simulator.Utils/Automation/AutomationUtils.cs 8.06% <0.00%> (+2.11%) ⬆️
Cognite.Simulator.Utils/LicenseController.cs 80.26% <80.26%> (ø)

... and 3 files with indirect coverage changes

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

@abdullah-cognite abdullah-cognite changed the title fix cdfretries feat: add license controller + fix bug Feb 20, 2025
@abdullah-cognite abdullah-cognite changed the title feat: add license controller + fix bug feat: add license controller + process termination support Mar 6, 2025
Copy link
Collaborator

@polomani polomani left a comment

Choose a reason for hiding this comment

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

looks better than before

}
}
if (!found) {
throw new Exception("No processes found to kill for the current user");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactor this into a separate unsafe method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can be done in a separate pr as well

{
foreach (ManagementObject process in results)
{
try
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can be outside the for loop as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can be done in a separate pr as well

@abdullah-cognite abdullah-cognite requested review from dbrattli, a team and finnag and removed request for a team March 6, 2025 12:52
Copy link

@finnag finnag left a comment

Choose a reason for hiding this comment

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

NT - just leaving this here to make the PR disappear from my risk review dashboard.
Dag is doing the risk review.

@@ -23,8 +23,10 @@

<ItemGroup>
<PackageReference Include="Cognite.ExtractorUtils" Version="1.29.0" />
<PackageReference Include="Microsoft.Bcl.TimeProvider" Version="10.0.0-preview.1.25080.5" />
Copy link

Choose a reason for hiding this comment

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

Why do we use the preview version?

@@ -175,7 +175,8 @@ public string GetSimulatorVersion()
public Task<Dictionary<string, SimulatorValueItem>> RunSimulation(
SampleModelFilestate modelState,
SimulatorRoutineRevision routineRevision,
Dictionary<string, SimulatorValueItem> inputData
Dictionary<string, SimulatorValueItem> inputData,
CancellationToken _token
Copy link

Choose a reason for hiding this comment

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

Why do we underscore the parameter name?

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.

5 participants