|
@@ -127,4 +127,82 @@ describe('Prometheus Result Transformer', () => {
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ describe('When resultFormat is time series', () => {
|
|
|
|
|
+ it('should transform matrix into timeseries', () => {
|
|
|
|
|
+ const response = {
|
|
|
|
|
+ status: 'success',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ resultType: 'matrix',
|
|
|
|
|
+ result: [
|
|
|
|
|
+ {
|
|
|
|
|
+ metric: { __name__: 'test', job: 'testjob' },
|
|
|
|
|
+ values: [[0, '10'], [1, '10'], [2, '0']],
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+ let result = [];
|
|
|
|
|
+ let options = {
|
|
|
|
|
+ format: 'timeseries',
|
|
|
|
|
+ start: 0,
|
|
|
|
|
+ end: 2,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ ctx.resultTransformer.transform(result, { data: response }, options);
|
|
|
|
|
+ expect(result).toEqual([{ target: 'test{job="testjob"}', datapoints: [[10, 0], [10, 1000], [0, 2000]] }]);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should fill timeseries with null values', () => {
|
|
|
|
|
+ const response = {
|
|
|
|
|
+ status: 'success',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ resultType: 'matrix',
|
|
|
|
|
+ result: [
|
|
|
|
|
+ {
|
|
|
|
|
+ metric: { __name__: 'test', job: 'testjob' },
|
|
|
|
|
+ values: [[1, '10'], [2, '0']],
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+ let result = [];
|
|
|
|
|
+ let options = {
|
|
|
|
|
+ format: 'timeseries',
|
|
|
|
|
+ step: 1,
|
|
|
|
|
+ start: 0,
|
|
|
|
|
+ end: 2,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ ctx.resultTransformer.transform(result, { data: response }, options);
|
|
|
|
|
+ expect(result).toEqual([{ target: 'test{job="testjob"}', datapoints: [[null, 0], [10, 1000], [0, 2000]] }]);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should align null values with step', () => {
|
|
|
|
|
+ const response = {
|
|
|
|
|
+ status: 'success',
|
|
|
|
|
+ data: {
|
|
|
|
|
+ resultType: 'matrix',
|
|
|
|
|
+ result: [
|
|
|
|
|
+ {
|
|
|
|
|
+ metric: { __name__: 'test', job: 'testjob' },
|
|
|
|
|
+ values: [[4, '10'], [8, '10']],
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+ let result = [];
|
|
|
|
|
+ let options = {
|
|
|
|
|
+ format: 'timeseries',
|
|
|
|
|
+ step: 2,
|
|
|
|
|
+ start: 0,
|
|
|
|
|
+ end: 8,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ ctx.resultTransformer.transform(result, { data: response }, options);
|
|
|
|
|
+ expect(result).toEqual([
|
|
|
|
|
+ { target: 'test{job="testjob"}', datapoints: [[null, 0], [null, 2000], [10, 4000], [null, 6000], [10, 8000]] },
|
|
|
|
|
+ ]);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|