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

[QA-52] - Push results to Grafana #2224

Merged
merged 25 commits into from
Sep 11, 2023
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
6 changes: 6 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ jobs:
env:
DISPLAY: :0.0

- name: Create env file
run: |
touch .env
echo ENV=${ENV} > .env
echo CYPRESS_BASE_URL='http://127.0.0.1:4173/' > .env

- name: Run Cypress Test
run: |+
#!/bin/bash
Expand Down
38 changes: 17 additions & 21 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
network: ['Ethereum', 'Arbitrum','Optimism', 'Avalanche', 'BNB']
network: ['Ethereum', 'Arbitrum', 'Optimism', 'Avalanche', 'BNB']
steps:
- name: Trigger Code Checkout
uses: actions/checkout@v3
Expand All @@ -30,9 +30,9 @@ jobs:

- name: Install linux deps
run: |
sudo apt-get install --no-install-recommends -y \
fluxbox \
xvfb
sudo apt-get install --no-install-recommends -y \
fluxbox \
xvfb

- name: Install cypress
run: yarn cypress install --force
Expand All @@ -43,31 +43,27 @@ jobs:
env:
DISPLAY: :0.0

- name: Create env file
run: |
touch .env
echo ENV=${ENV} > .env
echo GITHUB_RUN_ID=${GITHUB_RUN_ID} > .env
echo CORE_PUSH_GATEWAY_URL=${{ secrets.CORE_PUSH_GATEWAY_URL }} > .env
echo CYPRESS_BASE_URL='https://kyberswap.com/' > .env

- name: Run Cypress Test
run: |+
#!/bin/bash
yarn test-schedule -e grepTags=regression,NETWORK=${{ matrix.network }}
env:
DISPLAY: :0.0

- name: Notify on failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANEL: automation-test-bot
SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
SLACK_ICON: https://icon-library.com/images/star-wars-icon-png/star-wars-icon-png-16.jpg?size=48
SLACK_TITLE: E2E Test ${{inputs.BASE_URL}}
SLACK_USERNAME: autoBot
SLACK_LINK_NAMES: true
DISPLAY: :0.0

- name: Archive e2e artifacts
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
if: always()
with:
name: e2e-artifacts
path: |
cypress/videos
cypress/screenshots
name: e2e-artifacts
path: |
cypress/videos
cypress/screenshots
continue-on-error: true
126 changes: 125 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import synpressPlugins from '@synthetixio/synpress/plugins'
import { defineConfig } from 'cypress'
import client from 'prom-client'

require('dotenv').config()

export default defineConfig({
projectId: '4x4jf8',
component: {
devServer: {
framework: 'create-react-app',
Expand All @@ -22,7 +24,129 @@ export default defineConfig({
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@cypress/grep/src/plugin')(config)
synpressPlugins(on, config)
console.log('baseURL: ', process.env.CYPRESS_BASE_URL)
if (process.env.CYPRESS_BASE_URL === 'https://kyberswap.com/') {
on('after:run', async results => {
if (results) {
const register = new client.Registry()
const prefix = 'e2e_cypress'
const suite = new client.Counter({
name: `${prefix}_suite`,
help: `${prefix}_suite`,
labelNames: ['buildId', 'result', 'baseName', 'duration', 'chain'] as const,
})
suite.reset()
const { totalPassed, totalFailed, totalTests, totalDuration, runs } = results
runs.forEach(run => {
const { stats, spec } = run
const { tests, passes, pending, failures, duration } = stats
const { baseName } = spec
suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'failed',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(failures)

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'passed',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(passes)

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'pending',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(pending)
suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'tests',
baseName: baseName,
duration: duration,
chain: config.env.NETWORK,
})
.inc(tests)
})

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'passed',
baseName: 'All Specs',
duration: totalDuration,
chain: config.env.NETWORK,
})
.inc(totalPassed)

suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'failed',
baseName: 'All Specs',
duration: totalDuration,
chain: config.env.NETWORK,
})
.inc(totalFailed)
suite
.labels({
buildId: `${process.env.GITHUB_RUN_ID}`,
result: 'total',
baseName: 'All Specs',
duration: totalDuration,
chain: config.env.NETWORK,
})
.inc(totalTests)

const testPass = new client.Counter({
name: `${prefix}_test_passed`,
help: `${prefix}_pass`,
labelNames: ['buildId', 'chain'] as const,
})

const testFail = new client.Counter({
name: `${prefix}_test_failed`,
help: `${prefix}_fail`,
labelNames: ['buildId', 'chain'] as const,
})

testPass.reset()
testFail.reset()

testFail.labels({ buildId: `${process.env.GITHUB_RUN_ID}`, chain: config.env.NETWORK }).inc(totalFailed)
testPass.labels({ buildId: `${process.env.GITHUB_RUN_ID}`, chain: config.env.NETWORK }).inc(totalPassed)

register.registerMetric(testPass)
register.registerMetric(testFail)
register.registerMetric(suite)

const gateway = new client.Pushgateway(`${process.env.CORE_PUSH_GATEWAY_URL}`, [], register)
await gateway
.push({ jobName: 'ui-automation' })
.then(({ resp, body }) => {
console.log(`Body: ${body}`)
console.log(`Response status: ${resp}`)
})
.catch((err: any) => {
console.log('err: ', err)
})
}
})
}
},
baseUrl: process.env.CYPRESS_BASE_URL,
specPattern: 'cypress/e2e/specs/*.e2e.cy.ts',
},
})
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"start-dev": "vite --mode dev --host",
"start-stg": "vite --mode stg --host",
"start-prod": "vite --mode production --host",
"test-e2e": "synpress run -cf cypress.config.ts -c baseUrl=http://127.0.0.1:4173/",
"test-schedule": "synpress run -cf cypress.config.ts -c baseUrl=https://kyberswap.com/"
"test-e2e": "synpress run -cf cypress.config.ts",
"test-schedule": "synpress run -cf cypress.config.ts"
},
"browserslist": [
"chrome >= 52",
Expand Down Expand Up @@ -149,7 +149,7 @@
"@cypress/grep": "^3.1.5",
"@lingui/cli": "~3.14.0",
"@lingui/vite-plugin": "~3.16.1",
"@synthetixio/synpress": "^3.7.0",
"@synthetixio/synpress": "^3.7.2-beta.7",
"@trivago/prettier-plugin-sort-imports": "^3.3.1",
"@types/aos": "^3.0.4",
"@types/big.js": "^6.0.0",
Expand Down Expand Up @@ -190,6 +190,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-unused-imports": "^2.0.0",
"prettier": "^2.7.1",
"prom-client": "^14.2.0",
"ts-node": "^10.9.1",
"typescript": "4.8.4",
"vite": "^4.3.9",
Expand All @@ -205,4 +206,4 @@
"@lingui/core": "3.14.0",
"@lingui/conf": "3.16.0"
}
}
}
Loading
Loading