@@ -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 */
5353function 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
0 commit comments