(w http.ResponseWriter, r *http.Request)
| 587 | } |
| 588 | |
| 589 | func (p *Prober) RunAllHandler(w http.ResponseWriter, r *http.Request) error { |
| 590 | excluded := r.URL.Query()["exclude"] |
| 591 | |
| 592 | probes := make(map[string]*Probe) |
| 593 | p.mu.Lock() |
| 594 | for _, probe := range p.probes { |
| 595 | if !probe.IsContinuous() && !slices.Contains(excluded, probe.name) { |
| 596 | probes[probe.name] = probe |
| 597 | } |
| 598 | } |
| 599 | p.mu.Unlock() |
| 600 | |
| 601 | // Do not abort running probes just because one of them has failed. |
| 602 | g := new(errgroup.Group) |
| 603 | |
| 604 | var resultsMu sync.Mutex |
| 605 | results := make(map[string]RunHandlerResponse) |
| 606 | |
| 607 | for name, probe := range probes { |
| 608 | g.Go(func() error { |
| 609 | probe.mu.Lock() |
| 610 | prevInfo := probe.probeInfoLocked() |
| 611 | probe.mu.Unlock() |
| 612 | |
| 613 | info, err := probe.run() |
| 614 | |
| 615 | resultsMu.Lock() |
| 616 | results[name] = RunHandlerResponse{ |
| 617 | ProbeInfo: info, |
| 618 | PreviousSuccessRatio: prevInfo.RecentSuccessRatio(), |
| 619 | PreviousMedianLatency: prevInfo.RecentMedianLatency(), |
| 620 | } |
| 621 | resultsMu.Unlock() |
| 622 | return err |
| 623 | }) |
| 624 | } |
| 625 | |
| 626 | respStatus := http.StatusOK |
| 627 | if err := g.Wait(); err != nil { |
| 628 | respStatus = http.StatusFailedDependency |
| 629 | } |
| 630 | |
| 631 | // Return serialized JSON response if the client requested JSON |
| 632 | resp := &RunHandlerAllResponse{ |
| 633 | Results: results, |
| 634 | } |
| 635 | var b bytes.Buffer |
| 636 | if err := json.NewEncoder(&b).Encode(resp); err != nil { |
| 637 | return tsweb.Error(http.StatusInternalServerError, "error encoding JSON response", err) |
| 638 | } |
| 639 | |
| 640 | w.Header().Set("Content-Type", "application/json") |
| 641 | w.WriteHeader(respStatus) |
| 642 | w.Write(b.Bytes()) |
| 643 | |
| 644 | return nil |
| 645 | } |
| 646 |
nothing calls this directly
no test coverage detected