diff --git a/packages/caliper-core/lib/common/prometheus/prometheus-query-helper.js b/packages/caliper-core/lib/common/prometheus/prometheus-query-helper.js index 064eb33d8..a0b80e9c0 100644 --- a/packages/caliper-core/lib/common/prometheus/prometheus-query-helper.js +++ b/packages/caliper-core/lib/common/prometheus/prometheus-query-helper.js @@ -163,6 +163,8 @@ class PrometheusQueryHelper { return values[0]; } } + case 'sum': + return values.reduce((x, y) => x + y); default: Logger.error(`Unknown stat type passed: ${statType}`); throw new Error(`Unknown stat type passed: ${statType}`); diff --git a/packages/caliper-core/test/common/prometheus/prometheus-query-helper.js b/packages/caliper-core/test/common/prometheus/prometheus-query-helper.js index daa4b99a0..03c477260 100644 --- a/packages/caliper-core/test/common/prometheus/prometheus-query-helper.js +++ b/packages/caliper-core/test/common/prometheus/prometheus-query-helper.js @@ -410,6 +410,19 @@ describe('PrometheusQueryHelper implementation', () => { output.get('unknown').should.equal(2.8); }); + it('should retrieve the sum value from a matrix response', () => { + const response = { + data: { + resultType: 'matrix', + result: [{ values: [[111, 1], [111, 1], [111, 2], [111, 2], [111, 8]] }] + } + }; + const output = PrometheusQueryHelper.extractStatisticFromRange(response, 'sum'); + output.should.be.an('map'); + output.size.should.equal(1); + output.get('unknown').should.equal(14); + }); + it('should return `-` if passed too few results', () => { const response = { data: {