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 steps for ram and cpu use #230

Merged
merged 5 commits into from
Nov 9, 2023
Merged

feat: add steps for ram and cpu use #230

merged 5 commits into from
Nov 9, 2023

Conversation

patrzhan
Copy link
Contributor

@patrzhan patrzhan commented Nov 7, 2023

Issue #, if available:

Description of changes:
Adds common steps that allow tracking of the device CPU/RAM use. These will be used by a test that can verify if CPU or RAM use has exceeded a threshold. These CPU/RAM data samples are taken for the general system itself, rather than process specific. This is because it may be difficult to single out a specific component process, but also because we do not know the nature of the tests that may use these steps.

Why is this change necessary:
We will need these steps in order to add a test to the GDK testing template that monitors device CPU/RAM use before and after a component is installed.

How was this change tested:
Steps work with debugging logs when used in a feature file.

Any additional information or context required to review the change:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

github-actions bot commented Nov 7, 2023

Unit Tests Coverage Report for aws-greengrass-testing-features

File Coverage Lines Branches
All files 30% 37% 23%
com.aws.greengrass.testing.model.TestContextModel 0% 0% 0%
com.aws.greengrass.testing.model.RegistrationContextModel 0% 0% 0%
com.aws.greengrass.testing.model.ScenarioContext 64% 70% 57%
com.aws.greengrass.testing.model.GreengrassContextModel 25% 25% 0%
com.aws.greengrass.testing.component.RecipeComponentPreparationService$1 100% 100% 0%
com.aws.greengrass.testing.component.LocalComponentPreparationService$1 100% 100% 0%
com.aws.greengrass.testing.component.CloudComponentPreparationService 32% 39% 25%
com.aws.greengrass.testing.component.ClasspathComponentPreparationService 100% 100% 0%
com.aws.greengrass.testing.component.FileComponentPreparationService 100% 100% 0%
com.aws.greengrass.testing.component.CompositeComponentPreparationService 100% 100% 0%
com.aws.greengrass.testing.component.PreparationServiceUtils 10% 10% 0%
com.aws.greengrass.testing.component.LocalComponentPreparationService 59% 56% 63%
com.aws.greengrass.testing.component.RecipeComponentPreparationService 48% 53% 44%
com.aws.greengrass.testing.util.EncryptionUtils 0% 0% 0%
com.aws.greengrass.testing.util.EncryptionUtils$PemWriter 0% 0% 0%
com.aws.greengrass.testing.features.DeploymentSteps 25% 38% 13%
com.aws.greengrass.testing.features.GreengrassSteps 100% 100% 0%
com.aws.greengrass.testing.features.FileSteps$ByteNotation 0% 0% 0%
com.aws.greengrass.testing.features.FileSteps 11% 11% 0%
com.aws.greengrass.testing.features.WaitSteps 55% 73% 38%
com.aws.greengrass.testing.features.IotSteps 44% 44% 0%
com.aws.greengrass.testing.features.IamSteps 0% 0% 0%
com.aws.greengrass.testing.features.AWSResourcesSteps 0% 0% 0%
com.aws.greengrass.testing.features.DeploymentSteps$2 0% 0% 0%
com.aws.greengrass.testing.features.DeploymentSteps$1 100% 100% 0%
com.aws.greengrass.testing.features.NetworkUtilsSteps 0% 0% 0%
com.aws.greengrass.testing.features.DeploymentSteps$3 100% 100% 0%
com.aws.greengrass.testing.features.S3Steps 72% 94% 50%
com.aws.greengrass.testing.features.RegistrationSteps 34% 40% 28%
com.aws.greengrass.testing.features.GreengrassCliSteps 36% 56% 17%
com.aws.greengrass.testing.features.LoggerSteps 0% 0% 0%
com.aws.greengrass.testing.features.SystemMetricSteps 0% 0% 0%
com.aws.greengrass.testing.DefaultGreengrass 54% 69% 38%
com.aws.greengrass.testing.modules.HsmParameters 0% 0% 0%
com.aws.greengrass.testing.modules.FeatureParameters 0% 0% 0%

Minimum allowed coverage is 60%

Generated by 🐒 cobertura-action against a8433b3

Copy link

github-actions bot commented Nov 7, 2023

Unit Tests Coverage Report for aws-greengrass-testing-launcher

File Coverage Lines Branches
All files 65% 76% 53%
com.aws.greengrass.testing.launcher.reporting.StepTrackingReporting 49% 62% 36%
com.aws.greengrass.testing.launcher.utils.CucumberReportUtils 95% 100% 90%
com.aws.greengrass.testing.launcher.ParallelizationConfig 100% 100% 0%
com.aws.greengrass.testing.launcher.TestLauncherParameterValues 0% 0% 0%
com.aws.greengrass.testing.launcher.TestLauncherParameters 100% 100% 0%

Minimum allowed coverage is 60%

Generated by 🐒 cobertura-action against a8433b3

Copy link

github-actions bot commented Nov 7, 2023

Unit Tests Coverage Report for aws-greengrass-testing-platform-api

File Coverage Lines Branches
All files 40% 30% 49%
com.aws.greengrass.testing.platform.windows.WindowsNetworkUtils 0% 0% 0%
com.aws.greengrass.testing.platform.windows.WindowsPlatform 75% 75% 0%
com.aws.greengrass.testing.platform.windows.WindowsNetworkUtils$1 0% 0% 0%
com.aws.greengrass.testing.platform.windows.WindowsCommands 43% 36% 50%
com.aws.greengrass.testing.platform.macos.MacosNetworkUtils 0% 0% 0%
com.aws.greengrass.testing.platform.macos.MacosCommands 96% 100% 92%
com.aws.greengrass.testing.platform.macos.MacosPlatform 75% 75% 0%
com.aws.greengrass.testing.platform.linux.LinuxNetworkUtils 0% 0% 0%
com.aws.greengrass.testing.platform.linux.LinuxCommands 100% 100% 0%
com.aws.greengrass.testing.platform.linux.LinuxPlatform 75% 75% 0%
com.aws.greengrass.testing.platform.AbstractPlatform 100% 100% 0%
com.aws.greengrass.testing.platform.PlatformResolver 96% 100% 92%
com.aws.greengrass.testing.platform.RemoteFiles 15% 15% 0%
com.aws.greengrass.testing.platform.LocalFiles 61% 71% 50%
com.aws.greengrass.testing.platform.NetworkUtils 0% 0% 0%
com.aws.greengrass.testing.platform.UnixPathsMixin 0% 0% 0%
com.aws.greengrass.testing.platform.UnixCommands 7% 7% 0%
com.aws.greengrass.testing.platform.DevicePredicatePlatformFiles 28% 28% 0%
com.aws.greengrass.testing.platform.NucleusInstallationParametersModel 0% 0% 0%
com.aws.greengrass.testing.platform.Commands 0% 0% 0%
com.aws.greengrass.testing.platform.PlatformFiles 0% 0% 0%

Minimum allowed coverage is 60%

Generated by 🐒 cobertura-action against a8433b3

Copy link

github-actions bot commented Nov 7, 2023

Unit Tests Coverage Report for aws-greengrass-testing-platform-pillbox

File Coverage Lines Branches
All files 66% 67% 65%
com.aws.greengrass.testing.pillbox.commands.files.Mkdir 87% 90% 83%
com.aws.greengrass.testing.pillbox.commands.files.Exists 100% 100% 100%
com.aws.greengrass.testing.pillbox.commands.files.Find 82% 100% 64%
com.aws.greengrass.testing.pillbox.commands.files.Cat 100% 100% 100%
com.aws.greengrass.testing.pillbox.commands.files.Remove 88% 93% 83%
com.aws.greengrass.testing.pillbox.commands.files.Find$Type 89% 93% 86%
com.aws.greengrass.testing.pillbox.Pillbox 0% 0% 0%
com.aws.greengrass.testing.pillbox.commands.Process 0% 0% 0%
com.aws.greengrass.testing.pillbox.commands.Files 0% 0% 0%
com.aws.greengrass.testing.pillbox.commands.process.Descendants 0% 0% 0%

Minimum allowed coverage is 60%

Generated by 🐒 cobertura-action against a8433b3

Copy link
Contributor

@urvashijain18 urvashijain18 left a comment

Choose a reason for hiding this comment

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

What all platforms did you test these changes on?

@patrzhan
Copy link
Contributor Author

patrzhan commented Nov 8, 2023

What all platforms did you test these changes on?

Works on MacOS, Linux, and Windows.



@ScenarioScoped
public class SystemSteps {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can we rename this to something like SystemMetricSteps ?

Comment on lines 26 to 29
private SystemInfo si = new SystemInfo();
private HardwareAbstractionLayer hal = si.getHardware();
private CentralProcessor cpu = hal.getProcessor();
private GlobalMemory ram = hal.getMemory();
Copy link
Member

Choose a reason for hiding this comment

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

Initialize these in a constructor.

public void recordCpuOrRam(String stat) throws IllegalArgumentException {
switch (stat) {
case "CPU":
double cpuLoad = cpu.getSystemCpuLoad(500) * 100;
Copy link
Member

Choose a reason for hiding this comment

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

What does 500 signify here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Milliseconds to wait as the time period we check the cpu load over

Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: This is good. But, can we have a step that stores the recorded value in scenario context? This will help us test the difference between any two values instead of just the last two. Eg. I record the device's {word} usage statistic as {word} and the test would look the following.

    When I record the device's RAM usage statistic as RAM_1
    And I wait 10 seconds
    When I record the device's RAM usage statistic as RAM_2
    And I wait 10 seconds
    When I record the device's RAM usage statistic as RAM_3
    Then the difference between RAM_1 and RAM_3 is less than 1024 MB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that, replaced the old steps with these in latest commit.

switch (stat) {
case "CPU":
if (cpuList.size() < 2) {
throw new Exception("Need at least two CPU samples first.");
Copy link
Contributor

Choose a reason for hiding this comment

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

The exception is not very intuitive, it looks like that CPU or RAM usage is recorded implicitly and do not have enough data to compare instead of deliberately calling previous step to do so.

Same in line 77.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this exception since refactored the steps again, now the records will be saved to scenario context.

if (ramList.size() < 2) {
throw new Exception("Need at least two RAM samples first.");
}
double ramDiff = ramList.get(0) - ramList.get(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

if (cpuList.size() < 2) {
throw new Exception("Need at least two CPU samples first.");
}
double cpuDiff = cpuList.get(0) - cpuList.get(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hard coding the index is not good practice. What if the list has more than 2 records then last and second last index will not be 1 and 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also removed since we're now using scenario context, but in this context I was adding newest records to index 0 so that 0 and 1 would always be the latest two.

}
double cpuSample2 = Double.parseDouble(scenarioContext.get(statKey2));
double cpuSample1 = Double.parseDouble(scenarioContext.get(statKey1));
double cpuDiff = cpuSample2 - cpuSample1;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be absolute if we're checking only the difference? This is assuming that the latter record is always greater than former one. If that's the case, maybe we should reword the step to reflect that.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will update the step wording to reflect that we only care about the increase amount from the first to second sample

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See latest commit

Copy link
Member

Choose a reason for hiding this comment

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

Rename the step to one of these as discussed offline:

Then the CPU usage <metric1> is greater than <metric2> by atmost <threshold> <units>
Then the CPU usage <metric1> is no greater than <metric2> by <threshold> <units>
Then the increase in the CPU usage from <metric1> to <metric2> is less than <threshold> <units>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in latest commit, also added changes to logging.

}
double cpuSample2 = Double.parseDouble(scenarioContext.get(statKey2));
double cpuSample1 = Double.parseDouble(scenarioContext.get(statKey1));
double cpuDiff = cpuSample2 - cpuSample1;
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

}
double ramSample2 = Double.parseDouble(scenarioContext.get(statKey2));
double ramSample1 = Double.parseDouble(scenarioContext.get(statKey1));
double ramDiff = ramSample2 - ramSample1;
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

@patrzhan patrzhan merged commit a99ede2 into main Nov 9, 2023
5 checks passed
@patrzhan patrzhan deleted the ram-cpu-steps branch November 9, 2023 18:39
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.

None yet

3 participants