mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-18 03:46:45 +00:00
Review feedback, lint & fix tests.
This commit is contained in:
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func topologyServer() *httptest.Server {
|
||||
router := mux.NewRouter()
|
||||
app.RegisterTopologyRoutes(StaticReport{}, router)
|
||||
router := mux.NewRouter().SkipClean(true)
|
||||
app.RegisterTopologyRoutes(router, StaticReport{})
|
||||
return httptest.NewServer(router)
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestAPITopologyAddsKubernetes(t *testing.T) {
|
||||
router := mux.NewRouter()
|
||||
c := app.NewCollector(1 * time.Minute)
|
||||
app.RegisterReportPostHandler(c, router)
|
||||
app.RegisterTopologyRoutes(c, router)
|
||||
app.RegisterTopologyRoutes(router, c)
|
||||
ts := httptest.NewServer(router)
|
||||
defer ts.Close()
|
||||
|
||||
|
||||
+1
-8
@@ -80,14 +80,7 @@ func gzipHandler(h http.HandlerFunc) http.HandlerFunc {
|
||||
return handlers.GZIPHandlerFunc(h, nil)
|
||||
}
|
||||
|
||||
// TopologyHandler registers the various topology routes with a http mux.
|
||||
//
|
||||
// The returned http.Handler has to be passed directly to http.ListenAndServe,
|
||||
// and cannot be nested inside another gorrilla.mux.
|
||||
//
|
||||
// Routes which should be matched before the topology routes should be added
|
||||
// to a router and passed in preRoutes. Routes to be matches after topology
|
||||
// routes should be added to a router and passed to postRoutes.
|
||||
// RegisterTopologyRoutes registers the various topology routes with a http mux.
|
||||
func RegisterTopologyRoutes(router *mux.Router, r Reporter) {
|
||||
get := router.Methods("GET").Subrouter()
|
||||
get.HandleFunc("/api",
|
||||
|
||||
@@ -9,16 +9,15 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// Instrument is a Middleware which records timings for every HTTP request
|
||||
type Instrument struct {
|
||||
RouteMatcher RouteMatcher
|
||||
Duration *prometheus.SummaryVec
|
||||
}
|
||||
|
||||
// RouteMatcher is implemented by mux.Router.
|
||||
type RouteMatcher interface {
|
||||
Match(*http.Request, *mux.RouteMatch) bool
|
||||
RouteMatcher interface {
|
||||
Match(*http.Request, *mux.RouteMatch) bool
|
||||
}
|
||||
Duration *prometheus.SummaryVec
|
||||
}
|
||||
|
||||
// Wrap implements middleware.Interface
|
||||
func (i Instrument) Wrap(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
begin := time.Now()
|
||||
|
||||
+6
-6
@@ -138,11 +138,11 @@ func pipeRouterFactory(userIDer multitenant.UserIDer, pipeRouterURL, consulInf s
|
||||
// Main runs the app
|
||||
func appMain() {
|
||||
var (
|
||||
window = flag.Duration("window", 15*time.Second, "window")
|
||||
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
|
||||
logLevel = flag.String("log.level", "info", "logging threshold level: debug|info|warn|error|fatal|panic")
|
||||
logPrefix = flag.String("log.prefix", "<app>", "prefix for each log line")
|
||||
logRequests = flag.Bool("log.requests", false, "Log individual HTTP requests")
|
||||
window = flag.Duration("window", 15*time.Second, "window")
|
||||
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
|
||||
logLevel = flag.String("log.level", "info", "logging threshold level: debug|info|warn|error|fatal|panic")
|
||||
logPrefix = flag.String("log.prefix", "<app>", "prefix for each log line")
|
||||
logHTTP = flag.Bool("log.http", false, "Log individual HTTP requests")
|
||||
|
||||
weaveAddr = flag.String("weave.addr", app.DefaultWeaveURL, "Address on which to contact WeaveDNS")
|
||||
weaveHostname = flag.String("weave.hostname", app.DefaultHostname, "Hostname to advertise in WeaveDNS")
|
||||
@@ -219,7 +219,7 @@ func appMain() {
|
||||
}
|
||||
|
||||
handler := router(collector, controlRouter, pipeRouter)
|
||||
if *logRequests {
|
||||
if *logHTTP {
|
||||
handler = middleware.Logging.Wrap(handler)
|
||||
}
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user