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
1f5ae8cd
Commit
1f5ae8cd
authored
Sep 13, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'refactor-monitoring-service' into 'master'
Refactor MonitoringService class See merge request !14003
parents
7771afd5
70e9e884
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
54 deletions
+61
-54
app/assets/javascripts/monitoring/components/dashboard.vue
app/assets/javascripts/monitoring/components/dashboard.vue
+14
-47
app/assets/javascripts/monitoring/services/monitoring_service.js
...ets/javascripts/monitoring/services/monitoring_service.js
+42
-7
changelogs/unreleased/refactor-monitoring-service.yml
changelogs/unreleased/refactor-monitoring-service.yml
+5
-0
No files found.
app/assets/javascripts/monitoring/components/dashboard.vue
View file @
1f5ae8cd
<
script
>
<
script
>
/* global Flash */
/* global Flash */
import
_
from
'
underscore
'
;
import
_
from
'
underscore
'
;
import
statusCodes
from
'
../../lib/utils/http_status
'
;
import
MonitoringService
from
'
../services/monitoring_service
'
;
import
MonitoringService
from
'
../services/monitoring_service
'
;
import
GraphGroup
from
'
./graph_group.vue
'
;
import
GraphGroup
from
'
./graph_group.vue
'
;
import
Graph
from
'
./graph.vue
'
;
import
Graph
from
'
./graph.vue
'
;
...
@@ -21,10 +20,9 @@
...
@@ -21,10 +20,9 @@
hasMetrics
:
gl
.
utils
.
convertPermissionToBoolean
(
metricsData
.
hasMetrics
),
hasMetrics
:
gl
.
utils
.
convertPermissionToBoolean
(
metricsData
.
hasMetrics
),
documentationPath
:
metricsData
.
documentationPath
,
documentationPath
:
metricsData
.
documentationPath
,
settingsPath
:
metricsData
.
settingsPath
,
settingsPath
:
metricsData
.
settingsPath
,
e
ndpoint
:
metricsData
.
additionalMetrics
,
metricsE
ndpoint
:
metricsData
.
additionalMetrics
,
deploymentEndpoint
:
metricsData
.
deploymentEndpoint
,
deploymentEndpoint
:
metricsData
.
deploymentEndpoint
,
showEmptyState
:
true
,
showEmptyState
:
true
,
backOffRequestCounter
:
0
,
updateAspectRatio
:
false
,
updateAspectRatio
:
false
,
updatedAspectRatios
:
0
,
updatedAspectRatios
:
0
,
resizeThrottled
:
{},
resizeThrottled
:
{},
...
@@ -39,50 +37,16 @@
...
@@ -39,50 +37,16 @@
methods
:
{
methods
:
{
getGraphsData
()
{
getGraphsData
()
{
const
maxNumberOfRequests
=
3
;
this
.
state
=
'
loading
'
;
this
.
state
=
'
loading
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
{
Promise
.
all
([
this
.
service
.
get
().
then
((
resp
)
=>
{
this
.
service
.
getGraphsData
()
if
(
resp
.
status
===
statusCodes
.
NO_CONTENT
)
{
.
then
(
data
=>
this
.
store
.
storeMetrics
(
data
)),
this
.
backOffRequestCounter
=
this
.
backOffRequestCounter
+=
1
;
this
.
service
.
getDeploymentData
()
if
(
this
.
backOffRequestCounter
<
maxNumberOfRequests
)
{
.
then
(
data
=>
this
.
store
.
storeDeploymentData
(
data
))
next
();
.
catch
(()
=>
new
Flash
(
'
Error getting deployment information.
'
)),
}
else
{
])
stop
(
new
Error
(
'
Failed to connect to the prometheus server
'
));
.
then
(()
=>
{
this
.
showEmptyState
=
false
;
})
}
.
catch
(()
=>
{
this
.
state
=
'
unableToConnect
'
;
});
}
else
{
stop
(
resp
);
}
}).
catch
(
stop
);
})
.
then
((
resp
)
=>
{
if
(
resp
.
status
===
statusCodes
.
NO_CONTENT
)
{
this
.
state
=
'
unableToConnect
'
;
return
false
;
}
return
resp
.
json
();
})
.
then
((
metricGroupsData
)
=>
{
if
(
!
metricGroupsData
)
return
false
;
this
.
store
.
storeMetrics
(
metricGroupsData
.
data
);
return
this
.
getDeploymentData
();
})
.
then
((
deploymentData
)
=>
{
if
(
deploymentData
!==
false
)
{
this
.
store
.
storeDeploymentData
(
deploymentData
.
deployments
);
this
.
showEmptyState
=
false
;
}
return
{};
})
.
catch
(()
=>
{
this
.
state
=
'
unableToConnect
'
;
});
},
getDeploymentData
()
{
return
this
.
service
.
getDeploymentData
(
this
.
deploymentEndpoint
)
.
then
(
resp
=>
resp
.
json
())
.
catch
(()
=>
new
Flash
(
'
Error getting deployment information.
'
));
},
},
resize
()
{
resize
()
{
...
@@ -99,7 +63,10 @@
...
@@ -99,7 +63,10 @@
},
},
created
()
{
created
()
{
this
.
service
=
new
MonitoringService
(
this
.
endpoint
);
this
.
service
=
new
MonitoringService
({
metricsEndpoint
:
this
.
metricsEndpoint
,
deploymentEndpoint
:
this
.
deploymentEndpoint
,
});
eventHub
.
$on
(
'
toggleAspectRatio
'
,
this
.
toggleAspectRatio
);
eventHub
.
$on
(
'
toggleAspectRatio
'
,
this
.
toggleAspectRatio
);
},
},
...
...
app/assets/javascripts/monitoring/services/monitoring_service.js
View file @
1f5ae8cd
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
VueResource
from
'
vue-resource
'
;
import
VueResource
from
'
vue-resource
'
;
import
statusCodes
from
'
../../lib/utils/http_status
'
;
Vue
.
use
(
VueResource
);
Vue
.
use
(
VueResource
);
const
MAX_REQUESTS
=
3
;
function
backOffRequest
(
makeRequestCallback
)
{
let
requestCounter
=
0
;
return
gl
.
utils
.
backOff
((
next
,
stop
)
=>
{
makeRequestCallback
().
then
((
resp
)
=>
{
if
(
resp
.
status
===
statusCodes
.
NO_CONTENT
)
{
requestCounter
+=
1
;
if
(
requestCounter
<
MAX_REQUESTS
)
{
next
();
}
else
{
stop
(
new
Error
(
'
Failed to connect to the prometheus server
'
));
}
}
else
{
stop
(
resp
);
}
}).
catch
(
stop
);
});
}
export
default
class
MonitoringService
{
export
default
class
MonitoringService
{
constructor
(
endpoint
)
{
constructor
({
metricsEndpoint
,
deploymentEndpoint
})
{
this
.
graphs
=
Vue
.
resource
(
endpoint
);
this
.
metricsEndpoint
=
metricsEndpoint
;
this
.
deploymentEndpoint
=
deploymentEndpoint
;
}
}
get
()
{
getGraphsData
()
{
return
this
.
graphs
.
get
();
return
backOffRequest
(()
=>
Vue
.
http
.
get
(
this
.
metricsEndpoint
))
.
then
(
resp
=>
resp
.
json
())
.
then
((
response
)
=>
{
if
(
!
response
||
!
response
.
data
)
{
throw
new
Error
(
'
Unexpected metrics data response from prometheus endpoint
'
);
}
return
response
.
data
;
});
}
}
// eslint-disable-next-line class-methods-use-this
getDeploymentData
()
{
getDeploymentData
(
endpoint
)
{
return
backOffRequest
(()
=>
Vue
.
http
.
get
(
this
.
deploymentEndpoint
))
return
Vue
.
http
.
get
(
endpoint
);
.
then
(
resp
=>
resp
.
json
())
.
then
((
response
)
=>
{
if
(
!
response
||
!
response
.
deployments
)
{
throw
new
Error
(
'
Unexpected deployment data response from prometheus endpoint
'
);
}
return
response
.
deployments
;
});
}
}
}
}
changelogs/unreleased/refactor-monitoring-service.yml
0 → 100644
View file @
1f5ae8cd
---
title
:
Perform prometheus data endpoint requests in parallel
merge_request
:
14003
author
:
type
:
fixed
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