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
f69ad389
Commit
f69ad389
authored
Sep 01, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor monitoring_store.js
parent
a4d3ac40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
41 deletions
+37
-41
app/assets/javascripts/monitoring/stores/monitoring_store.js
app/assets/javascripts/monitoring/stores/monitoring_store.js
+37
-41
No files found.
app/assets/javascripts/monitoring/stores/monitoring_store.js
View file @
f69ad389
import
_
from
'
underscore
'
;
const
sortMetrics
=
metrics
=>
_
.
chain
(
metrics
).
sortBy
(
'
weight
'
).
sortBy
(
'
title
'
).
value
();
function
sortMetrics
(
metrics
)
{
return
_
.
chain
(
metrics
).
sortBy
(
'
weight
'
).
sortBy
(
'
title
'
).
value
();
}
function
normalizeMetrics
(
metrics
)
{
return
metrics
.
map
(
metric
=>
({
...
metric
,
queries
:
metric
.
queries
.
map
(
query
=>
({
...
query
,
result
:
query
.
result
.
map
(
result
=>
({
...
result
,
values
:
result
.
values
.
map
(([
timestamp
,
value
])
=>
({
time
:
new
Date
(
timestamp
*
1000
),
value
,
})),
})),
})),
}));
}
function
collate
(
array
,
rows
=
2
)
{
const
collatedArray
=
[];
let
row
=
[];
array
.
forEach
((
value
,
index
)
=>
{
row
.
push
(
value
);
if
(
index
%
rows
===
0
)
{
collatedArray
.
push
(
row
);
row
=
[];
}
});
if
(
row
.
length
>
0
)
{
collatedArray
.
push
(
row
);
}
return
collatedArray
;
}
class
MonitoringStore
{
export
default
class
MonitoringStore
{
constructor
()
{
this
.
groups
=
[];
this
.
deploymentData
=
[];
}
// eslint-disable-next-line class-methods-use-this
createArrayRows
(
metrics
=
[])
{
const
currentMetrics
=
metrics
;
const
availableMetrics
=
[];
let
metricsRow
=
[];
let
index
=
1
;
Object
.
keys
(
currentMetrics
).
forEach
((
key
)
=>
{
const
metricValues
=
currentMetrics
[
key
].
queries
[
0
].
result
;
if
(
metricValues
!=
null
)
{
currentMetrics
[
key
].
queries
[
0
].
result
=
metricValues
.
map
((
series
)
=>
{
let
convertedValues
=
[];
if
(
series
!=
null
)
{
convertedValues
=
series
.
values
.
map
(
metric
=>
({
time
:
new
Date
(
metric
[
0
]
*
1000
),
value
:
metric
[
1
],
}));
}
return
{
metric
:
series
.
metric
,
values
:
convertedValues
,
};
});
metricsRow
.
push
(
currentMetrics
[
key
]);
if
(
index
%
2
===
0
)
{
availableMetrics
.
push
(
metricsRow
);
metricsRow
=
[];
}
index
=
index
+=
1
;
}
});
if
(
metricsRow
.
length
>
0
)
{
availableMetrics
.
push
(
metricsRow
);
}
return
availableMetrics
;
}
storeMetrics
(
groups
=
[])
{
this
.
groups
=
groups
.
map
(
group
=>
({
...
group
,
metrics
:
this
.
createArrayRows
(
sortMetrics
(
group
.
metrics
)),
metrics
:
collate
(
normalizeMetrics
(
sortMetrics
(
group
.
metrics
)
)),
}));
}
...
...
@@ -65,5 +63,3 @@ class MonitoringStore {
return
metricsCount
;
}
}
export
default
MonitoringStore
;
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