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

CLI option --format=json should change the STDERR logging to output JSON structured logging #421

Merged
merged 3 commits into from
Jul 28, 2022
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
40 changes: 16 additions & 24 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ variables:
GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}"
GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git"
# Cache .npm
NPM_CONFIG_CACHE: "${CI_PROJECT_DIR}/tmp/npm"
npm_config_cache: "${CI_PROJECT_DIR}/tmp/npm"
# Prefer offline node module installation
NPM_CONFIG_PREFER_OFFLINE: "true"
npm_config_prefer_offline: "true"
# Homebrew cache only used by macos runner
HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew"

Expand Down Expand Up @@ -50,7 +50,7 @@ check:lint:
needs: []
script:
- >
nix-shell --run '
nix-shell --arg ci true --run $'
npm run lint;
npm run lint-shell;
'
Expand Down Expand Up @@ -82,8 +82,8 @@ check:test-generate:
needs: []
script:
- >
nix-shell --run '
./scripts/check-test-generate.sh > ./tmp/check-test.yml
nix-shell --arg ci true --run $'
./scripts/check-test-generate.sh > ./tmp/check-test.yml;
'
artifacts:
when: always
Expand Down Expand Up @@ -124,7 +124,7 @@ build:merge:
# Required for `gh pr create`
- git remote add upstream "$GH_PROJECT_URL"
- >
nix-shell --run '
nix-shell --arg ci true --run $'
gh pr create \
--head staging \
--base master \
Expand All @@ -149,7 +149,7 @@ build:dist:
needs: []
script:
- >
nix-shell --run '
nix-shell --arg ci true --run $'
npm run build --verbose;
'
artifacts:
Expand All @@ -167,8 +167,8 @@ build:platforms-generate:
needs: []
script:
- >
nix-shell --run '
./scripts/build-platforms-generate.sh > ./tmp/build-platforms.yml
nix-shell --arg ci true --run $'
./scripts/build-platforms-generate.sh > ./tmp/build-platforms.yml;
'
artifacts:
when: always
Expand Down Expand Up @@ -210,7 +210,7 @@ build:prerelease:
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
- echo 'Publishing library prerelease'
- >
nix-shell --run '
nix-shell --arg ci true --run $'
npm publish --tag prerelease --access public;
'
after_script:
Expand Down Expand Up @@ -425,10 +425,7 @@ integration:prerelease:
script:
- echo 'Publishing application prerelease'
- >
nix-shell --run $'
set -o errexit;
set -o nounset;
set -o pipefail;
nix-shell --arg ci true --run $'
if gh release view "$CI_COMMIT_TAG" --repo "$GH_PROJECT_PATH" >/dev/null; then \
gh release \
upload "$CI_COMMIT_TAG" \
Expand Down Expand Up @@ -456,10 +453,7 @@ integration:prerelease:
'
- echo 'Prereleasing container image'
- >
nix-shell --run $'
set -o errexit;
set -o nounset;
set -o pipefail;
nix-shell --arg ci true --run $'
skopeo login \
--username "$CI_REGISTRY_USER" \
--password "$CI_REGISTRY_PASSWORD" \
Expand All @@ -481,8 +475,6 @@ integration:merge:
stage: integration
needs:
- build:merge
- job: build:dist
optional: true
- job: build:platforms
optional: true
- job: integration:nix
Expand All @@ -505,7 +497,7 @@ integration:merge:
GIT_DEPTH: 0
script:
- >
nix-shell --run '
nix-shell --arg ci true --run $'
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
| gh pr comment staging \
--body-file - \
Expand Down Expand Up @@ -624,12 +616,12 @@ release:distribution:
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
- echo 'Publishing library'
- >
nix-shell --run $'
nix-shell --arg ci true --run $'
npm publish --access public;
'
- echo 'Releasing application builds'
- >
nix-shell --run $'
nix-shell --arg ci true --run $'
gh release \
CMCDragonkai marked this conversation as resolved.
Show resolved Hide resolved
create "$CI_COMMIT_TAG" \
builds/*.closure.gz \
Expand All @@ -644,7 +636,7 @@ release:distribution:
'
- echo 'Releasing container image'
- >
nix-shell --run $'
nix-shell --arg ci true --run $'
skopeo login \
--username "$CI_REGISTRY_USER" \
--password "$CI_REGISTRY_PASSWORD" \
Expand Down
21 changes: 5 additions & 16 deletions benches/gitgc.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import path from 'path';
import b from 'benny';
import packageJson from '../package.json';
import { suiteCommon } from './utils';

async function main () {
let map = new Map();
let obj = {};
let arr = [];
let arr: any = [];
let set = new Set();
const summary = await b.suite(
'gitgc',
path.basename(__filename, path.extname(__filename)),
b.add('map', async () => {
map = new Map();
return async () => {
Expand Down Expand Up @@ -78,19 +79,7 @@ async function main () {
}
};
}),
b.cycle(),
b.complete(),
b.save({
file: 'gitgc',
folder: 'benches/results',
version: packageJson.version,
details: true,
}),
b.save({
file: 'gitgc',
folder: 'benches/results',
format: 'chart.html',
}),
...suiteCommon,
);
return summary;
}
Expand Down
27 changes: 25 additions & 2 deletions benches/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
#!/usr/bin/env node
#!/usr/bin/env ts-node

import fs from 'fs';
import path from 'path';
import si from 'systeminformation';
import gitgc from './gitgc';

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
await gitgc();
const resultFilenames = await fs.promises.readdir(
path.join(__dirname, 'results'),
);
const metricsFile = await fs.promises.open(
path.join(__dirname, 'results', 'metrics.txt'),
'w',
);
let concatenating = false;
for (const resultFilename of resultFilenames) {
if (/.+_metrics\.txt$/.test(resultFilename)) {
const metricsData = await fs.promises.readFile(
path.join(__dirname, 'results', resultFilename),
);
if (concatenating) {
await metricsFile.write('\n');
}
await metricsFile.write(metricsData);
concatenating = true;
}
}
await metricsFile.close();
const systemData = await si.get({
cpu: '*',
osInfo: 'platform, distro, release, kernel, arch',
system: 'model, manufacturer',
});
await fs.promises.writeFile(
'benches/results/system.json',
path.join(__dirname, 'results', 'system.json'),
JSON.stringify(systemData, null, 2),
);
}
Expand Down
1 change: 1 addition & 0 deletions benches/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './utils';
61 changes: 61 additions & 0 deletions benches/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import fs from 'fs';
import path from 'path';
import b from 'benny';
import { codeBlock } from 'common-tags';
import packageJson from '../../package.json';

const suiteCommon = [
b.cycle(),
b.complete(),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
version: packageJson.version,
details: true,
}),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
version: packageJson.version,
format: 'chart.html',
}),
b.complete((summary) => {
const filePath = path.join(
__dirname,
'../results',
summary.name + '_metrics.txt',
);
fs.writeFileSync(
filePath,
codeBlock`
# TYPE ${summary.name}_ops gauge
${summary.results
.map(
(result) =>
`${summary.name}_ops{name="${result.name}"} ${result.ops}`,
)
.join('\n')}

# TYPE ${summary.name}_margin gauge
${summary.results
.map(
(result) =>
`${summary.name}_margin{name="${result.name}"} ${result.margin}`,
)
.join('\n')}

# TYPE ${summary.name}_samples counter
${summary.results
.map(
(result) =>
`${summary.name}_samples{name="${result.name}"} ${result.samples}`,
)
.join('\n')}
` + '\n',
);
// eslint-disable-next-line no-console
console.log('\nSaved to:', path.resolve(filePath));
}),
];

export { suiteCommon };
Loading