Skip to content

Commit

Permalink
fix: add total perf metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
SkReD committed Nov 14, 2022
1 parent 173b0ee commit 0d800c3
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 9 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
docs:
runs-on: ubuntu-latest
container: mshipov/plantuml:1.0.4
needs: update
needs:
- update
- perf-test
permissions:
contents: read
pages: write
Expand All @@ -40,8 +42,28 @@ jobs:
- uses: ./.github/actions/build-docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@master
with:
name: metrics
path: website/build
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./website/build
force_orphan: true

perf-test:
runs-on: ubuntu-latest
concurrency:
group: docs
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: ./.github/actions/setup
- run: npm run build
- run: node scripts/perf/run.js
- uses: actions/upload-artifact@master
with:
name: metrics
path: public/
13 changes: 13 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ jobs:
name: docs
path: ./website/build

perf-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: ./.github/actions/setup
- run: npm run build
- run: node scripts/perf/run.js --historyLength 2
- run: node scripts/perf/create-report-comment.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test:
runs-on: ubuntu-latest
steps:
Expand Down
26 changes: 24 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ jobs:
docs:
runs-on: ubuntu-latest
container: mshipov/plantuml:1.0.4
needs: release
needs:
- release
- perf-test
permissions:
contents: write
concurrency:
Expand All @@ -46,8 +48,28 @@ jobs:
- uses: ./.github/actions/build-docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@master
with:
name: metrics
path: website/build
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./website/build
force_orphan: true

perf-test:
runs-on: ubuntu-latest
concurrency:
group: docs
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: ./.github/actions/setup
- run: npm run build
- run: node scripts/perf/run.js
- uses: actions/upload-artifact@master
with:
name: metrics
path: public/
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"typescript-json-schema": "^0.51.0",
"unified": "^10.1.2",
"verdaccio": "^5.1.6",
"get-port": "^5.1.1"
"get-port": "^5.1.1",
"handlebars": "^4.7.7",
"yargs": "^15.4.1"
}
}
2 changes: 0 additions & 2 deletions packages/pvm-artifacts/lib/storage-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ export class StorageManager {
case ArtifactsStorages.ReleaseList: {
const result = await this.init(ReleaseListStorage, config.release_list.storage)
logger.info(`Initialized ${result.name} storage for ReleaseList artifact`)
// @ts-ignore не очень понятно почему ts не разрешает вернуть ReleaseListStorage здесь
return result
}
case ArtifactsStorages.Changelogs: {
const result = await this.init(ChangelogsStorage, config.changelog.storage)
logger.info(`Initialized ${result.name} storage for Changelogs artifact`)
// @ts-ignore
return result
}
default:
Expand Down
16 changes: 16 additions & 0 deletions scripts/perf/create-report-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { Pvm } = require('@pvm/pvm')
const { PLATFORM_TOKEN } = require('@pvm/tokens-core')
const fs = require('fs')

async function main() {
const pvmApp = new Pvm()
const githubPlatform = pvmApp.container.get(PLATFORM_TOKEN)

await githubPlatform.beginMrAttribution()
await githubPlatform.syncText('performance-report', fs.readFileSync('public/metrics-table.html', 'utf-8'))
}

main().catch(e => {
process.exitCode = 1
console.error(e)
})
13 changes: 13 additions & 0 deletions scripts/perf/report.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<body>
<br>
<h2>PVM commands performance</h2>
<p>Test performed in github actions runner on ubuntu image. Specs can be found <a
href="https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources">here</a>.
</p>
<br>
{{> table }}
</body>
118 changes: 118 additions & 0 deletions scripts/perf/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const got = require('got')
const fs = require('fs-extra')
const path = require('path')
const Handlebars = require('handlebars')
const initRepo = require('../../test/initRepo')
const { writeRepo } = require('../../test/writeRepo')
const { start, stop } = require('../../test/gl-api-mock')
const yargs = require('yargs')

const args = yargs
.option('historyLength', {
type: 'number',
description: 'How much history to include in result',
default: -1,
})
.argv

const TEST_COMMANDS = [
'pkgset -s all',
'pkgset -s affected',
'update --dry-run',
'publish --dry-run',
]
const COMMITS_COUNT = 10
const RELEASES_COUNT = 3
const PACKAGES_COUNT = 200
const RUNS_COUNT = 4

async function collectPerfMetrics(gitlabApp) {
const versions = Array(PACKAGES_COUNT).fill(0).map((v, i) => `src/a${i}@0.0.0-stub`)
const repo = await initRepo(writeRepo({
name: 'manyPackagesPerf',
private: true,
spec: versions.join(','),
}), {
versioning: {
source: 'tag',
},
})

const releasesStep = Math.floor(COMMITS_COUNT / RELEASES_COUNT)
for (let i = 0; i < COMMITS_COUNT; i++) {
await repo.runScript(`echo "content ${i}" > src/a1/trigger.txt`)
await repo.runScript(`git add src/a1/trigger.txt`)
await repo.runScript(`git commit -a -m "Commit ${i}"`)
if (i % releasesStep === 0) {
await repo.annotatedTag(`release-${i}`, `---
${versions.map(p => p.split('/')[1]).join('\n')}`)
}
}

const result = {
releaseLink: `<a href="${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/releases/tag/${process.env.GITHUB_REF_NAME}">${process.env.GITHUB_REF_NAME}</a>`,
timestamp: new Date().toUTCString(),
packagesCount: PACKAGES_COUNT,
releasesCount: RELEASES_COUNT,
commitsCount: COMMITS_COUNT,
commands: {},
}
for (const cmd of TEST_COMMANDS) {
const runs = []
for (let i = 0; i < RUNS_COUNT; i++) {
const time = process.hrtime.bigint()
await repo.execScript(`pvm ${cmd}`, {
env: {
...process.env,
PVM_CONFIG_JIRA__URL: 'https://jira.example.com',
PVM_TEST_DATE_NOW: '2018-11-27T12:00:00.000Z',
CI_PROJECT_NAMESPACE: 'pfp',
CI_PROJECT_NAME: 'test-p',
CI_PROJECT_ID: 111,
GL_TOKEN: '___gl___',
PVM_TESTING_ENV: process.env.PVM_TESTING_ENV ?? 'true',
NPM_TOKEN: '123',
PVM_CONFIG_PLUGINS_V2: JSON.stringify([{ plugin: require.resolve('@pvm/gitlab/plugin') }]),
PVM_CONFIG_GITLAB__URL: `http://localhost:${gitlabApp.httpServer.address().port}`,
},
})
const timeEnd = process.hrtime.bigint()
runs.push(Number(Number(timeEnd - time) / 1e9))
}

result.commands[cmd] = (runs.reduce((s, r) => s + r, 0) / RUNS_COUNT).toFixed(3)
}

return result
}

async function main() {
let currentMetrics
const gitlabApp = await start()

try {
currentMetrics = await collectPerfMetrics(gitlabApp)
} finally {
await stop()
}

let metrics = JSON.parse((await got.get('https://tinkoff.github.io/pvm/metrics.json')).body ?? '[]')
if (args.historyLength !== -1) {
metrics = metrics.slice(0, args.historyLength)
}
metrics.unshift(currentMetrics)
fs.outputFileSync('public/metrics.json', JSON.stringify(metrics), 'utf-8')

const tableTempl = fs.readFileSync(path.join(__dirname, 'table.hbs'), 'utf-8')
Handlebars.registerPartial('table', tableTempl)
const table = Handlebars.compile(tableTempl)
const report = Handlebars.compile(fs.readFileSync(path.join(__dirname, 'report.hbs'), 'utf-8'))
fs.outputFileSync('public/metrics.html', report(metrics), 'utf-8')
fs.outputFileSync('public/metrics-table.html', table(metrics), 'utf-8')
console.log(`\nResult metrics:\n\n${JSON.stringify(metrics, null, 2)}`)
}

main().catch(e => {
process.exitCode = 1
console.log(e)
})
32 changes: 32 additions & 0 deletions scripts/perf/table.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Timestamp</th>
<th scope="col">Release</th>
<th scope="col">Packages</th>
<th scope="col">Releases</th>
<th scope="col">Commits</th>
<th scope="col">pkgset -s all</th>
<th scope="col">pkgset -s affected</th>
<th scope="col">update --dry-run</th>
<th scope="col">publish --dry-run</th>
</tr>
</thead>
<tbody>
{{#each this}}
<tr>
<td>{{timestamp}}</td>
<td>{{{releaseLink}}}</td>
<td>{{packagesCount}}</td>
<td>{{releasesCount}}</td>
<td>{{commitsCount}}</td>
{{#with commands}}
<td>{{[pkgset -s all]}} s</td>
<td>{{[pkgset -s affected]}} s</td>
<td>{{[update --dry-run]}} s</td>
<td>{{[publish --dry-run]}} s</td>
{{/with}}
</tr>
{{/each}}
</tbody>
</table>
2 changes: 0 additions & 2 deletions test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ global.writeRepo = writeRepo

Object.assign(process.env, {
PVM_CONFIG_SEARCH_FROM: __dirname,
__PVM_ENABLE_INVALIDATE_RELEASES_BUT_IT_MAY_RESULT_IN_A_DENIAL_OF_SERVICE: 'true',
PVM_CONFIG_JIRA__URL: 'https://jira.example.com',
PVM_TEST_DATE_NOW: '2018-11-27T12:00:00.000Z',
// SLACK_WEBHOOK: `http://localhost:${process.env.GITLAB_HTTP_PORT}/slack-hook/`,
CI_PROJECT_NAMESPACE: 'pfp',
CI_PROJECT_NAME: 'test-p',
CI_PROJECT_ID: 111,
Expand Down

0 comments on commit 0d800c3

Please sign in to comment.