Skip to content

Commit fcf7a5a

Browse files
committed
Allows for other metrics too
1 parent 437b755 commit fcf7a5a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

bin/otel-metrics-sender.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function sanitize(str) {
4848
/**
4949
* Normalizes and sends metrics for a single benchmark file's results.
5050
* @param {object} benchmarkFileData The benchmark test file data e.g. { name: 'test.bench.js', parsedOutput: { 'test case 1': { mean: 123, max: 456 }, ... } }
51-
* @param {object} commonAttributes Common attributes to add to all metrics.
51+
* @param {object} commonAttributes Common attributes to add to all metrics, like Node version.
5252
*/
5353
function sendBenchmarkTestMetrics(benchmarkFileData, commonAttributes = {}) {
5454
const fileName = benchmarkFileData.name
@@ -62,21 +62,23 @@ function sendBenchmarkTestMetrics(benchmarkFileData, commonAttributes = {}) {
6262
const suiteName = sanitize(fileName)
6363
console.log(`--- Sending metrics for ${fileName} ---`)
6464

65+
// measurements will contain the following:
66+
// 'mean', 'max', 'min', 'median', '5thPercentile', '95thPercentile', 'stdDev', 'numSamples'
6567
for (const [caseName, measurements] of Object.entries(testCases)) {
6668
const sanitizedCaseName = sanitize(caseName)
67-
//for (const [metricKey, metricValue] of Object.entries(measurements)) {
68-
//if (metricKey === 'numSamples') continue
69-
//if (typeof metricValue === 'number' && !isNaN(metricValue)) {
69+
for (const [metricKey, metricValue] of Object.entries(measurements)) {
70+
if (metricKey === 'numSamples') continue
71+
if (typeof metricValue === 'number' && !isNaN(metricValue)) {
7072
const attributes = {
7173
...commonAttributes,
7274
suite_name: suiteName,
7375
case_name: sanitizedCaseName,
74-
metric_type: 'mean', // e.g., 'mean', 'max', 'min',
76+
metric_type: metricKey,
7577
numSamples: measurements.numSamples
7678
};
77-
benchmarkValueGauge.record(measurements.mean, attributes);
78-
//}
79-
//}
79+
benchmarkValueGauge.record(metricValue, attributes);
80+
}
81+
}
8082
}
8183
}
8284

bin/run-bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,5 @@ async function run() {
184184
resolveGlobs()
185185
await runBenchmarks()
186186
await Promise.all(testPromises)
187-
await printer.finish()
187+
printer.finish()
188188
}

0 commit comments

Comments
 (0)