Skip to content

QA-7806 created hourly spawned user test for BHA Search and Admit Client #398

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
311 changes: 311 additions & 0 deletions .github/workflows/locust-hourly-admit-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Hourly Admit Client Load test

on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to run tests against'
required: true
default: 'production'
type: choice
options:
- production
jobs:
set_matrix:
runs-on: ubuntu-latest
if: ${{ !(github.event_name == 'repository_dispatch' && github.event.client_payload.environment == 'staging') }}
outputs:
matrix: ${{ steps.set-matrix-schedule.outputs.matrix || steps.set-matrix-deploy.outputs.matrix || steps.set-matrix-manual.outputs.matrix || steps.set-matrix-default.outputs.matrix }}
steps:
- id: set-matrix-manual
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "::set-output name=matrix::{\"environment\":[\"${{ inputs.environment }}\"]}"
- id: set-matrix-default
if: ${{ github.event_name != 'repository_dispatch' }}
run: |
echo "::set-output name=matrix::{\"environment\": [\"production\"]}"
- id: invalid-deploy
if: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.environment != 'production' }}
run: |
echo "Invalid environment: ${{ github.event.client_payload.environment }}"
exit 1

build:
needs: set_matrix
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.set_matrix.outputs.matrix) }}
concurrency:
group: ${{ github.workflow }}-${{ matrix.environment }}
cancel-in-progress: true
name: LoadTest on '${{ matrix.environment }}'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.13
uses: actions/setup-python@v2
with:
python-version: 3.13

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r LocustScripts/requirements.txt

- name: Hourly Admit Client Load test with Locust
env:
DIMAGIQA_ENV: ${{ matrix.environment }} #${{ secrets.DIMAGIQA_URL }}
DIMAGIQA_LOCUST_PASSWORD: ${{ secrets.DIMAGIQA_LOCUST_PASSWORD }}
DIMAGIQA_MAIL_USERNAME: ${{ secrets.DIMAGIQA_MAIL_USERNAME }}
DIMAGIQA_MAIL_PASSWORD: ${{ secrets.DIMAGIQA_MAIL_PASSWORD }}
run: |
echo "client_payload: ${{ toJson(github.event.client_payload) }}"
echo "matrix environment: ${{ matrix.environment }}"
echo "NOW=$(date +'%m-%d %H:%M')" >> $GITHUB_ENV
echo ${{env.NOW}}
python LocustScripts/update-scripts/run_24hr_locust_schedule.py \
--locust-file LocustScripts/update-scripts/commcarehq-hourly-search-and-admit-mw-login.py \
--users-json LocustScripts/update-scripts/project-config/co-carecoordination-perf/mobile_worker_credentials_search_admit_hourly.json \
--app-config LocustScripts/update-scripts/project-config/co-carecoordination-perf/app_config_automated_cr_admit_client.json \
--host https://www.commcarehq.org \
--domain co-carecoordination-perf \
--app-id 77bbaaa1d7e5404781bbe680ce9a90d2 \
--build-id 2ae6dcfc44834e40a703155ebedd3bec

- name: Archive test results
id: artifact-upload-step
if: ${{ success() || failure() }}
uses: actions/upload-artifact@v4
with:
name: hourly-locust-reports-*
path: /home/runner/work/dimagi-qa/dimagi-qa/hour_*.html
retention-days: 2

- name: Fetch artifact ID
run: echo 'Artifact ID is ${{ steps.artifact-upload-step.outputs.artifact-id }}'


- name: Set email vars
if: ${{ failure() }}
id: configure_email
uses: actions/github-script@v6
env:
JOB_STATUS: ${{ job.status }}
CC_ENV: ${{ matrix.environment }}
with:
script: |
const { promises: fs } = require('fs')

const {JOB_STATUS, NOW, CC_ENV, GITHUB_HEAD_REF} = process.env
const prefix = `[${CC_ENV}] Admit Client Locust Tests - ${JOB_STATUS.toUpperCase()} - Run #${context.runNumber}`
const suffix = `at ${NOW}`

let subject = `${prefix} on "deploy_success" ${suffix}`
if (context.eventName !== "repository_dispatch") {
subject = `${prefix} on branch "${GITHUB_HEAD_REF}" ${suffix}`
}

let bodyFile = './common_utilities/mail_templates/email_pass.md'
if (JOB_STATUS !== 'success') {
bodyFile = './common_utilities/mail_templates/email_fail.md'
}

let actionRunLink = context.payload.repository.html_url + `/actions/runs/${context.runId}`
let testSuite = 'BHA Admit Client Hourle Load Tests'
let bodyContent = await fs.readFile(bodyFile, 'utf8')
bodyContent = bodyContent.replace(/{{actionRunLink}}/g, actionRunLink)
.replace(/{{runNumber}}/g, context.runNumber)
.replace(/{{environment}}/g, CC_ENV)
.replace(/{{testSuite}}/g, testSuite)

let receivers = 'qa-automation@dimagi.com'
if (context.eventName !== "pull_request" || context.eventName !== "push") {
receivers = 'kbordoloi@dimagi.com'
}

return {
"subject": subject,
"body": bodyContent,
"reference": Math.random().toString(36).substr(2), // used to prevent threading of similar emails
"receivers": receivers
}

- name: Send Result Email
if: ${{ failure() }}
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{secrets.DIMAGIQA_MAIL_USERNAME}}
password: ${{secrets.DIMAGIQA_MAIL_PASSWORD}}
subject: ${{ fromJSON(steps.configure_email.outputs.result).subject }}
to: ${{ fromJSON(steps.configure_email.outputs.result).receivers }}
from: <${{secrets.DIMAGIQA_MAIL_USERNAME}}>
html_body: ${{ fromJSON(steps.configure_email.outputs.result).body }}
convert_markdown: true
attachments: ${{ github.workspace }}/hour_*.html
in_reply_to: ${{ fromJSON(steps.configure_email.outputs.result).reference }}

- name: Set slack vars
if: ${{ always() }}
id: configure_slack
uses: actions/github-script@v6
env:
JOB_STATUS: ${{ job.status }}
CC_ENV: ${{ matrix.environment }}
CC_EVENT: ${{ github.event_name }}
with:
result-encoding: string
script: |
const {CC_ENV, JOB_STATUS, CC_EVENT} = process.env
let SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_SMOKE }}'
if (CC_EVENT == 'repository_dispatch' && CC_ENV == 'production') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_PROD_RESULTS }}'
console.log( "Prod deploy")
} else if (CC_EVENT != 'repository_dispatch' && CC_ENV == 'production' && JOB_STATUS == 'failure') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_SMOKE }}'
console.log( "Not Prod deploy but Prof failure")
} else if (CC_ENV == 'staging' && JOB_STATUS == 'failure') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_SMOKE }}'
console.log("Staging Failure")
} else if (CC_EVENT == 'repository_dispatch' && CC_ENV == 'india') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_INDIA }}'
console.log("India Failure")
} else if (CC_EVENT != 'repository_dispatch' && CC_ENV == 'india' && JOB_STATUS == 'failure') {
SLACK_WEBHOOK_URL = '${{ secrets.SLACK_WEBHOOK_URL_SMOKE }}'
console.log("India Success")
} else {
SLACK_WEBHOOK_URL = ' '
console.log("No notification sent")
}

return SLACK_WEBHOOK_URL

- name: Post to Slack channel on Failure
id: slack_fail
uses: slackapi/slack-github-action@v1.23.0
if: ${{ steps.configure_slack.outputs.result != ' ' && failure() }}
with:
payload: |
{
"attachments": [
{
"color": "#FF0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": " Bonjour :alphabet-yellow-q::alphabet-yellow-a: 👋 \n*${{ github.workflow }}* were just triggered!\n"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Environment: *\n ${{ matrix.environment }} \n"
},
{
"type": "mrkdwn",
"text": " "
},
{
"type": "mrkdwn",
"text": "*Status: *\n ${{ job.status }} :x:"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Here's the corresponding report :arrow_right::arrow_right:"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click to Downlaod",
"emoji": true
},
"value": "click_me_123",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}",
"action_id": "button-action",
"style": "danger"
}
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ steps.configure_slack.outputs.result }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

- name: Post to Slack channel on Success
id: slack_pass
uses: slackapi/slack-github-action@v1.23.0
if: ${{ steps.configure_slack.outputs.result != ' ' && success() }}
with:
payload: |
{
"attachments": [
{
"color": "#36a64f",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": " Bonjour :alphabet-yellow-q::alphabet-yellow-a: 👋 \n*${{ github.workflow }}* were just triggered!\n"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Environment: *\n ${{ matrix.environment }} \n"
},
{
"type": "mrkdwn",
"text": " "
},
{
"type": "mrkdwn",
"text": "*Status: *\n ${{ job.status }} :white_check_mark:"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Here's the corresponding report :arrow_right::arrow_right:"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click to Download",
"emoji": true
},
"value": "click_me_123",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}",
"action_id": "button-action",
"style": "primary"
}
}
]
}
]
}

env:
SLACK_WEBHOOK_URL: ${{ steps.configure_slack.outputs.result }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
Loading
Loading