diff --git a/app/api_report_test.go b/app/api_report_test.go index 97d2fcc56..1d7bd2b69 100644 --- a/app/api_report_test.go +++ b/app/api_report_test.go @@ -14,7 +14,7 @@ import ( func topologyServer() *httptest.Server { router := mux.NewRouter().SkipClean(true) - app.RegisterTopologyRoutes(router, app.StaticCollector(fixture.Report)) + app.RegisterTopologyRoutes(router, app.StaticCollector(fixture.Report), map[string]bool{"foo_capability": true}) return httptest.NewServer(router) } diff --git a/app/api_topologies_test.go b/app/api_topologies_test.go index 09e25e350..6a5ec88f1 100644 --- a/app/api_topologies_test.go +++ b/app/api_topologies_test.go @@ -189,7 +189,7 @@ func TestAPITopologyAddsKubernetes(t *testing.T) { router := mux.NewRouter() c := app.NewCollector(1 * time.Minute) app.RegisterReportPostHandler(c, router) - app.RegisterTopologyRoutes(router, c) + app.RegisterTopologyRoutes(router, c, map[string]bool{"foo_capability": true}) ts := httptest.NewServer(router) defer ts.Close() diff --git a/app/router.go b/app/router.go index 0bfbbd4d5..73cbccb2d 100644 --- a/app/router.go +++ b/app/router.go @@ -90,10 +90,10 @@ func gzipHandler(h http.HandlerFunc) http.HandlerFunc { } // RegisterTopologyRoutes registers the various topology routes with a http mux. -func RegisterTopologyRoutes(router *mux.Router, r Reporter) { +func RegisterTopologyRoutes(router *mux.Router, r Reporter, capabilities map[string]bool) { get := router.Methods("GET").Subrouter() get.HandleFunc("/api", - gzipHandler(requestContextDecorator(apiHandler(r)))) + gzipHandler(requestContextDecorator(apiHandler(r, capabilities)))) get.HandleFunc("/api/topology", gzipHandler(requestContextDecorator(topologyRegistry.makeTopologyList(r)))) get. @@ -177,7 +177,7 @@ func NewVersion(version, downloadURL string) { } } -func apiHandler(rep Reporter) CtxHandlerFunc { +func apiHandler(rep Reporter, capabilities map[string]bool) CtxHandlerFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) { report, err := rep.Report(ctx) if err != nil { @@ -187,11 +187,12 @@ func apiHandler(rep Reporter) CtxHandlerFunc { newVersion.Lock() defer newVersion.Unlock() respondWith(w, http.StatusOK, xfer.Details{ - ID: UniqueID, - Version: Version, - Hostname: hostname.Get(), - Plugins: report.Plugins, - NewVersion: newVersion.NewVersionInfo, + ID: UniqueID, + Version: Version, + Hostname: hostname.Get(), + Plugins: report.Plugins, + Capabilities: capabilities, + NewVersion: newVersion.NewVersionInfo, }) } } diff --git a/common/xfer/constants.go b/common/xfer/constants.go index 3ae0c9e84..f88d688db 100644 --- a/common/xfer/constants.go +++ b/common/xfer/constants.go @@ -14,12 +14,15 @@ const ( ScopeProbeVersionHeader = "X-Scope-Probe-Version" ) +const ReportPersistenceCapability = "report_persistence" + // Details are some generic details that can be fetched from /api type Details struct { - ID string `json:"id"` - Version string `json:"version"` - Hostname string `json:"hostname"` - Plugins PluginSpecs `json:"plugins,omitempty"` + ID string `json:"id"` + Version string `json:"version"` + Hostname string `json:"hostname"` + Plugins PluginSpecs `json:"plugins,omitempty"` + Capabilities map[string]bool `json:"capabilities,omitempty"` NewVersion *NewVersionInfo `json:"newVersion,omitempty"` } diff --git a/prog/app.go b/prog/app.go index 1fb28d5c1..fa0755c9c 100644 --- a/prog/app.go +++ b/prog/app.go @@ -19,6 +19,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/tylerb/graceful" "github.com/weaveworks/go-checkpoint" + "github.com/weaveworks/scope/common/xfer" "github.com/weaveworks/weave/common" billing "github.com/weaveworks/billing-client" @@ -50,7 +51,7 @@ func init() { } // Router creates the mux for all the various app components. -func router(collector app.Collector, controlRouter app.ControlRouter, pipeRouter app.PipeRouter, externalUI bool) http.Handler { +func router(collector app.Collector, controlRouter app.ControlRouter, pipeRouter app.PipeRouter, externalUI bool, capabilities map[string]bool) http.Handler { router := mux.NewRouter().SkipClean(true) // We pull in the http.DefaultServeMux to get the pprof routes @@ -60,7 +61,7 @@ func router(collector app.Collector, controlRouter app.ControlRouter, pipeRouter app.RegisterReportPostHandler(collector, router) app.RegisterControlRoutes(router, controlRouter) app.RegisterPipeRoutes(router, pipeRouter) - app.RegisterTopologyRoutes(router, collector) + app.RegisterTopologyRoutes(router, collector, capabilities) uiHandler := http.FileServer(GetFS(externalUI)) router.PathPrefix("/ui").Name("static").Handler( @@ -294,7 +295,10 @@ func appMain(flags appFlags) { } } - handler := router(collector, controlRouter, pipeRouter, flags.externalUI) + capabilities := map[string]bool{ + xfer.ReportPersistenceCapability: flags.s3URL != "local", + } + handler := router(collector, controlRouter, pipeRouter, flags.externalUI, capabilities) if flags.logHTTP { handler = middleware.Log{ LogRequestHeaders: flags.logHTTPHeaders,