Skip to content

Commit 21aca8a

Browse files
authored
Merge pull request #421 from MatrixAI/feature-json-logger
CLI option `--format=json` should change the STDERR logging to output JSON structured logging
2 parents 4117a04 + dca4cca commit 21aca8a

File tree

82 files changed

+1129
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1129
-218
lines changed

.gitlab-ci.yml

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ variables:
1010
GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}"
1111
GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git"
1212
# Cache .npm
13-
NPM_CONFIG_CACHE: "${CI_PROJECT_DIR}/tmp/npm"
13+
npm_config_cache: "${CI_PROJECT_DIR}/tmp/npm"
1414
# Prefer offline node module installation
15-
NPM_CONFIG_PREFER_OFFLINE: "true"
15+
npm_config_prefer_offline: "true"
1616
# Homebrew cache only used by macos runner
1717
HOMEBREW_CACHE: "${CI_PROJECT_DIR}/tmp/Homebrew"
1818

@@ -50,7 +50,7 @@ check:lint:
5050
needs: []
5151
script:
5252
- >
53-
nix-shell --run '
53+
nix-shell --arg ci true --run $'
5454
npm run lint;
5555
npm run lint-shell;
5656
'
@@ -82,8 +82,8 @@ check:test-generate:
8282
needs: []
8383
script:
8484
- >
85-
nix-shell --run '
86-
./scripts/check-test-generate.sh > ./tmp/check-test.yml
85+
nix-shell --arg ci true --run $'
86+
./scripts/check-test-generate.sh > ./tmp/check-test.yml;
8787
'
8888
artifacts:
8989
when: always
@@ -124,7 +124,7 @@ build:merge:
124124
# Required for `gh pr create`
125125
- git remote add upstream "$GH_PROJECT_URL"
126126
- >
127-
nix-shell --run '
127+
nix-shell --arg ci true --run $'
128128
gh pr create \
129129
--head staging \
130130
--base master \
@@ -149,7 +149,7 @@ build:dist:
149149
needs: []
150150
script:
151151
- >
152-
nix-shell --run '
152+
nix-shell --arg ci true --run $'
153153
npm run build --verbose;
154154
'
155155
artifacts:
@@ -167,8 +167,8 @@ build:platforms-generate:
167167
needs: []
168168
script:
169169
- >
170-
nix-shell --run '
171-
./scripts/build-platforms-generate.sh > ./tmp/build-platforms.yml
170+
nix-shell --arg ci true --run $'
171+
./scripts/build-platforms-generate.sh > ./tmp/build-platforms.yml;
172172
'
173173
artifacts:
174174
when: always
@@ -210,7 +210,7 @@ build:prerelease:
210210
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
211211
- echo 'Publishing library prerelease'
212212
- >
213-
nix-shell --run '
213+
nix-shell --arg ci true --run $'
214214
npm publish --tag prerelease --access public;
215215
'
216216
after_script:
@@ -425,10 +425,7 @@ integration:prerelease:
425425
script:
426426
- echo 'Publishing application prerelease'
427427
- >
428-
nix-shell --run $'
429-
set -o errexit;
430-
set -o nounset;
431-
set -o pipefail;
428+
nix-shell --arg ci true --run $'
432429
if gh release view "$CI_COMMIT_TAG" --repo "$GH_PROJECT_PATH" >/dev/null; then \
433430
gh release \
434431
upload "$CI_COMMIT_TAG" \
@@ -456,10 +453,7 @@ integration:prerelease:
456453
'
457454
- echo 'Prereleasing container image'
458455
- >
459-
nix-shell --run $'
460-
set -o errexit;
461-
set -o nounset;
462-
set -o pipefail;
456+
nix-shell --arg ci true --run $'
463457
skopeo login \
464458
--username "$CI_REGISTRY_USER" \
465459
--password "$CI_REGISTRY_PASSWORD" \
@@ -481,8 +475,6 @@ integration:merge:
481475
stage: integration
482476
needs:
483477
- build:merge
484-
- job: build:dist
485-
optional: true
486478
- job: build:platforms
487479
optional: true
488480
- job: integration:nix
@@ -505,7 +497,7 @@ integration:merge:
505497
GIT_DEPTH: 0
506498
script:
507499
- >
508-
nix-shell --run '
500+
nix-shell --arg ci true --run $'
509501
printf "Pipeline Succeeded on ${CI_PIPELINE_ID} for ${CI_COMMIT_SHA}\n\n${CI_PIPELINE_URL}" \
510502
| gh pr comment staging \
511503
--body-file - \
@@ -624,12 +616,12 @@ release:distribution:
624616
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
625617
- echo 'Publishing library'
626618
- >
627-
nix-shell --run $'
619+
nix-shell --arg ci true --run $'
628620
npm publish --access public;
629621
'
630622
- echo 'Releasing application builds'
631623
- >
632-
nix-shell --run $'
624+
nix-shell --arg ci true --run $'
633625
gh release \
634626
create "$CI_COMMIT_TAG" \
635627
builds/*.closure.gz \
@@ -644,7 +636,7 @@ release:distribution:
644636
'
645637
- echo 'Releasing container image'
646638
- >
647-
nix-shell --run $'
639+
nix-shell --arg ci true --run $'
648640
skopeo login \
649641
--username "$CI_REGISTRY_USER" \
650642
--password "$CI_REGISTRY_PASSWORD" \

benches/gitgc.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import path from 'path';
12
import b from 'benny';
2-
import packageJson from '../package.json';
3+
import { suiteCommon } from './utils';
34

45
async function main () {
56
let map = new Map();
67
let obj = {};
7-
let arr = [];
8+
let arr: any = [];
89
let set = new Set();
910
const summary = await b.suite(
10-
'gitgc',
11+
path.basename(__filename, path.extname(__filename)),
1112
b.add('map', async () => {
1213
map = new Map();
1314
return async () => {
@@ -78,19 +79,7 @@ async function main () {
7879
}
7980
};
8081
}),
81-
b.cycle(),
82-
b.complete(),
83-
b.save({
84-
file: 'gitgc',
85-
folder: 'benches/results',
86-
version: packageJson.version,
87-
details: true,
88-
}),
89-
b.save({
90-
file: 'gitgc',
91-
folder: 'benches/results',
92-
format: 'chart.html',
93-
}),
82+
...suiteCommon,
9483
);
9584
return summary;
9685
}

benches/index.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env ts-node
22

33
import fs from 'fs';
4+
import path from 'path';
45
import si from 'systeminformation';
56
import gitgc from './gitgc';
67

78
async function main(): Promise<void> {
9+
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
810
await gitgc();
11+
const resultFilenames = await fs.promises.readdir(
12+
path.join(__dirname, 'results'),
13+
);
14+
const metricsFile = await fs.promises.open(
15+
path.join(__dirname, 'results', 'metrics.txt'),
16+
'w',
17+
);
18+
let concatenating = false;
19+
for (const resultFilename of resultFilenames) {
20+
if (/.+_metrics\.txt$/.test(resultFilename)) {
21+
const metricsData = await fs.promises.readFile(
22+
path.join(__dirname, 'results', resultFilename),
23+
);
24+
if (concatenating) {
25+
await metricsFile.write('\n');
26+
}
27+
await metricsFile.write(metricsData);
28+
concatenating = true;
29+
}
30+
}
31+
await metricsFile.close();
932
const systemData = await si.get({
1033
cpu: '*',
1134
osInfo: 'platform, distro, release, kernel, arch',
1235
system: 'model, manufacturer',
1336
});
1437
await fs.promises.writeFile(
15-
'benches/results/system.json',
38+
path.join(__dirname, 'results', 'system.json'),
1639
JSON.stringify(systemData, null, 2),
1740
);
1841
}

benches/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './utils';

benches/utils/utils.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import b from 'benny';
4+
import { codeBlock } from 'common-tags';
5+
import packageJson from '../../package.json';
6+
7+
const suiteCommon = [
8+
b.cycle(),
9+
b.complete(),
10+
b.save({
11+
file: (summary) => summary.name,
12+
folder: path.join(__dirname, '../results'),
13+
version: packageJson.version,
14+
details: true,
15+
}),
16+
b.save({
17+
file: (summary) => summary.name,
18+
folder: path.join(__dirname, '../results'),
19+
version: packageJson.version,
20+
format: 'chart.html',
21+
}),
22+
b.complete((summary) => {
23+
const filePath = path.join(
24+
__dirname,
25+
'../results',
26+
summary.name + '_metrics.txt',
27+
);
28+
fs.writeFileSync(
29+
filePath,
30+
codeBlock`
31+
# TYPE ${summary.name}_ops gauge
32+
${summary.results
33+
.map(
34+
(result) =>
35+
`${summary.name}_ops{name="${result.name}"} ${result.ops}`,
36+
)
37+
.join('\n')}
38+
39+
# TYPE ${summary.name}_margin gauge
40+
${summary.results
41+
.map(
42+
(result) =>
43+
`${summary.name}_margin{name="${result.name}"} ${result.margin}`,
44+
)
45+
.join('\n')}
46+
47+
# TYPE ${summary.name}_samples counter
48+
${summary.results
49+
.map(
50+
(result) =>
51+
`${summary.name}_samples{name="${result.name}"} ${result.samples}`,
52+
)
53+
.join('\n')}
54+
` + '\n',
55+
);
56+
// eslint-disable-next-line no-console
57+
console.log('\nSaved to:', path.resolve(filePath));
58+
}),
59+
];
60+
61+
export { suiteCommon };

0 commit comments

Comments
 (0)