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.
This commit is contained in:
Matthias Radestock
2017-12-14 01:07:40 +00:00
parent 72b9e9c6b9
commit 70d84170d6

View File

@@ -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)