Azure DevOps

Ovaj vodič objašnjava kako integrirati LoadFocus JMeter API klijent s Azure DevOps za automatizirano testiranje performansi.

Koraci postavljanja

1. Pohranite vjerodajnice u Azure Key Vault

Za sigurno upravljanje vjerodajnicama, pohranite vaše LoadFocus API vjerodajnice u Azure Key Vault:

  1. Kreirajte Key Vault u Azureu ako ga nemate
  2. Dodajte sljedeće tajne:
    • loadfocus-api-key: Vaš LoadFocus API ključ
    • loadfocus-team-id: Vaš LoadFocus ID tima
  3. Postavite servisnu vezu za pristup Key Vaultu iz vašeg cjevovoda

2. Kreirajte Azure cjevovod

Kreirajte novu datoteku pod nazivom azure-pipelines.yml u vašem repozitoriju:

trigger:
- main
- develop
pool:
vmImage: 'ubuntu-latest'
variables:
- group: loadfocus-variables # Variable group containing Key Vault references
stages:
- stage: Build
jobs:
- job: BuildAndTest
steps:
# Your existing build and test steps...
- stage: PerformanceTest
dependsOn: Build
condition: succeeded()
jobs:
- job: RunPerformanceTests
steps:
- task: NodeTool@0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- script: |
npm install -g @loadfocus/loadfocus-api-client
displayName: 'Install LoadFocus JMeter API Client'
- script: |
loadfocus-api config set apikey $(LOADFOCUS_API_KEY)
loadfocus-api config set teamid $(LOADFOCUS_TEAM_ID)
displayName: 'Configure LoadFocus API Client'
- script: |
loadfocus-api jmeter run-test \
--name "AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)" \
--thresholds "avgresponse<=200,errors==0,p95<=250" \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
displayName: 'Run Performance Tests'
continueOnError: false
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'performance-test-results'
displayName: 'Publish Performance Test Results'
- stage: Deploy
dependsOn: PerformanceTest
condition: succeeded()
jobs:
- job: DeployApplication
steps:
# Your deployment steps...

3. Postavljanje grupe varijabli s Key Vault integracijom

  1. Idite na Pipelines > Library > Variable Groups
  2. Kreirajte novu grupu varijabli pod nazivom "loadfocus-variables"
  3. Povežite je s vašim Azure Key Vault-om
  4. Dodajte sljedeće varijable, povezujući ih s vašim Key Vault tajnama:
    • LOADFOCUS_API_KEY: Povežite s tajnom loadfocus-api-key
    • LOADFOCUS_TEAM_ID: Povežite s tajnom loadfocus-team-id

Napredna konfiguracija

Korištenje YAML predložaka

Za višekratne korake testiranja performansi, kreirajte datoteku predloška performance-test-template.yml:

parameters:
testName: 'Default_Test'
thresholds: 'avgresponse<=200,errors==0,p95<=250'
waitTimeout: 1800
steps:
- script: |
loadfocus-api jmeter run-test \
--name "${{ parameters.testName }}" \
--thresholds "${{ parameters.thresholds }}" \
--waitTimeout ${{ parameters.waitTimeout }} \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
displayName: 'Run Performance Tests'
continueOnError: false

Zatim u vašem glavnom cjevovodu:

- template: performance-test-template.yml
parameters:
testName: 'AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)'
thresholds: 'avgresponse<=150,errors==0,p95<=200'
waitTimeout: 2400

Pokretanje više testova

Za pokretanje više testova performansi u nizu:

- script: |
# Run API test
loadfocus-api jmeter run-test \
--name "API_Test" \
--thresholds "avgresponse<=200,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/api_test_results.json
# Run UI test
loadfocus-api jmeter run-test \
--name "UI_Test" \
--thresholds "avgresponse<=500,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/ui_test_results.json
displayName: 'Run Multiple Performance Tests'

Integracija s Azure Test Plans

Za integraciju rezultata testova performansi s Azure Test Plans:

- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '$(Build.ArtifactStagingDirectory)/test-results.xml'
testRunTitle: 'Performance Tests'
displayName: 'Publish Test Results'
condition: succeededOrFailed()

Morat ćete pretvoriti JSON izlaz u JUnit format:

- script: |
# Run performance test
loadfocus-api jmeter run-test \
--name "AzureDevOps_Test" \
--thresholds "avgresponse<=200,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
# Convert JSON to JUnit format (using a custom script)
node convert-to-junit.js \
$(Build.ArtifactStagingDirectory)/performance_results.json \
$(Build.ArtifactStagingDirectory)/test-results.xml
displayName: 'Run Performance Tests and Convert Results'

Savjeti za Azure DevOps integraciju

  1. Paralelni poslovi: Ako imate više testova performansi, razmislite o korištenju paralelnih poslova:

    jobs:
    - job: API_Performance_Test
    steps:
    # Run API performance test
    - job: UI_Performance_Test
    steps:
    # Run UI performance test
  2. Vrata za postavljanje: Koristite rezultate testova performansi kao vrata za postavljanje:

    - job: DeploymentGate
    steps:
    - script: |
    # Check if performance tests passed
    if grep -q '"overallResult": "FAILED"' $(Build.ArtifactStagingDirectory)/performance_results.json; then
    echo "##vso[task.logissue type=error]Performance tests failed"
    echo "##vso[task.complete result=Failed;]"
    fi
  3. Prilagođena nadzorna ploča: Kreirajte prilagođenu nadzornu ploču za vizualizaciju rezultata testova performansi tijekom vremena.

  4. Obavijesti: Postavite obavijesti za neuspjehe testova performansi:

    - task: SendEmail@1
    inputs:
    to: 'team@example.com'
    subject: 'Performance Test Failed'
    body: 'Performance tests failed to meet thresholds. See attached results.'
    addAttachment: true
    attachmentPath: '$(Build.ArtifactStagingDirectory)/performance_results.json'
    condition: failed()

Za više informacija, pogledajte Azure DevOps dokumentaciju i LoadFocus API Client dokumentaciju.