Skip to content

Commit a13a0c4

Browse files
committed
chore: address PR comments
Signed-off-by: Jacob Lisi <[email protected]>
1 parent 81a929b commit a13a0c4

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

pkg/api/handlers.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func NewQuerierHandler(
204204
InflightRequests: inflightRequests,
205205
}
206206
cacheGenHeaderMiddleware := getHTTPCacheGenNumberHeaderSetterMiddleware(tombstonesLoader)
207-
middlewares := middleware.Merge(fakeRemoteAddr(), inst, cacheGenHeaderMiddleware)
207+
middlewares := middleware.Merge(inst, cacheGenHeaderMiddleware)
208208
router.Use(middlewares.Wrap)
209209

210210
promRouter := route.New().WithPrefix(cfg.ServerPrefix + cfg.PrometheusHTTPPrefix + "/api/v1")
@@ -227,9 +227,7 @@ func NewQuerierHandler(
227227
// A prefix is fine because external routes will be registered explicitly
228228
router.PathPrefix(cfg.LegacyHTTPPrefix + "/api/v1/").Handler(legacyPromRouter)
229229

230-
// Since we have a new router and the request will not go trough the default server
231-
// HTTP middleware stack, we need to add a middleware to extract the trace context
232-
// from the HTTP headers and inject it into the Go context.
230+
// Add a middleware to extract the trace context and add a header.
233231
return nethttp.MiddlewareFunc(opentracing.GlobalTracer(), router.ServeHTTP, nethttp.OperationNameFunc(func(r *http.Request) string {
234232
return "internalQuerier"
235233
}))

pkg/api/middlewares.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@ import (
1010
"github.com/cortexproject/cortex/pkg/querier/queryrange"
1111
)
1212

13-
// Latest Prometheus requires r.RemoteAddr to be set to addr:port, otherwise it reject the request.
14-
// Requests to Querier sometimes doesn't have that (if they are fetched from Query-Frontend).
15-
// Prometheus uses this when logging queries to QueryLogger, but Cortex doesn't call engine.SetQueryLogger to set one.
16-
//
17-
// Can be removed when (if) https://github.com/prometheus/prometheus/pull/6840 is merged.
18-
func fakeRemoteAddr() middleware.Interface {
19-
return middleware.Func(func(next http.Handler) http.Handler {
20-
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
21-
if r.RemoteAddr == "" {
22-
r.RemoteAddr = "127.0.0.1:8888"
23-
}
24-
next.ServeHTTP(w, r)
25-
})
26-
})
27-
}
28-
2913
// middleware for setting cache gen header to let consumer of response know all previous responses could be invalid due to delete operation
3014
func getHTTPCacheGenNumberHeaderSetterMiddleware(cacheGenNumbersLoader *purger.TombstonesLoader) middleware.Interface {
3115
return middleware.Func(func(next http.Handler) http.Handler {

pkg/cortex/modules.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,17 @@ func (t *Cortex) initQueryable() (serv services.Service, err error) {
206206

207207
// initQuerier registers an internal HTTP router with a Prometheus API backed by the
208208
// Cortex Queryable. Then it does one of the following:
209+
//
209210
// 1. Query-Frontend Enabled: If Cortex has an All or QueryFrontend target, the internal
210211
// HTTP router is wrapped with Tenant ID parsing middleware and passed to the frontend
211212
// worker.
213+
//
212214
// 2. Querier Standalone: The querier will register the internal HTTP router with the external
213215
// HTTP router for the Prometheus API routes. Then the external HTTP server will be passed
214216
// as a http.Handler to the frontend worker.
217+
//
215218
// Route Diagram:
219+
//
216220
// │ query
217221
// │ request
218222
// │
@@ -249,6 +253,7 @@ func (t *Cortex) initQueryable() (serv services.Service, err error) {
249253
// └──────────────────────│ Prometheus API │
250254
// │ │
251255
// └──────────────────┘
256+
//
252257
func (t *Cortex) initQuerier() (serv services.Service, err error) {
253258
// Create a internal HTTP handler that is configured with the Prometheus API routes and points
254259
// to a Prometheus API struct instantiated with the Cortex Queryable.

0 commit comments

Comments
 (0)