Commit 0a69bb2d authored by Miguel Rincon's avatar Miguel Rincon

Adds tests to Prometheus data processing

parent f9c4c463
......@@ -191,7 +191,7 @@ const mapPanelToViewModel = ({
xAxis,
maxValue: max_value,
links: links.map(mapLinksToViewModel),
metrics: mapToMetricsViewModel(metrics, yAxis.name),
metrics: mapToMetricsViewModel(metrics),
};
};
......@@ -224,6 +224,19 @@ export const mapToDashboardViewModel = ({ dashboard = '', panel_groups = [] }) =
};
};
/**
* Processes a single Range vector, part of the result
* of type `matrix` in the form:
*
* {
* "metric": { "<label_name>": "<label_value>", ... },
* "values": [ [ <unix_time>, "<sample_value>" ], ... ]
* },
*
* See https://prometheus.io/docs/prometheus/latest/querying/api/#range-vectors
*
* @param {*} timeSeries
*/
export const normalizeQueryResult = timeSeries => {
let normalizedResult = {};
......
......@@ -5,6 +5,7 @@ import {
parseAnnotationsResponse,
removeLeadingSlash,
mapToDashboardViewModel,
normalizeQueryResult,
} from '~/monitoring/stores/utils';
import { annotationsData } from '../mock_data';
import { NOT_IN_DB_PREFIX } from '~/monitoring/constants';
......@@ -391,6 +392,28 @@ describe('mapToDashboardViewModel', () => {
});
});
describe('normalizeQueryResult', () => {
const testData = {
metric: {
__name__: 'up',
job: 'prometheus',
instance: 'localhost:9090',
},
values: [[1435781430.781, '1'], [1435781445.781, '1'], [1435781460.781, '1']],
};
it('processes a simple matrix result', () => {
expect(normalizeQueryResult(testData)).toEqual({
metric: { __name__: 'up', job: 'prometheus', instance: 'localhost:9090' },
values: [
['2015-07-01T20:10:30.781Z', 1],
['2015-07-01T20:10:45.781Z', 1],
['2015-07-01T20:11:00.781Z', 1],
],
});
});
});
describe('uniqMetricsId', () => {
[
{ input: { id: 1 }, expected: `${NOT_IN_DB_PREFIX}_1` },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment