windows: changed method for retrieving Windows network statistics in case of awsvpc network mode
Summary
Previously, we were running a Powershell method (Get-NetAdapterStatistics) to retrieve the network statistics when the task is using awsvpc network mode. However, this can cause CPU spikes on smaller instance types.
Another method to obtain the network statistics would be access them using Win32 API. This method is significantly more performant than using Powershell cmdlet. Therefore, we are switching the agent implementation to use native Win32 API for retrieving the same.
Implementation
When we initialise the stats module for a given task, we will query and store the interface LUID of the task ENI. During the subsequent calls to retrieve the network statistics, we will query the statistics specific to the interface using it's LUID.
In order to accomplish the same, we are introducing two new APIs in NetworkUtils interface would be the preferred way to access Windows networking APIs in the agent. The two APIs are-
- ConvertInterfaceAliasToLUID: Converts the interface alias into the corresponding LUID.
- Internally invokes
ConvertInterfaceAliasToLuidWin32 API to convert interface alias into LUID.
- Internally invokes
- GetMIBIfEntryFromLUID: Returns the MIB_IF_ROW2 for the interface with the given LUID.
- Internally invokes
GetIfEntry2ExWin32 API to obtain the specific interface which has given LUID.
- Internally invokes
Reference:
- https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-convertinterfacealiastoluid
- https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getifentry2ex
Note: As part of this PR, refactoring has been done to improve the code quality of existing Windows workflow.
- Removed
Settermethod fromnetworkUtilspackage - Removed
Settermethod fromwatcherpackage - Introduced mocks for
networkUtilspackage and used the same inwatchertests instead of object injection.
Testing
Tested the new agent using a custom AMI. Tested it out on smaller instance types for any periodic spikes.
New tests cover the changes: Yes
Description for the changelog
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.