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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
e6cd217d
Commit
e6cd217d
authored
Feb 02, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted prometheus_metrics.js to use axios
parent
85e0bf39
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
28 deletions
+33
-28
app/assets/javascripts/prometheus_metrics/prometheus_metrics.js
...sets/javascripts/prometheus_metrics/prometheus_metrics.js
+7
-10
spec/javascripts/prometheus_metrics/prometheus_metrics_spec.js
...javascripts/prometheus_metrics/prometheus_metrics_spec.js
+26
-18
No files found.
app/assets/javascripts/prometheus_metrics/prometheus_metrics.js
View file @
e6cd217d
import
axios
from
'
../lib/utils/axios_utils
'
;
import
PANEL_STATE
from
'
./constants
'
;
import
PANEL_STATE
from
'
./constants
'
;
import
{
backOff
}
from
'
../lib/utils/common_utils
'
;
import
{
backOff
}
from
'
../lib/utils/common_utils
'
;
...
@@ -81,24 +82,20 @@ export default class PrometheusMetrics {
...
@@ -81,24 +82,20 @@ export default class PrometheusMetrics {
loadActiveMetrics
()
{
loadActiveMetrics
()
{
this
.
showMonitoringMetricsPanelState
(
PANEL_STATE
.
LOADING
);
this
.
showMonitoringMetricsPanelState
(
PANEL_STATE
.
LOADING
);
backOff
((
next
,
stop
)
=>
{
backOff
((
next
,
stop
)
=>
{
$
.
ajax
({
axios
.
get
(
this
.
activeMetricsEndpoint
)
url
:
this
.
activeMetricsEndpoint
,
.
then
(({
data
})
=>
{
dataType
:
'
json
'
,
if
(
data
&&
data
.
success
)
{
global
:
false
,
stop
(
data
);
})
.
done
((
res
)
=>
{
if
(
res
&&
res
.
success
)
{
stop
(
res
);
}
else
{
}
else
{
this
.
backOffRequestCounter
=
this
.
backOffRequestCounter
+=
1
;
this
.
backOffRequestCounter
=
this
.
backOffRequestCounter
+=
1
;
if
(
this
.
backOffRequestCounter
<
3
)
{
if
(
this
.
backOffRequestCounter
<
3
)
{
next
();
next
();
}
else
{
}
else
{
stop
(
res
);
stop
(
data
);
}
}
}
}
})
})
.
fail
(
stop
);
.
catch
(
stop
);
})
})
.
then
((
res
)
=>
{
.
then
((
res
)
=>
{
if
(
res
&&
res
.
data
&&
res
.
data
.
length
)
{
if
(
res
&&
res
.
data
&&
res
.
data
.
length
)
{
...
...
spec/javascripts/prometheus_metrics/prometheus_metrics_spec.js
View file @
e6cd217d
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
PrometheusMetrics
from
'
~/prometheus_metrics/prometheus_metrics
'
;
import
PrometheusMetrics
from
'
~/prometheus_metrics/prometheus_metrics
'
;
import
PANEL_STATE
from
'
~/prometheus_metrics/constants
'
;
import
PANEL_STATE
from
'
~/prometheus_metrics/constants
'
;
import
{
metrics
,
missingVarMetrics
}
from
'
./mock_data
'
;
import
{
metrics
,
missingVarMetrics
}
from
'
./mock_data
'
;
...
@@ -102,25 +104,38 @@ describe('PrometheusMetrics', () => {
...
@@ -102,25 +104,38 @@ describe('PrometheusMetrics', () => {
describe
(
'
loadActiveMetrics
'
,
()
=>
{
describe
(
'
loadActiveMetrics
'
,
()
=>
{
let
prometheusMetrics
;
let
prometheusMetrics
;
let
mock
;
function
mockSuccess
()
{
mock
.
onGet
(
prometheusMetrics
.
activeMetricsEndpoint
).
reply
(
200
,
{
data
:
metrics
,
success
:
true
,
});
}
function
mockError
()
{
mock
.
onGet
(
prometheusMetrics
.
activeMetricsEndpoint
).
networkError
();
}
beforeEach
(()
=>
{
beforeEach
(()
=>
{
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
prometheusMetrics
=
new
PrometheusMetrics
(
'
.js-prometheus-metrics-monitoring
'
);
prometheusMetrics
=
new
PrometheusMetrics
(
'
.js-prometheus-metrics-monitoring
'
);
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
mock
.
restore
();
});
});
it
(
'
should show loader animation while response is being loaded and hide it when request is complete
'
,
(
done
)
=>
{
it
(
'
should show loader animation while response is being loaded and hide it when request is complete
'
,
(
done
)
=>
{
const
deferred
=
$
.
Deferred
();
mockSuccess
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValue
(
deferred
.
promise
());
prometheusMetrics
.
loadActiveMetrics
();
prometheusMetrics
.
loadActiveMetrics
();
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
expect
(
$
.
ajax
).
toHaveBeenCalledWith
({
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
prometheusMetrics
.
activeMetricsEndpoint
);
url
:
prometheusMetrics
.
activeMetricsEndpoint
,
dataType
:
'
json
'
,
global
:
false
,
});
deferred
.
resolve
({
data
:
metrics
,
success
:
true
});
setTimeout
(()
=>
{
setTimeout
(()
=>
{
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
...
@@ -129,14 +144,10 @@ describe('PrometheusMetrics', () => {
...
@@ -129,14 +144,10 @@ describe('PrometheusMetrics', () => {
});
});
it
(
'
should show empty state if response failed to load
'
,
(
done
)
=>
{
it
(
'
should show empty state if response failed to load
'
,
(
done
)
=>
{
const
deferred
=
$
.
Deferred
();
mockError
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValue
(
deferred
.
promise
());
spyOn
(
prometheusMetrics
,
'
populateActiveMetrics
'
);
prometheusMetrics
.
loadActiveMetrics
();
prometheusMetrics
.
loadActiveMetrics
();
deferred
.
reject
();
setTimeout
(()
=>
{
setTimeout
(()
=>
{
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
expect
(
prometheusMetrics
.
$monitoredMetricsLoading
.
hasClass
(
'
hidden
'
)).
toBeTruthy
();
expect
(
prometheusMetrics
.
$monitoredMetricsEmpty
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
expect
(
prometheusMetrics
.
$monitoredMetricsEmpty
.
hasClass
(
'
hidden
'
)).
toBeFalsy
();
...
@@ -145,14 +156,11 @@ describe('PrometheusMetrics', () => {
...
@@ -145,14 +156,11 @@ describe('PrometheusMetrics', () => {
});
});
it
(
'
should populate metrics list once response is loaded
'
,
(
done
)
=>
{
it
(
'
should populate metrics list once response is loaded
'
,
(
done
)
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValue
(
deferred
.
promise
());
spyOn
(
prometheusMetrics
,
'
populateActiveMetrics
'
);
spyOn
(
prometheusMetrics
,
'
populateActiveMetrics
'
);
mockSuccess
();
prometheusMetrics
.
loadActiveMetrics
();
prometheusMetrics
.
loadActiveMetrics
();
deferred
.
resolve
({
data
:
metrics
,
success
:
true
});
setTimeout
(()
=>
{
setTimeout
(()
=>
{
expect
(
prometheusMetrics
.
populateActiveMetrics
).
toHaveBeenCalledWith
(
metrics
);
expect
(
prometheusMetrics
.
populateActiveMetrics
).
toHaveBeenCalledWith
(
metrics
);
done
();
done
();
...
...
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