MCPcopy Index your code
hub / github.com/cortexproject/cortex / ServeHTTP

Method ServeHTTP

tools/querytee/proxy_endpoint.go:52–72  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

50}
51
52func (p *ProxyEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
53 level.Debug(p.logger).Log("msg", "Received request", "path", r.URL.Path, "query", r.URL.RawQuery)
54
55 // Send the same request to all backends.
56 resCh := make(chan *backendResponse, len(p.backends))
57 go p.executeBackendRequests(r, resCh)
58
59 // Wait for the first response that's feasible to be sent back to the client.
60 downstreamRes := p.waitBackendResponseForDownstream(resCh)
61
62 if downstreamRes.err != nil {
63 http.Error(w, downstreamRes.err.Error(), http.StatusInternalServerError)
64 } else {
65 w.WriteHeader(downstreamRes.status)
66 if _, err := w.Write(downstreamRes.body); err != nil {
67 level.Warn(p.logger).Log("msg", "Unable to write response", "err", err)
68 }
69 }
70
71 p.metrics.responsesTotal.WithLabelValues(downstreamRes.backend.name, r.Method, p.routeName).Inc()
72}
73
74func (p *ProxyEndpoint) executeBackendRequests(r *http.Request, resCh chan *backendResponse) {
75 responses := make([]*backendResponse, 0, len(p.backends))

Callers 1

injectAuthHeaderFunction · 0.45

Calls 6

LogMethod · 0.45
ErrorMethod · 0.45
WriteMethod · 0.45
IncMethod · 0.45

Tested by

no test coverage detected