From 70d84170d6ca122db19e0a66fc57a4b1eb2c9bd8 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 14 Dec 2017 01:07:40 +0000 Subject: [PATCH] introduce a cheap /api/probes?sparse variant In many cases we only need to know whether there are _any_ connected probes, and not the probe details. Obtaining that info is cheaper since it requires no reading or merging or reports. --- app/api_report.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/api_report.go b/app/api_report.go index 6dfbd153d..d930a5373 100644 --- a/app/api_report.go +++ b/app/api_report.go @@ -32,6 +32,16 @@ type probeDesc struct { // Probe handler func makeProbeHandler(rep Reporter) CtxHandlerFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) { + r.ParseForm() + if _, sparse := r.Form["sparse"]; sparse { + // if we have reports, we must have connected probes + hasProbes, err := rep.HasReports(ctx, time.Now()) + if err != nil { + respondWith(w, http.StatusInternalServerError, err) + } + respondWith(w, http.StatusOK, hasProbes) + return + } rpt, err := rep.Report(ctx, time.Now()) if err != nil { respondWith(w, http.StatusInternalServerError, err)