mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
Add pipe/{pipeID}/check endpoint
This commit is contained in:
16
app/pipes.go
16
app/pipes.go
@@ -12,6 +12,10 @@ import (
|
||||
|
||||
// RegisterPipeRoutes registers the pipe routes
|
||||
func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) {
|
||||
router.Methods("GET").
|
||||
Path("/api/pipe/{pipeID}/check").
|
||||
HandlerFunc(requestContextDecorator(checkPipe(pr, UIEnd)))
|
||||
|
||||
router.Methods("GET").
|
||||
Path("/api/pipe/{pipeID}").
|
||||
HandlerFunc(requestContextDecorator(handlePipeWs(pr, UIEnd)))
|
||||
@@ -25,6 +29,18 @@ func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) {
|
||||
HandlerFunc(requestContextDecorator(deletePipe(pr)))
|
||||
}
|
||||
|
||||
func checkPipe(pr PipeRouter, end End) CtxHandlerFunc {
|
||||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
id := mux.Vars(r)["pipeID"]
|
||||
_, _, ok := pr.Get(ctx, id, end)
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
defer pr.Release(ctx, id, end)
|
||||
}
|
||||
}
|
||||
|
||||
func handlePipeWs(pr PipeRouter, end End) CtxHandlerFunc {
|
||||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
id := mux.Vars(r)["pipeID"]
|
||||
|
||||
@@ -214,16 +214,16 @@ export function deletePipe(pipeId) {
|
||||
}
|
||||
|
||||
export function getPipeStatus(pipeId) {
|
||||
const url = `/api/pipe/${encodeURIComponent(pipeId)}`;
|
||||
const url = `/api/pipe/${encodeURIComponent(pipeId)}/check`;
|
||||
reqwest({
|
||||
method: 'GET',
|
||||
url: url,
|
||||
success: function(res) {
|
||||
log('ERROR: expected responses: [400, 404]. Got:', res);
|
||||
log('ERROR: expected responses: [200, 404]. Got:', res);
|
||||
},
|
||||
error: function(err) {
|
||||
const status = {
|
||||
400: 'PIPE_ALIVE',
|
||||
200: 'PIPE_ALIVE',
|
||||
404: 'PIPE_DELETED'
|
||||
}[err.status];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user