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 = ({ ...@@ -192,7 +192,7 @@ const mapPanelToViewModel = ({
xAxis, xAxis,
maxValue: max_value, maxValue: max_value,
links: links.map(mapLinksToViewModel), links: links.map(mapLinksToViewModel),
metrics: mapToMetricsViewModel(metrics, yAxis.name), metrics: mapToMetricsViewModel(metrics),
}; };
}; };
...@@ -232,6 +232,19 @@ export const mapToDashboardViewModel = ({ ...@@ -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 => { export const normalizeQueryResult = timeSeries => {
let normalizedResult = {}; let normalizedResult = {};
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
parseAnnotationsResponse, parseAnnotationsResponse,
removeLeadingSlash, removeLeadingSlash,
mapToDashboardViewModel, mapToDashboardViewModel,
normalizeQueryResult,
} from '~/monitoring/stores/utils'; } from '~/monitoring/stores/utils';
import { annotationsData } from '../mock_data'; import { annotationsData } from '../mock_data';
import { NOT_IN_DB_PREFIX } from '~/monitoring/constants'; import { NOT_IN_DB_PREFIX } from '~/monitoring/constants';
...@@ -397,6 +398,28 @@ describe('mapToDashboardViewModel', () => { ...@@ -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', () => { describe('uniqMetricsId', () => {
[ [
{ input: { id: 1 }, expected: `${NOT_IN_DB_PREFIX}_1` }, { 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