-
Notifications
You must be signed in to change notification settings - Fork 40
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
DevSecOps : Adopt/Deploy Load-Testing Framework #17005
Comments
Select the Appropriate Load Testing FrameworkGoal: Identify and adopt a load testing framework that aligns with the system requirements and DevSecOps practices. Tasks:
|
Set Up the Load Testing FrameworkGoal: Install and configure the chosen framework for the test environment. Tasks:
|
Develop Load Testing ScriptsGoal: Write reusable and parameterized scripts for simulating production-like workloads. Tasks:
|
Automate Load Testing in CI/CDGoal: Integrate the load testing framework into CI/CD pipelines for continuous validation. Tasks:
|
Validate and Optimize the FrameworkGoal: Test the framework's effectiveness and refine it for long-term use. Tasks:
|
Detailed GitHub Actions Workflow for Load TestingBelow is a GitHub Actions workflow to automate load testing with K6. It can be customized for other tools like Apache JMeter or Locust. Workflow Example: Load Testing with K6name: Load Testing Workflow
on:
push:
branches:
- main
jobs:
load-test:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout Code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Install K6
- name: Install K6
run: sudo apt-get update && sudo apt-get install -y k6
# Step 3: Run K6 Load Test
- name: Run K6 Load Test
run: |
k6 run --vus 100 --duration 5m tests/load_test.js
# Step 4: Upload Test Results
- name: Upload Test Results
uses: actions/upload-artifact@v3
with:
name: k6-results
path: ./k6-results.json
# Step 5: Generate Load Test Report (Optional)
- name: Generate HTML Report
run: k6 run --out json=k6-results.json tests/load_test.js && k6 report --out=html=k6-report.html
# Step 6: Upload HTML Report
- name: Upload HTML Report
uses: actions/upload-artifact@v3
with:
name: k6-html-report
path: ./k6-report.html Key Points:
|
Sample Load Testing ScriptsA. API Load Testing Script (K6)import http from 'k6/http';
import { sleep } from 'k6';
export let options = {
stages: [
{ duration: '1m', target: 10 }, // Ramp up to 10 users
{ duration: '3m', target: 50 }, // Maintain 50 users
{ duration: '1m', target: 0 }, // Ramp down to 0 users
],
thresholds: {
http_req_duration: ['p(95)<500'], // 95% of requests must complete below 500ms
http_req_failed: ['rate<0.01'], // Error rate should be less than 1%
},
};
export default function () {
http.get('https://your-api-endpoint.com/data');
sleep(1);
} |
B. Batch Processing Load Testing Script (K6)import http from 'k6/http';
import { sleep } from 'k6';
export let options = {
stages: [
{ duration: '2m', target: 20 }, // Ramp up to 20 users
{ duration: '5m', target: 100 }, // Maintain 100 users
{ duration: '2m', target: 0 }, // Ramp down to 0 users
],
};
export default function () {
const payload = JSON.stringify({
batchId: `batch-${__VU}-${__ITER}`, // Unique batch ID
data: Array.from({ length: 2500 }, (_, i) => i + 1), // Simulate 2.5k batch size
});
const params = {
headers: {
'Content-Type': 'application/json',
},
};
http.post('https://your-api-endpoint.com/process-batch', payload, params);
sleep(1);
} |
C. Concurrency Load Testing Script (K6)import http from 'k6/http';
import { sleep } from 'k6';
export let options = {
vus: 50, // Simulate 50 virtual users concurrently
duration: '10m', // Run test for 10 minutes
};
export default function () {
const payload = JSON.stringify({
batchId: `batch-${__VU}-${__ITER}`, // Unique batch ID
data: Array.from({ length: 1000 }, (_, i) => i + 1), // Simulate 1k batch size
});
const params = {
headers: {
'Content-Type': 'application/json',
},
};
http.post('https://your-api-endpoint.com/process-batch', payload, params);
sleep(Math.random() * 2); // Random wait between requests
} |
Monitoring Integration with Azure MonitorA. Monitor Load Testing MetricsUse Azure Monitor and Application Insights to collect performance metrics during load tests. Metrics to Monitor:
|
B. KQL Queries for Azure Monitor
|
Visualizing Results with Azure WorkbooksDashboard Ideas
Creating Azure Workbook
|
Templates for Azure Workbook DashboardsBelow are detailed dashboard ideas and queries you can use in Azure Workbooks to visualize load testing results. A. Latency and Throughput Trends
|
B. Error Rate Analysis
|
C. Resource Utilization Dashboard
|
D. Workbook Setup
|
Complex Load Testing ScriptsA. Simulating Variable Traffic PatternsThis script simulates a mix of GET and POST requests with randomized traffic patterns. import http from 'k6/http';
import { sleep, check } from 'k6';
export let options = {
scenarios: {
steady_traffic: {
executor: 'constant-vus',
vus: 50,
duration: '10m',
},
spike_traffic: {
executor: 'ramping-vus',
startVUs: 10,
stages: [
{ duration: '1m', target: 100 }, // Ramp up to 100 users
{ duration: '5m', target: 100 }, // Hold at 100 users
{ duration: '2m', target: 0 }, // Ramp down
],
},
},
thresholds: {
http_req_duration: ['p(95)<400'], // 95% of requests must complete below 400ms
},
};
export default function () {
const urls = ['https://your-api-endpoint.com/data', 'https://your-api-endpoint.com/process'];
const payload = JSON.stringify({ key: 'value' });
const res = Math.random() > 0.5
? http.get(urls[0])
: http.post(urls[1], payload, { headers: { 'Content-Type': 'application/json' } });
check(res, {
'status was 200': (r) => r.status === 200,
});
sleep(Math.random() * 2);
} |
B. Stress Testing with Large Batch SizesThis script pushes the system to handle increasingly large batch sizes. import http from 'k6/http';
import { sleep } from 'k6';
export let options = {
stages: [
{ duration: '2m', target: 50 }, // Ramp up to 50 users
{ duration: '5m', target: 200 }, // Maintain 200 users
{ duration: '1m', target: 0 }, // Ramp down
],
};
export default function () {
const payload = JSON.stringify({
batchId: `batch-${__VU}-${__ITER}`,
data: Array.from({ length: __ITER * 100 }, (_, i) => i + 1),
});
const params = {
headers: { 'Content-Type': 'application/json' },
};
const res = http.post('https://your-api-endpoint.com/process-batch', payload, params);
sleep(1);
} |
Automating Test Result ReportingA. GitHub Actions IntegrationAdd a reporting step in your GitHub Actions workflow to upload results. # Workflow snippet for reporting
- name: Generate HTML Report
run: |
k6 run --out json=k6-results.json tests/load_test.js
k6 report --out=html=k6-report.html
- name: Upload Report
uses: actions/upload-artifact@v3
with:
name: k6-html-report
path: ./k6-report.html |
B. Post-Test Azure Monitor IntegrationSend results from test scripts to Azure Monitor for centralized visualization.
|
C. Visualization Using Power BI
|
Objective:
Implement a robust load testing framework to simulate production-level traffic, measure system performance under various loads, and identify bottlenecks. The framework will support testing batch processing, APIs, and overall system scalability.
Deliverables
Integration With Existing Sections
The text was updated successfully, but these errors were encountered: