Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0a69bb2d
Commit
0a69bb2d
authored
Jun 04, 2020
by
Miguel Rincon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds tests to Prometheus data processing
parent
f9c4c463
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
app/assets/javascripts/monitoring/stores/utils.js
app/assets/javascripts/monitoring/stores/utils.js
+14
-1
spec/frontend/monitoring/store/utils_spec.js
spec/frontend/monitoring/store/utils_spec.js
+23
-0
No files found.
app/assets/javascripts/monitoring/stores/utils.js
View file @
0a69bb2d
...
@@ -191,7 +191,7 @@ const mapPanelToViewModel = ({
...
@@ -191,7 +191,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
),
};
};
};
};
...
@@ -224,6 +224,19 @@ export const mapToDashboardViewModel = ({ dashboard = '', panel_groups = [] }) =
...
@@ -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
=>
{
export
const
normalizeQueryResult
=
timeSeries
=>
{
let
normalizedResult
=
{};
let
normalizedResult
=
{};
...
...
spec/frontend/monitoring/store/utils_spec.js
View file @
0a69bb2d
...
@@ -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
'
;
...
@@ -391,6 +392,28 @@ describe('mapToDashboardViewModel', () => {
...
@@ -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
'
,
()
=>
{
describe
(
'
uniqMetricsId
'
,
()
=>
{
[
[
{
input
:
{
id
:
1
},
expected
:
`
${
NOT_IN_DB_PREFIX
}
_1`
},
{
input
:
{
id
:
1
},
expected
:
`
${
NOT_IN_DB_PREFIX
}
_1`
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment