Commit 8b39ede9 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'mrincon/prometheus-data-spec' into 'master'

Adds tests to utils for prometheus data processing

See merge request gitlab-org/gitlab!33835
parents 93107c59 0a69bb2d
......@@ -192,7 +192,7 @@ const mapPanelToViewModel = ({
xAxis,
maxValue: max_value,
links: links.map(mapLinksToViewModel),
metrics: mapToMetricsViewModel(metrics, yAxis.name),
metrics: mapToMetricsViewModel(metrics),
};
};
......@@ -232,6 +232,19 @@ export const mapToDashboardViewModel = ({
};
};
/**
* 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';
......@@ -397,6 +398,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