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

Stress development maturity updates #3481

Merged
merged 14 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/common/scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ $GetOnboardedDocsMsPackagesForMonikerFn = "Get-${Language}-OnboardedDocsMsPackag
$GetDocsMsTocDataFn = "Get-${Language}-DocsMsTocData"
$GetDocsMsTocChildrenForManagementPackagesFn = "Get-${Language}-DocsMsTocChildrenForManagementPackages"
$UpdateDocsMsTocFn = "Get-${Language}-UpdatedDocsMsToc"
$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme"
$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme"
5 changes: 4 additions & 1 deletion eng/common/scripts/stress-testing/deploy-stress-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ param(
[switch] $CI = ($null -ne $env:SYSTEM_TEAMPROJECTID),

# Optional namespace override, otherwise the shell user or chart annotation will be used
[string]$Namespace
[string]$Namespace,

# Override remote stress-test-addons with local on-disk addons for development
[System.IO.FileInfo]$LocalAddonsPath
)

. $PSScriptRoot/stress-test-deployment-lib.ps1
Expand Down
31 changes: 19 additions & 12 deletions eng/common/scripts/stress-testing/find-all-stress-packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class StressTestPackageInfo {
[string]$ReleaseName
[string]$Dockerfile
[string]$DockerBuildDir
[string]$Deployer
}

function FindStressPackages(
Expand Down Expand Up @@ -50,6 +51,23 @@ function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) {
return $true
}

function GetUsername() {
# Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and
# we would like to avoid namespace overlaps for different codespaces users.
$stressUser = if ($env:GITHUB_USER) {
$env:GITHUB_USER
} elseif ($env:USER) {
$env:USER
} else {
$env:USERNAME
}
benbp marked this conversation as resolved.
Show resolved Hide resolved
# Remove spaces, underscores, etc. that may be in $namespace.
# Value must be a valid RFC 1123 DNS label: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
$stressUser = $stressUser -replace '_|\W', '-'

return $stressUser.ToLower()
}

function NewStressTestPackageInfo(
[hashtable]$chart,
[System.IO.FileInfo]$chartFile,
Expand All @@ -61,18 +79,7 @@ function NewStressTestPackageInfo(
} elseif ($CI) {
$chart.annotations.namespace
} else {
# Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and
# we would like to avoid namespace overlaps for different codespaces users.
$namespace = if ($env:GITHUB_USER) {
$env:GITHUB_USER
} elseif ($env:USER) {
$env:USER
} else {
$env:USERNAME
}
# Remove spaces, underscores, etc. that may be in $namespace. Value must be a valid RFC 1123 DNS label:
# https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
$namespace -replace '_|\W', '-'
GetUsername
}

return [StressTestPackageInfo]@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,18 @@ function DeployStressTests(
[string]$repository = '',
[switch]$pushImages,
[string]$clusterGroup = '',
[string]$deployId = 'local',
[string]$deployId = '',
[switch]$login,
[string]$subscription = '',
[switch]$CI,
[string]$Namespace
[string]$Namespace,
[ValidateScript({
if (!(Test-Path $_)) {
throw "LocalAddonsPath $LocalAddonsPath does not exist"
}
return $true
})]
[System.IO.FileInfo]$LocalAddonsPath
ckairen marked this conversation as resolved.
Show resolved Hide resolved
) {
if ($environment -eq 'test') {
if ($clusterGroup -or $subscription) {
Expand All @@ -94,26 +101,37 @@ function DeployStressTests(
Login -subscription $subscription -clusterGroup $clusterGroup -pushImages:$pushImages
}

RunOrExitOnFailure helm repo add stress-test-charts https://stresstestcharts.blob.core.windows.net/helm/
$chartRepoName = 'stress-test-charts'
if ($LocalAddonsPath) {
$absAddonsPath = Resolve-Path $LocalAddonsPath
ckairen marked this conversation as resolved.
Show resolved Hide resolved
if (!(helm plugin list | Select-String 'file')) {
helm plugin add (Join-Path $absAddonsPath file-plugin)
}
RunOrExitOnFailure helm repo add --force-update $chartRepoName file://$absAddonsPath
} else {
RunOrExitOnFailure helm repo add --force-update $chartRepoName https://stresstestcharts.blob.core.windows.net/helm/
}

Run helm repo update
if ($LASTEXITCODE) { return $LASTEXITCODE }

$deployer = if ($deployId) { $deployId } else { GetUsername }
$pkgs = FindStressPackages -directory $searchDirectory -filters $filters -CI:$CI -namespaceOverride $Namespace
Write-Host "" "Found $($pkgs.Length) stress test packages:"
Write-Host $pkgs.Directory ""
foreach ($pkg in $pkgs) {
Write-Host "Deploying stress test at '$($pkg.Directory)'"
DeployStressPackage `
-pkg $pkg `
-deployId $deployId `
-deployId $deployer `
-environment $environment `
-repositoryBase $repository `
-pushImages:$pushImages `
-login:$login
}

Write-Host "Releases deployed by $deployId"
Run helm list --all-namespaces -l deployId=$deployId
Write-Host "Releases deployed by $deployer"
Run helm list --all-namespaces -l deployId=$deployer

if ($FailedCommands) {
Write-Warning "The following commands failed:"
Expand Down
20 changes: 20 additions & 0 deletions eng/pipelines/stress-cluster-provision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pr: none

trigger: none

parameters:
- name: Environment
type: string
default: test
values:
- prod
- test
Copy link
Member

Choose a reason for hiding this comment

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

Should it be pg?

Copy link
Member Author

@benbp benbp Jun 22, 2022

Choose a reason for hiding this comment

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

Yes I was planning on rebasing/updating after your changes went in.

- name: WhatIf
type: boolean
Copy link
Member

Choose a reason for hiding this comment

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

This will be an interesting pattern. If you find that it works out OK can you please write up some guideline docs about this pattern.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep can do. Plumbing WhatIf support through all our scripts will be pretty useful for general testing and development, I think. Similarly we could run a lot more validation pipelines/scripts on PR changes if we had WhatIf enabled to catch surface level issues.

default: false

extends:
template: /eng/pipelines/templates/jobs/stress-cluster-provision.yml
parameters:
Environment: ${{ parameters.Environment }}
WhatIf: ${{ parameters.WhatIf }}
72 changes: 6 additions & 66 deletions eng/pipelines/stress-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,9 @@ parameters:
type: string
default: main

variables:
- template: /eng/pipelines/templates/variables/globals.yml

jobs:
- job:
strategy:
matrix:
${{ if or(eq(parameters.TestRepository, 'examples'), eq(parameters.TestRepository, 'all')) }}:
examples:
Repository: Azure/azure-sdk-tools
Filters: '@{ "example" = "true" }'
${{ if or(eq(parameters.TestRepository, 'javascript'), eq(parameters.TestRepository, 'all')) }}:
javascript:
Repository: Azure/azure-sdk-for-js
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'java'), eq(parameters.TestRepository, 'all')) }}:
java:
Repository: Azure/azure-sdk-for-java
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'net'), eq(parameters.TestRepository, 'all')) }}:
net:
Repository: Azure/azure-sdk-for-net
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'python'), eq(parameters.TestRepository, 'all')) }}:
python:
Repository: Azure/azure-sdk-for-python
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'go'), eq(parameters.TestRepository, 'all')) }}:
go:
Repository: Azure/azure-sdk-for-go
Filters: '@{}'
pool:
vmImage: 'ubuntu-20.04'
#name: 'azsdk-pool-mms-ubuntu-2004-general'
#vmImage: 'MMSUbuntu20.04'
steps:
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
parameters:
Repositories:
- Name: $(Repository)
Commitish: ${{ parameters.DeployFromBranchOrCommit }}
WorkingDirectory: $(System.DefaultWorkingDirectory)/$(Repository)
Paths:
- '/*'
- '!sdk/**/test-recordings'
- '!sdk/**/session-records'
- '!sdk/**/SessionRecords'

- task: AzureCLI@2
displayName: Build and Deploy Stress Tests
inputs:
${{ if eq(parameters.Environment, 'prod') }}:
azureSubscription: Azure SDK Test Resources
${{ if eq(parameters.Environment, 'test') }}:
azureSubscription: Azure SDK Developer Playground
scriptType: pscore
scriptPath: $(System.DefaultWorkingDirectory)/$(Repository)/eng/common/scripts/stress-testing/deploy-stress-tests.ps1
arguments:
-SearchDirectory '$(System.DefaultWorkingDirectory)/$(Repository)'
-Filters $(Filters)
-Environment '${{ parameters.Environment }}'
-Repository '$(Agent.JobName)'
-PushImages
-Login
-DeployId '$(Build.BuildNumber)'
-CI
extends:
template: /eng/pipelines/templates/jobs/stress-test-release.yml
parameters:
Environment: ${{ parameters.Environment }}
TestRepository: ${{ parameters.TestRepository }}
DeployFromBranchOrCommit: ${{ parameters.DeployFromBranchOrCommit }}
44 changes: 44 additions & 0 deletions eng/pipelines/templates/jobs/stress-cluster-provision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
parameters:
- name: Environment
type: string
- name: WhatIf
type: boolean
default: true

jobs:
- job:
variables:
- template: /eng/pipelines/templates/variables/globals.yml
${{ if eq(parameters.WhatIf, true) }}:
displayName: 'Validate Provision'
${{ else }}:
displayName: 'Provision'
pool:
name: 'azsdk-pool-mms-ubuntu-2004-general'
vmImage: 'MMSUbuntu20.04'
steps:
- ${{ if eq(parameters.WhatIf, true) }}:
- task: AzureCLI@2
displayName: Validate Provision
inputs:
${{ if eq(parameters.Environment, 'prod') }}:
azureSubscription: Azure SDK Test Resources
${{ if eq(parameters.Environment, 'test') }}:
azureSubscription: Azure SDK Playground
scriptType: pscore
scriptPath: $(System.DefaultWorkingDirectory)/tools/stress-cluster/cluster/provision.ps1
arguments:
-Environment ${{ parameters.Environment }}
-WhatIf
- ${{ else }}:
- task: AzureCLI@2
displayName: Provision
inputs:
${{ if eq(parameters.Environment, 'prod') }}:
azureSubscription: Azure SDK Test Resources
${{ if eq(parameters.Environment, 'test') }}:
azureSubscription: Azure SDK Playground
scriptType: pscore
scriptPath: $(System.DefaultWorkingDirectory)/tools/stress-cluster/cluster/provision.ps1
arguments:
-Environment ${{ parameters.Environment }}
77 changes: 77 additions & 0 deletions eng/pipelines/templates/jobs/stress-test-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
parameters:
- name: Environment
type: string
default: test
- name: TestRepository
type: string
default: all
- name: DeployFromBranchOrCommit
type: string
default: main

jobs:
- job:
variables:
- template: /eng/pipelines/templates/variables/globals.yml
strategy:
matrix:
${{ if or(eq(parameters.TestRepository, 'examples'), eq(parameters.TestRepository, 'all')) }}:
examples:
Repository: Azure/azure-sdk-tools
Filters: '@{ "example" = "true" }'
${{ if or(eq(parameters.TestRepository, 'javascript'), eq(parameters.TestRepository, 'all')) }}:
javascript:
Repository: Azure/azure-sdk-for-js
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'java'), eq(parameters.TestRepository, 'all')) }}:
java:
Repository: Azure/azure-sdk-for-java
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'net'), eq(parameters.TestRepository, 'all')) }}:
net:
Repository: Azure/azure-sdk-for-net
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'python'), eq(parameters.TestRepository, 'all')) }}:
python:
Repository: Azure/azure-sdk-for-python
Filters: '@{}'
${{ if or(eq(parameters.TestRepository, 'go'), eq(parameters.TestRepository, 'all')) }}:
go:
Repository: Azure/azure-sdk-for-go
Filters: '@{}'
pool:
vmImage: 'ubuntu-20.04'
#name: 'azsdk-pool-mms-ubuntu-2004-general'
#vmImage: 'MMSUbuntu20.04'
ckairen marked this conversation as resolved.
Show resolved Hide resolved
steps:
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
parameters:
Repositories:
- Name: $(Repository)
Commitish: ${{ parameters.DeployFromBranchOrCommit }}
WorkingDirectory: $(System.DefaultWorkingDirectory)/$(Repository)
Paths:
- '/*'
- '!sdk/**/recordings/*'
- '!sdk/**/test-recordings/*'
- '!sdk/**/session-records/*'
- '!sdk/**/SessionRecords/*'

- task: AzureCLI@2
displayName: Build and Deploy Stress Tests
inputs:
${{ if eq(parameters.Environment, 'prod') }}:
azureSubscription: Azure SDK Test Resources
${{ if eq(parameters.Environment, 'test') }}:
azureSubscription: Azure SDK Playground
scriptType: pscore
scriptPath: $(System.DefaultWorkingDirectory)/$(Repository)/eng/common/scripts/stress-testing/deploy-stress-tests.ps1
arguments:
-SearchDirectory '$(System.DefaultWorkingDirectory)/$(Repository)'
-Filters $(Filters)
-Environment '${{ parameters.Environment }}'
-Repository '$(Agent.JobName)'
-PushImages
-Login
-DeployId '$(Build.BuildNumber)'
-CI
12 changes: 6 additions & 6 deletions eng/pipelines/templates/stages/archetype-sdk-tool-pwsh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ stages:
strategy:
matrix:
Windows:
Pool: 'azsdk-pool-mms-ubuntu-2004-general'
vmImage: 'MMSUbuntu20.04'
Linux:
Pool: 'azsdk-pool-mms-win-2019-general'
vmImage: 'MMS2019'
Image: 'MMS2019'
scbedd marked this conversation as resolved.
Show resolved Hide resolved
Linux:
Pool: 'azsdk-pool-mms-ubuntu-2004-general'
Image: 'MMSUbuntu20.04'
Mac:
Pool: 'Azure Pipelines'
Image: 'macOS-10.15'
Expand All @@ -48,7 +48,7 @@ stages:
$config = New-PesterConfiguration
$config.CodeCoverage.Enabled = $true
$config.TestResult.Enabled = $true

if ($tags) {
$config.Filter.Tag = $tags
}
Expand All @@ -75,4 +75,4 @@ stages:
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '$(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}/coverage.xml'
pathToSources: '$(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}'
pathToSources: '$(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}'
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ annotations:
dependencies:
- name: stress-test-addons
version: 0.1.17
repository: https://stresstestcharts.blob.core.windows.net/helm/
repository: "@stress-test-charts"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- include "stress-test-addons.chaos-wrapper.tpl" (list . "network-chaos") -}}
{{- include "stress-test-addons.chaos-wrapper.tpl" (list . "stress.network-chaos") -}}
{{- define "stress.network-chaos" -}}
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
Expand Down
Loading