MCPcopy Create free account
hub / github.com/couchbase/cbft / ServeHTTP

Method ServeHTTP

ns_server.go:554–592  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

552}
553
554func (h *NsStatsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
555 currentStatsCount := atomic.AddInt64(&h.statsCount, 1)
556 initNsServerCaching(h.mgr)
557
558 rd := getRecentInfo()
559 if rd.err != nil {
560 rest.ShowError(w, req, fmt.Sprintf("could not retrieve defs: %v", rd.err),
561 http.StatusInternalServerError)
562 return
563 }
564
565 nsIndexStats, err := gatherIndexStats(h.mgr, rd, false)
566 if err != nil {
567 rest.ShowError(w, req, fmt.Sprintf("error in retrieving defs: %v", err),
568 http.StatusInternalServerError)
569 return
570 }
571
572 if LogEveryNStats != 0 && currentStatsCount%int64(LogEveryNStats) == 0 {
573 go func() {
574 var buf bytes.Buffer
575 err := rest.WriteManagerStatsJSON(h.mgr, &buf, "")
576 if err != nil {
577 log.Warnf("error formatting managerStatsJSON for logs: %v", err)
578 } else {
579 log.Printf("managerStats: %s", buf.String())
580 }
581
582 statsJSON, err := json.MarshalIndent(nsIndexStats, "", " ")
583 if err != nil {
584 log.Warnf("error formatting JSON for logs: %v", err)
585 return
586 }
587 log.Printf("stats: %s", string(statsJSON))
588 }()
589 }
590
591 rest.MustEncode(w, nsIndexStats)
592}
593
594func addFeedStats(feed cbgt.Feed, nsIndexStat map[string]interface{}) error {
595 buffer := new(bytes.Buffer)

Callers

nothing calls this directly

Calls 4

initNsServerCachingFunction · 0.85
getRecentInfoFunction · 0.85
gatherIndexStatsFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected