diff --git a/packages/test/test-service-load/QueryCommands.json b/packages/test/test-service-load/QueryCommands.json new file mode 100644 index 000000000000..0fc7ff1de3b2 --- /dev/null +++ b/packages/test/test-service-load/QueryCommands.json @@ -0,0 +1,3 @@ +{ + "TestRunSummary":"let searchTestUid = \"{0}\";let searchTimeStart = datetime({1});let searchTimeEnd = datetime({2});customEvents| where timestamp between(searchTimeStart .. searchTimeEnd)| extend testUid = tostring(customDimensions.testUid)| where testUid == searchTestUid| extend category = tostring(customDimensions.category), error = tostring(customDimensions.error), runId = toint(customDimensions.runId), eventName = tostring(customDimensions.eventName)| where category == \"error\" and error !has \"deprecated\" and error !contains \"fluid:telemetry:SummaryStatus Behind\" and eventName != \"fluid:telemetry:SummaryStatus:Behind\" and error !has \"MaxListenersExceededWarning\" and eventName != \"Runner Error\"| summarize errCnt = count() by error, eventName| summarize errCount = sum(errCnt), errors = make_bag(pack(iif(isnotempty(error), error, \"Unknown\"), errCnt)) by eventName| order by errCount" +} \ No newline at end of file diff --git a/packages/test/test-service-load/mailAuto.ps1 b/packages/test/test-service-load/mailAuto.ps1 new file mode 100644 index 000000000000..7826073d0606 --- /dev/null +++ b/packages/test/test-service-load/mailAuto.ps1 @@ -0,0 +1,123 @@ +<# + Script to programmatically mail the results to + the specified users, at the end of a scale test run. + + Make sure that the appropriate environment variables are set. +#> + +Param( + [Parameter(Mandatory = $false, HelpMessage = 'Mail Address of the Sender')] + [string]$MailFrom = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Mail Address of the Recipient')] + [string]$MailTo = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Mail Address of Additional Recipient')] + [string]$MailCC = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Subject of the Mail')] + [string]$MailSubject = "Scale Test Results", + + [Parameter(Mandatory = $false, HelpMessage = 'Full Path of the results file to be attached')] + [string]$AttachmentPath = [System.Environment]::GetEnvironmentVariable('LoadTestResultsFile') +) + +function Invoke-SetProperty { + # Reflection to set the SendUsingAccount property + Param( + [__ComObject] $Object, + [String] $Property, + $Value + ) + + [Void] $Object.GetType().InvokeMember($Property,"SetProperty",$NULL,$Object,$Value) +} + +function MailUsingOutlookPowershell { + <# + .SYNOPSIS + Creates an Outlook COM Object, and sends a mail + with the desired parameters. + + You should ensure that the Outlook client + is setup with the appropriate accounts + #> + $SendFromSmtpAddress = $MailFrom + + # Create COM object named Outlook + $Outlook = New-Object -ComObject Outlook.Application + $Account = $Outlook.session.accounts | ? { $_.smtpAddress -eq $SendFromSmtpAddress } + + # Create Outlook MailItem named Mail using CreateItem() method + $Mail = $Outlook.CreateItem(0) + + # Add properties as desired + $Mail.To = $MailTo + $Mail.CC = $MailCC + $Mail.Subject = $MailSubject + $Mail.Body = $MailBody + $Attachment = $AttachmentPath + $Mail.Attachments.Add($Attachment) + + # Send message + Invoke-SetProperty -Object $Mail -Property "SendUsingAccount" -Value $Account + $Mail.Send() + + # Wait for sometime before quitting outlook + Start-Sleep -Seconds (1*30) + + # Quit and Cleanup + $Outlook.Quit() + [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Outlook) | Out-Null +} + +function MailUsingSendMailMessage { + <# + .SYNOPSIS + Sends a mail using the `Send-MailMessage` cmdlet. + Will be deprecated soon, so you should migrate to + `MailUsingOutlookPowershell` above. + + You should ensure that the appropriate environment + variables are set, and that the credentials are available. + #> + $PassLoc = [System.Environment]::GetEnvironmentVariable('MailFromPasswordPath') + $Username = $MailFrom + $Password = Get-Content $PassLoc | ConvertTo-SecureString + $Cred = New-Object -typename System.Management.Automation.PSCredential ` + -argumentlist $Username, $Password + + $MailHash = @{ + To = $MailTo + From = $MailFrom + Subject = $MailSubject + Body = $MailBody + CC = $MailCC + BodyAsHtml = $true + SmtpServer = 'smtp.office365.com' + UseSSL = $true + Credential = $Cred + Port = 587 + Attachments = $AttachmentPath + } + + Send-MailMessage @MailHash +} + +$TestGuid = [System.Environment]::GetEnvironmentVariable('LoadTestGuid') +$MailBody = "Results of the Load Test with GUID: {0}" -f $TestGuid + +<# + TO-DO: Deprecate this shortly, and use the alternative `MailUsingOutlookPowershell` + for the programmatic mailer after setting up the appropriate account(s) on Outlook. +#> +Write-Host "Mailing the results of the load test" -ForegroundColor Green +MailUsingSendMailMessage +#MailUsingOutlookPowershell +Write-Host "Successfully mailed the results of the load test" -ForegroundColor Green + +<# + Acknowledgements: + [1] https://gist.github.com/ClaudioESSilva/dfaf1de2e5da88fca1e59f70edd7f4ae [ClaudioESSilva] [Mail with Outlook Powershell] + [2] https://sid-500.com/2020/08/25/microsoft-365-send-e-mails-with-powershell/ [Patrick Gruenauer] [Mail with Send-MailMessage] +#> \ No newline at end of file diff --git a/packages/test/test-service-load/mailAutoHelper.ps1 b/packages/test/test-service-load/mailAutoHelper.ps1 new file mode 100644 index 000000000000..152773afd1a8 --- /dev/null +++ b/packages/test/test-service-load/mailAutoHelper.ps1 @@ -0,0 +1,14 @@ +<# + Helper script to read in the password for the automatic mailer, + and save the path to the password (stored as a secure string), + as an appropriate environment variable. +#> + +$PasswordLocation = "" +# Enter the password, to be stored as a secure string +Write-Host "Enter the password for the automatic mailer" -ForegroundColor Cyan +read-host -assecurestring | convertfrom-securestring | out-file $PasswordLocation +# Store the location of the password in an environment variable +[System.Environment]::SetEnvironmentVariable('MailFromPasswordPath', ` + $PasswordLocation, ` + [System.EnvironmentVariableTarget]::User) \ No newline at end of file diff --git a/packages/test/test-service-load/mergeUpstreamMainAuto.ps1 b/packages/test/test-service-load/mergeUpstreamMainAuto.ps1 new file mode 100644 index 000000000000..55b125204d74 --- /dev/null +++ b/packages/test/test-service-load/mergeUpstreamMainAuto.ps1 @@ -0,0 +1,32 @@ +<# + Script to merge the changes in main branch with the loadtest branch at the specified time, + to generate updated builds. + + Ensure that remote origin and remote upstream point to appropriate repositories. + + Merge conflicts need to be resolved manually. +#> + +Param( + [Parameter(Mandatory = $false, HelpMessage = 'Fluid Framework CodeBase Directory')] + [string]$LoadTestDir = "C:\FluidFrameworkCodebase\FluidFramework" +) + +# Make sure this points to the right directory in your local setup (wherever the load test scripts are present) +cd $LoadTestDir + +Write-Host "Checkout local main branch" -ForegroundColor "Green" +git checkout main +Write-Host "Pull the changes from upstream main" -ForegroundColor "Green" +git pull upstream main +Write-Host "Push the changes to origin main" -ForegroundColor "Green" +git push origin main +Write-Host "Checkout local loadtest branch" -ForegroundColor "Green" +git checkout loadtest/main + +# Merge conflicts would need to be resolved manually +Write-Host "Merge the changes made in the main branch, with the loadtest branch" -ForegroundColor "Green" +git merge main +Write-Host "Push changes from local loadtest branch to the branch in remote origin" -ForegroundColor "Green" +git push origin loadtest/main +Write-Host "Changes updated successfully" -ForegroundColor "Green" \ No newline at end of file diff --git a/packages/test/test-service-load/queryLoadTestResults.ps1 b/packages/test/test-service-load/queryLoadTestResults.ps1 new file mode 100644 index 000000000000..3b20c6cbaed6 --- /dev/null +++ b/packages/test/test-service-load/queryLoadTestResults.ps1 @@ -0,0 +1,88 @@ +<# + Make sure that the appropriate environment variables are set. + Uses the python json.tool to pretty-print the results JSON object. +#> + +function QueryLoadTestResults{ + <# + .SYNOPSIS + Fetches the results of the load test run. + + .DESCRIPTION + Queries the results of the scale test by calling the REST API exposed by AppInsights. + Generates the corresponding CURL command given the KustoQuery, and appropriate parameters. + Saves the results as a pretty-printed JSON object, to an output file. + + .PARAMETER AppID + Application ID for the AppInsights Client + + .PARAMETER APIKey + APIKey to call the AppInsights REST API + + .PARAMETER Timespan + Timespan to look at, in the AppInsight logs + + .PARAMETER KustoQueryName + Name of the KustoQuery to be executed + #> + [CmdletBinding()] + Param( + [Parameter(Mandatory = $false, HelpMessage = 'App ID corresponding to the AppInsight')] + [string]$AppID = "", + + [Parameter(Mandatory = $false, HelpMessage = 'API Key with the relevant permission, for the AppInsight')] + [string]$APIKey = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Timespan for the query')] + [string]$Timespan = "PT12H", + + [Parameter(Mandatory = $false, HelpMessage = 'Kusto Query to get the results of the Load Test')] + [string]$KustoQueryName = "TestRunSummary", + + [Parameter(Mandatory = $false, HelpMessage = 'Path to JSON file containing query commands')] + [string]$QueryCommandsPath = ".\QueryCommands.json" + ) + + # AppInsights URL + $SiteURL = "https://api.applicationinsights.io" + + # Get the required environment variables + $LoadTestGuid = [System.Environment]::GetEnvironmentVariable('LoadTestGuid') + $LoadTestStartTime = [System.Environment]::GetEnvironmentVariable('LoadTestStartTime') + $LoadTestStopTime = [System.Environment]::GetEnvironmentVariable('LoadTestStopTime') + + if ($AppID -eq "") + { + $AppID = [System.Environment]::GetEnvironmentVariable('AppInsightAppID') + } + + if ($APIKey -eq "") + { + $APIKey = [System.Environment]::GetEnvironmentVariable('AppInsightAPIKey') + } + + if($KustoQueryName -eq "TestRunSummary") + { + # KustoQuery to fetch the TestRunSummary results + $ReadQuery = Get-Content $QueryCommandsPath | ConvertFrom-Json + $KustoQuery = $ReadQuery.${KustoQueryName} -f $LoadTestGuid,$LoadTestStartTime,$LoadTestStopTime + } + + # Encode Kusto Query into the URI space + $URLQuery = [uri]::EscapeDataString($KustoQuery) + + $SaveFileSuffix = "_{0}.txt" -f $KustoQueryName + $SaveResults = (Get-Location).ToString() +"\out\" + ` + (Get-Date -Format "dddd MM_dd_yyyy HH_mm").ToString() + $SaveFileSuffix + + # CURL command to fetch the results as a JSON object, and pretty print & pipe the JSON into an output file + curl.exe "$SiteURL/v1/apps/$AppID/query?timespan=$Timespan&query=$URLQuery" -H "x-api-key: $APIKey" ` + | python -m json.tool | Out-File -FilePath $SaveResults + + [System.Environment]::SetEnvironmentVariable('LoadTestResultsFile', ` + $SaveResults, ` + [System.EnvironmentVariableTarget]::User) + + Write-Host "Results of the latest load test, TestGuid: $LoadTestGuid fetched and written to $SaveResults" ` + -ForegroundColor Green +} \ No newline at end of file diff --git a/packages/test/test-service-load/queryResultsAuto.ps1 b/packages/test/test-service-load/queryResultsAuto.ps1 new file mode 100644 index 000000000000..ff5a984ba683 --- /dev/null +++ b/packages/test/test-service-load/queryResultsAuto.ps1 @@ -0,0 +1,24 @@ +<# + Script to fetch the results at the end of a load test run. + Triggered as a scheduled task at the specified time. + + Make sure that the appropriate environment variables are set. +#> + +Param( + [Parameter(Mandatory = $false, HelpMessage = 'Load Test Scripts Directory')] + [string]$LoadTestDir = "" +) + +# Make sure this points to the right directory in your local setup (wherever the load test scripts are present) +cd $LoadTestDir + +# Register the QueryLoadTestResults cmdlet function +. .\queryLoadTestResults.ps1 + +# Fetch the required environment variables +$AppID = [System.Environment]::GetEnvironmentVariable('AppInsightAppID') +$APIKey = [System.Environment]::GetEnvironmentVariable('AppInsightAPIKey') + +Write-Host "Fetching the Latest Results" -ForegroundColor Green +QueryLoadTestResults -KustoQueryName "TestRunSummary" -AppID $AppID -APIKey $APIKey \ No newline at end of file diff --git a/packages/test/test-service-load/registerScheduledTasks.ps1 b/packages/test/test-service-load/registerScheduledTasks.ps1 new file mode 100644 index 000000000000..bb87671d68b8 --- /dev/null +++ b/packages/test/test-service-load/registerScheduledTasks.ps1 @@ -0,0 +1,109 @@ +<# + Script to register and run startScaleTestAuto.ps1, stopScaleTestAuto.ps1, queryResultsAuto.ps1, + mergeUpstreamMainAuto.ps1, and mailAuto.ps1 as Scheduled Tasks. + + Starts the Fluid Scale test at the StartTime specified, and stops the test at the specified StopTime. + It then fetches the results of the scale test by running the queryResultsAuto.ps1 script at QueryTime. + Finally, the results of the load test are mailed to the appropriate mailing list. + + The times are in Coordinated Universal Time (UTC) unless specified otherwise. + + Presently, frequency for the Start-Load-Test, Stop-Load-Test, Fetch-Load-Test-Results and + Mail-Load-Test-Results tasks is Daily, and that of the Merge-From-Upstream task is once every 3 days. +#> + +Param( + [Parameter(Mandatory = $false, HelpMessage = 'Start time for the load test')] + [string]$StartTime = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Location of the start script')] + [string]$StartScriptPath = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Stop time for the load test')] + [string]$StopTime = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Location of the stop script')] + [string]$StopScriptPath = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Time at which load test results are to be fetched')] + [string]$QueryTime = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Location of the fetch results script')] + [string]$QueryScriptPath = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Time at which load test results are to be mailed')] + [string]$MailTime = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Location of the programmatic results mailer script')] + [string]$MailScriptPath = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Time at which changes from upstream are to be updated')] + [string]$UpdateTime = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Location of the merge-from-upstream script')] + [string]$UpdateScriptPath = "" + +) + +function RegisterTask { + <# + .SYNOPSIS + Registers the task with the given name, to be triggered at the specified time. + + .PARAMETER TaskName + Name of the Scheduled Task + + .PARAMETER ScheduledTime + Time at which the Scheduled Task is to be triggered + + .PARAMETER Frequency + Frequency (in units of Days) at which the Scheduled Task is to be triggered + + .PARAMETER ScriptPath + Path to the script that is to be executed as a scheduled task + #> + Param( + [Parameter()] + [string]$TaskName, + [Parameter()] + [string]$ScheduledTime, + [Parameter()] + [string]$Frequency, + [Parameter()] + [string]$ScriptPath + ) + + # Initialize common variables + $ExecProg = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" # Make sure this points to the appropriate location in your setup + $Principal = New-ScheduledTaskPrincipal -UserID "$($env:USERDOMAIN)\$($env:USERNAME)" ` + -LogonType ServiceAccount -RunLevel Highest + $Settings = New-ScheduledTaskSettingsSet -Compatibility Win8 + + # Execute Action at the given Trigger + $Trigger = New-ScheduledTaskTrigger -Daily -DaysInterval $Frequency -At $ScheduledTime + $Action = New-ScheduledTaskAction -Execute $ExecProg -Argument "-File $ScriptPath" + Register-ScheduledTask -TaskName $TaskName -Trigger $Trigger -Action $Action ` + -Principal $Principal -Settings $Settings + $OutputMessage = "Successfully Registered the {0} Scheduled Task" -f $TaskName + Write-Host $OutputMessage -ForegroundColor Green +} + +# Register the Merge-From-Upstream task at the specified start time +RegisterTask -TaskName "Merge-From-Upstream" -ScheduledTime $UpdateTime ` +-Frequency "3" -ScriptPath $UpdateScriptPath + +# Register the Start-Load-Test task at the specified start time +RegisterTask -TaskName "Start-Load-Test" -ScheduledTime $StartTime ` +-Frequency "1" -ScriptPath $StartScriptPath + +# Register the Stop-Load-Test task at the specified stop time +RegisterTask -TaskName "Stop-Load-Test" -ScheduledTime $StopTime ` +-Frequency "1" -ScriptPath $StopScriptPath + +# Register the fetch results task at the specified time +RegisterTask -TaskName "Fetch-Load-Test-Results" -ScheduledTime $QueryTime ` +-Frequency "1" -ScriptPath $QueryScriptPath + +# Register the mail results task at the specified time +RegisterTask -TaskName "Mail-Load-Test-Results" -ScheduledTime $MailTime ` +-Frequency "1" -ScriptPath $MailScriptPath \ No newline at end of file diff --git a/packages/test/test-service-load/runloadtest.ps1 b/packages/test/test-service-load/runloadtest.ps1 index 320b73fc0705..f448d7a4730e 100644 --- a/packages/test/test-service-load/runloadtest.ps1 +++ b/packages/test/test-service-load/runloadtest.ps1 @@ -32,7 +32,14 @@ function RunLoadTest { # Create and upload configs for pods to trigger tests. CreateAndUploadConfig -TestTenantConfig $TestTenantConfig -TestUid $TestUid - Write-Output "Triggered LoadTest for TestUid: $TestUid TestDocFolder: $TestDocFolder" + $LatestRunSaveFilePath = (Get-Location).ToString() +"\out\latest_run.txt" + $OutDir = (Get-Location).ToString() +"\out" + If(!(test-path $OutDir)) + { + New-Item -ItemType Directory -Force -Path $OutDir | Out-Null + } + Write-Output "Triggered LoadTest for TestUid: $TestUid TestDocFolder: $TestDocFolder" ` + | Out-File -FilePath $LatestRunSaveFilePath } function CreateInfra { diff --git a/packages/test/test-service-load/startScaleTestAuto.ps1 b/packages/test/test-service-load/startScaleTestAuto.ps1 new file mode 100644 index 000000000000..cff741bcaaeb --- /dev/null +++ b/packages/test/test-service-load/startScaleTestAuto.ps1 @@ -0,0 +1,104 @@ +<# + Script to start the scale test runs: + 1. Logs in to the AKS portal using a service principal + 2. Powers on the Managed Cluster + 3. Scales up the nodes + 4. Triggers the scale test + 5. Deletes the namespace after a specified time, to handle the cold start issue + 6. Re-Triggers the scale test + + Make sure that all the appropriate environment variables are set. +#> + +Param( + [Parameter(Mandatory = $false, HelpMessage = 'Number of documents to run test on')] + [ValidateRange(1, 2400)] + [int]$NumOfDocs = 10, + + [Parameter(Mandatory = $false, HelpMessage = 'Profile to run test with')] + [string]$Profile = "", + + [Parameter(Mandatory = $false, HelpMessage = 'AKS Namespace')] + [ValidateScript({ ( $NumOfDocs -le 10 ) -or ($_ -eq 'fluid-scale-test' ) })] + [string]$Namespace = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Folder to create in Storage for test files')] + [string]$TestDocFolder = [Math]::Floor([decimal](Get-Date(Get-Date).ToUniversalTime() -uformat '%s')), + + [Parameter(Mandatory = $false, HelpMessage = 'File with tenants and users information')] + [string]$TestTenantConfig = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Number of nodes to which the node pool should be scaled')] + [string]$NodeCount = '5', + + [Parameter(Mandatory = $false, HelpMessage = 'Name of the resource group')] + [string]$ResourceGroup = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Name of the AKS Cluster')] + [string]$AKSClusterName = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Name of the node pool to be scaled')] + [string]$NodePoolName = "", + + # Restart the load test after a specified time to avoid the Cold Start issue + [Parameter(Mandatory = $false, HelpMessage = 'Time (in min) after which the scale test is re-triggered')] + [int]$RestartTime = 60, + + [Parameter(Mandatory = $false, HelpMessage = 'Load Test Scripts Directory')] + [string]$LoadTestDir = "" +) + +# Make sure this points to the right directory in your local setup (wherever the load test scripts are present) +cd $LoadTestDir + +Write-Host "Logging in to the AKS portal" -ForegroundColor Green +# Service principal based authentication +az login --service-principal -u $env:AKSServicePrincipalID -p $env:AKSServicePrincipalKey --tenant $env:AKSTenant + +Write-Host "Loading variables and preparing for run" -ForegroundColor Green +. .\runloadtest.ps1 + +Write-Host "Powering On Managed Cluster" -ForegroundColor Green +az aks start -n $AKSClusterName -g $ResourceGroup + +Write-Host "Scaling the Node Pool" -ForegroundColor Green +# Manually scale the Node Pool as appropriate +$_ScaleNodesJob = { param($nodecount, $resourcegroup, $aksclustername, $nodepoolname) ` + az aks scale --resource-group $resourcegroup --name $aksclustername ` + --node-count $nodecount --nodepool-name $nodepoolname + } +$ScaleNodesJob = Start-Job $_ScaleNodesJob -ArgumentList $NodeCount, ` + $ResourceGroup, ` + $AKSClusterName, ` + $NodePoolName +Wait-Job $ScaleNodesJob +Receive-Job $ScaleNodesJob +Write-Host "Scaling Node Pool Finished" -ForegroundColor Green + +Write-Host "Triggering Load Test" -ForegroundColor Green +# Trigger the first run of the load test +RunLoadTest -Profile $Profile -NumOfDocs $NumOfDocs -TestTenantConfig $TestTenantConfig + +# Waits for a specified amount of time after which the load test is re-triggered +Start-Sleep -Seconds (1*60*$RestartTime) + +# End the first run, and re-trigger a second. This is done to tackle the cold-start issue we often encounter +Write-Host "Ending the Load Test" -ForegroundColor Green +$DeleteNamespaceJob = { param($namespace) ` + kubectl delete ns $namespace + } +$DeleteJob = Start-Job $DeleteNamespaceJob -ArgumentList $Namespace +Wait-Job $DeleteJob +Receive-Job $DeleteJob + +# Sets the StartTime environment variable - which will later be used by the queryLoadTestResults script +$StartTime = (Get-Date -Format "yyyy-MM-ddTHH:mm").ToString() +[System.Environment]::SetEnvironmentVariable('LoadTestStartTime', ` + $StartTime, ` + [System.EnvironmentVariableTarget]::User) + +Write-Host "Re-Triggering Load Test" -ForegroundColor Green +# Modify $OutFile as appropriate to point to the location where you want to save the output of `RunLoadTest` +$OutFile = (Get-Location).ToString() +"\out\" + (Get-Date -Format "dddd MM_dd_yyyy HH_mm").ToString() + ".txt" +RunLoadTest -Profile $Profile -NumOfDocs $NumOfDocs -TestTenantConfig $TestTenantConfig ` + | Out-File -FilePath $OutFile \ No newline at end of file diff --git a/packages/test/test-service-load/stopScaleTestAuto.ps1 b/packages/test/test-service-load/stopScaleTestAuto.ps1 new file mode 100644 index 000000000000..a49a2b64a7c7 --- /dev/null +++ b/packages/test/test-service-load/stopScaleTestAuto.ps1 @@ -0,0 +1,57 @@ +<# + Script to stop the scale test runs: + 1. Deletes the namespace + 2. Scales down the nodes + 3. Powers off the Managed Cluster + + Make sure that all the appropriate environment variables are set. +#> + +Param( + [Parameter(Mandatory = $false, HelpMessage = 'AKS Namespace')] + [string]$Namespace = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Number of nodes to which the node pool should be scaled')] + [string]$NodeCount = '0', + + [Parameter(Mandatory = $false, HelpMessage = 'Name of the resource group')] + [string]$ResourceGroup = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Name of the AKS Cluster')] + [string]$AKSClusterName = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Name of the node pool to be scaled')] + [string]$NodePoolName = "", + + [Parameter(Mandatory = $false, HelpMessage = 'Load Test Scripts Directory')] + [string]$LoadTestDir = "" +) + +# Make sure this points to the right directory in your local setup (wherever the load test scripts are present) +cd $LoadTestDir + +Write-Host "Deleting namespace" -ForegroundColor Green +kubectl delete ns $Namespace + +Write-Host "Scaling down the node pool" -ForegroundColor Green +$_ScaleNodesJob = { param($nodecount, $resourcegroup, $aksclustername, $nodepoolname) ` + az aks scale --resource-group $resourcegroup --name $aksclustername ` + --node-count $nodecount --nodepool-name $nodepoolname + } +$ScaleNodesJob = Start-Job $_ScaleNodesJob -ArgumentList $NodeCount, ` + $ResourceGroup, ` + $AKSClusterName, ` + $NodePoolName +Wait-Job $ScaleNodesJob +Receive-Job $ScaleNodesJob +Write-Host "Finished scaling down the node pool" -ForegroundColor Green + +Write-Host "Powering Off Managed Cluster" -ForegroundColor Green +az aks stop -n $AKSClusterName -g $ResourceGroup +Write-Host "Powered Off Managed Cluster" -ForegroundColor Green + +# Sets the StopTime environment variable - which will later be used by the queryLoadTestResults script +$StopTime = (Get-Date -Format "yyyy-MM-ddTHH:mm").ToString() +[System.Environment]::SetEnvironmentVariable('LoadTestStopTime', ` + $StopTime, ` + [System.EnvironmentVariableTarget]::User) \ No newline at end of file