MCPcopy
hub / github.com/grafana/tempo / usageStatsHandler

Function usageStatsHandler

cmd/tempo/app/modules.go:852–873  ·  view source on GitHub ↗
(urCfg usagestats.Config)

Source from the content-addressed store, hash-verified

850}
851
852func usageStatsHandler(urCfg usagestats.Config) http.HandlerFunc {
853 if !urCfg.Enabled {
854 return func(w http.ResponseWriter, r *http.Request) {
855 http.Error(w, "usage-stats is not enabled", http.StatusOK)
856 }
857 }
858
859 // usage stats is Enabled, build and return usage stats json
860 reportBytes, err := json.Marshal(usagestats.BuildStats())
861 if err != nil {
862 return func(w http.ResponseWriter, r *http.Request) {
863 http.Error(w, "error building usage report", http.StatusInternalServerError)
864 }
865 }
866 reportStr := string(reportBytes)
867
868 return func(w http.ResponseWriter, r *http.Request) {
869 w.WriteHeader(http.StatusOK)
870 w.Header().Set("Content-Type", "application/json")
871 _, _ = io.WriteString(w, reportStr)
872 }
873}

Callers 1

initQueryFrontendMethod · 0.85

Calls 6

BuildStatsFunction · 0.92
ErrorMethod · 0.65
MarshalMethod · 0.65
SetMethod · 0.65
WriteHeaderMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected