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

Performance/win runner #101

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 20 additions & 4 deletions .github/workflows/taxreport-loadtest-ondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ on:
default: "'ubuntu-latest'"
options:
- "'ubuntu-latest'"
- "['self-hosted', 'macOS', 'X64']"
- "'windows-latest'"
- "'macOS-latest'"

jobs:
run-taxreport-ondemand:
Expand All @@ -34,14 +35,29 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Generate tokens
- name: Generate tokens (Linux/Mac)
if: runner.os != 'Windows'
working-directory: ./performance-tests/tax-report/src
run: ../../generate-tokens/src/generate-tokens.sh ../../generate-tokens/src ${{ inputs.limit }}
env:
API_ENVIRONMENT: ${{ secrets.YTENVIRONMENT }}
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKENGENUSER }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKENGENPWD }}

- name: Generate tokens (Windows)
if: runner.os == 'Windows'
working-directory: ./performance-tests/tax-report/src
run: pwsh ../../generate-tokens/src/generate-tokens.ps1 `
-testdatafilepath ../../generate-tokens/src `
-limit ${{ inputs.limit }} `
-API_ENVIRONMENT ${{ secrets.YTENVIRONMENT }} `
-TOKEN_GENERATOR_USERNAME ${{ secrets.TOKENGENUSER }} `
-TOKEN_GENERATOR_PASSWORD ${{ secrets.TOKENGENPWD }}
env:
API_ENVIRONMENT: ${{ secrets.YTENVIRONMENT }}
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKENGENUSER }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKENGENPWD }}

- name: Setup K6
uses: grafana/setup-k6-action@v1

Expand All @@ -53,8 +69,8 @@ jobs:
env:
K6_WEB_DASHBOARD: true
K6_WEB_DASHBOARD_EXPORT: html-report.html
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
#K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
#K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
serviceowner: ${{ secrets.OWNER }}

- name: Upload summary html report
Expand Down
85 changes: 85 additions & 0 deletions performance-tests/generate-tokens/src/generate-tokens.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
param (
[Parameter(Mandatory=$true)]
[string]$TOKEN_GENERATOR_USERNAME,
[Parameter(Mandatory=$true)]
[string]$TOKEN_GENERATOR_PASSWORD,
[Parameter(Mandatory=$true)]
[string]$API_ENVIRONMENT,
[Parameter(Mandatory=$true)]
[string]$testdatafilepath,
[Parameter(Mandatory=$true)]
[int]$limit
)

# Check if required environment variables are set
if (-not $TOKEN_GENERATOR_USERNAME -or -not $TOKEN_GENERATOR_PASSWORD -or -not $API_ENVIRONMENT) {
Write-Host "Error: TOKEN_GENERATOR_USERNAME, TOKEN_GENERATOR_PASSWORD, and API_ENVIRONMENT must be set"
exit 1
}

# Function to display usage information
function Usage {
Write-Host "Usage: $PSCommandPath -testdatafilepath <testdatafilepath> -limit <limit>"
Write-Host " <testdatafilepath>: Path to the test data files"
Write-Host " <limit>: limit number of tokens to generate. 0 means generate all"
exit 1
}

# Validate arguments
#if ($args.Length -ne 2) {
# Usage
#}

$tokengenuser = $TOKEN_GENERATOR_USERNAME
$tokengenpasswd = $TOKEN_GENERATOR_PASSWORD

$env = ""
switch ($API_ENVIRONMENT) {
"at21" { $env = "at21" }
"tt02" { $env = "tt02" }
"yt01" { $env = "yt01" }
default {
Write-Host "Error: Unknown api environment $API_ENVIRONMENT"
exit 1
}
}

$enduser_datafile = "$testdatafilepath/data-$API_ENVIRONMENT.csv"
$enduser_tokenfile = ".data-with-tokens.csv"

if (-not (Test-Path $enduser_datafile)) {
Write-Host "Error: Input file not found: $enduser_datafile"
exit 1
}

"userId,partyId,ssn,token" | Out-File -FilePath $enduser_tokenfile -Encoding utf8
$status = $?
if ($status -ne 1) {
Write-Host "Error: Failed to write header to file $enduser_tokenfile"
exit 1
}

$generated = 0
Import-Csv -Path $enduser_datafile | ForEach-Object {
if ($limit -gt 0 -and $generated -ge $limit) {
break
}
$partyId = $_.partyId
$userId = $_.userId
$ssn = $_.ssn

$url = "https://altinn-testtools-token-generator.azurewebsites.net/api/GetPersonalToken?env=$env&userId=$userId&partyId=$partyId&pid=$ssn&ttl=3600"
#$token = Invoke-RestMethod -Uri $url -Method Get -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $tokengenuser, (ConvertTo-SecureString -String $tokengenpasswd -AsPlainText -Force))
$token = Invoke-RestMethod -Uri $url -Headers @{Authorization=("Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${tokengenuser}:${tokengenpasswd}")))} -Method Get
if (-not $?) {
Write-Host "Error: Failed to generate personal token for: $ssn, $scopes"
continue
}
"$userId,$partyId,$ssn,$token" | Out-File -FilePath $enduser_tokenfile -Append -Encoding utf8
$status = $?
if ($status -ne 1) {
Write-Host "Error: Failed to write personal token to file for: $ssn $status"
} else {
$generated++
}
}
Loading