@@ -41,6 +41,9 @@ var Config = struct {
41
41
TimeoutMs int
42
42
TimeoutMsAfterAllStarted int
43
43
44
+ SearchBackend string
45
+ SearchPrefix string
46
+
44
47
GraphiteHost string
45
48
46
49
pathCache pathCache
@@ -67,6 +70,8 @@ var Metrics = struct {
67
70
FindRequests * expvar.Int
68
71
FindErrors * expvar.Int
69
72
73
+ SearchRequests * expvar.Int
74
+
70
75
RenderRequests * expvar.Int
71
76
RenderErrors * expvar.Int
72
77
@@ -81,6 +86,8 @@ var Metrics = struct {
81
86
FindRequests : expvar .NewInt ("find_requests" ),
82
87
FindErrors : expvar .NewInt ("find_errors" ),
83
88
89
+ SearchRequests : expvar .NewInt ("search_requests" ),
90
+
84
91
RenderRequests : expvar .NewInt ("render_requests" ),
85
92
RenderErrors : expvar .NewInt ("render_errors" ),
86
93
@@ -294,38 +301,62 @@ func findHandler(w http.ResponseWriter, req *http.Request) {
294
301
295
302
Metrics .FindRequests .Add (1 )
296
303
304
+ queries := []string {req .FormValue ("query" )}
305
+
297
306
rewrite , _ := url .ParseRequestURI (req .URL .RequestURI ())
298
307
v := rewrite .Query ()
299
308
format := req .FormValue ("format" )
300
309
v .Set ("format" , "protobuf" )
301
310
rewrite .RawQuery = v .Encode ()
302
311
303
- query := req .FormValue ("query" )
304
- var tld string
305
- if i := strings .IndexByte (query , '.' ); i > 0 {
306
- tld = query [:i ]
307
- }
308
- // lookup tld in our map of where they live to reduce the set of
309
- // servers we bug with our find
310
- var backends []string
311
- var ok bool
312
- if backends , ok = Config .pathCache .get (tld ); ! ok || backends == nil || len (backends ) == 0 {
313
- backends = Config .Backends
312
+ if strings .HasPrefix (queries [0 ], Config .SearchPrefix ) {
313
+ Metrics .SearchRequests .Add (1 )
314
+ // Send query to SearchBackend. The result is []queries for StorageBackends
315
+ searchResponse := multiGet ([]string {Config .SearchBackend }, rewrite .RequestURI ())
316
+ m , _ := findUnpackPB (req , searchResponse )
317
+ queries = make ([]string , 0 , len (m ))
318
+ for _ , v := range m {
319
+ queries = append (queries , * v .Path )
320
+ }
314
321
}
315
322
316
- responses := multiGet (backends , rewrite .RequestURI ())
323
+ var metrics []* pb.GlobMatch
324
+ // TODO(nnuss): Rewrite the result queries to a series of brace expansions based on TLD?
325
+ // [a.b, a.c, a.dee.eee.eff, x.y] => [ "a.{b,c,dee.eee.eff}", "x.y" ]
326
+ // Be mindful that carbonserver's default MaxGlobs is 10
327
+ for _ , query := range queries {
317
328
318
- if len (responses ) == 0 {
319
- logger .Logln ("find: error querying backends for: " , rewrite .RequestURI ())
320
- http .Error (w , "find: error querying backends" , http .StatusInternalServerError )
321
- return
322
- }
329
+ v .Set ("query" , query )
330
+ rewrite .RawQuery = v .Encode ()
323
331
324
- metrics , paths := findUnpackPB (req , responses )
332
+ var tld string
333
+ if i := strings .IndexByte (query , '.' ); i > 0 {
334
+ tld = query [:i ]
335
+ }
325
336
326
- // update our cache of which servers have which metrics
327
- for k , v := range paths {
328
- Config .pathCache .set (k , v )
337
+ // lookup tld in our map of where they live to reduce the set of
338
+ // servers we bug with our find
339
+ var backends []string
340
+ var ok bool
341
+ if backends , ok = Config .pathCache .get (tld ); ! ok || backends == nil || len (backends ) == 0 {
342
+ backends = Config .Backends
343
+ }
344
+
345
+ responses := multiGet (backends , rewrite .RequestURI ())
346
+
347
+ if len (responses ) == 0 {
348
+ logger .Logln ("find: error querying backends for: " , rewrite .RequestURI ())
349
+ http .Error (w , "find: error querying backends" , http .StatusInternalServerError )
350
+ return
351
+ }
352
+
353
+ m , paths := findUnpackPB (req , responses )
354
+ metrics = append (metrics , m ... )
355
+
356
+ // update our cache of which servers have which metrics
357
+ for k , v := range paths {
358
+ Config .pathCache .set (k , v )
359
+ }
329
360
}
330
361
331
362
switch format {
0 commit comments