@@ -21,7 +21,7 @@ use ceresdbproto::{
21
21
use common_util:: time:: InstantExt ;
22
22
use futures:: { stream, stream:: BoxStream , StreamExt } ;
23
23
use http:: StatusCode ;
24
- use proxy:: { Context , Proxy } ;
24
+ use proxy:: { Context , Proxy , FORWARDED_FROM } ;
25
25
use query_engine:: executor:: Executor as QueryExecutor ;
26
26
use table_engine:: engine:: EngineRuntimes ;
27
27
@@ -138,6 +138,10 @@ impl<Q: QueryExecutor + 'static> StorageService for StorageServiceImpl<Q> {
138
138
runtime : self . runtimes . read_runtime . clone ( ) ,
139
139
timeout : self . timeout ,
140
140
enable_partition_table_access : false ,
141
+ forwarded_from : req
142
+ . metadata ( )
143
+ . get ( FORWARDED_FROM )
144
+ . map ( |value| value. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
141
145
} ;
142
146
let stream = Self :: stream_sql_query_internal ( ctx, proxy, req) . await ;
143
147
@@ -155,13 +159,17 @@ impl<Q: QueryExecutor + 'static> StorageServiceImpl<Q> {
155
159
& self ,
156
160
req : tonic:: Request < RouteRequest > ,
157
161
) -> Result < tonic:: Response < RouteResponse > , tonic:: Status > {
158
- let req = req. into_inner ( ) ;
159
- let proxy = self . proxy . clone ( ) ;
160
162
let ctx = Context {
161
163
runtime : self . runtimes . read_runtime . clone ( ) ,
162
164
timeout : self . timeout ,
163
165
enable_partition_table_access : false ,
166
+ forwarded_from : req
167
+ . metadata ( )
168
+ . get ( FORWARDED_FROM )
169
+ . map ( |value| value. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
164
170
} ;
171
+ let req = req. into_inner ( ) ;
172
+ let proxy = self . proxy . clone ( ) ;
165
173
166
174
let join_handle = self
167
175
. runtimes
@@ -186,13 +194,17 @@ impl<Q: QueryExecutor + 'static> StorageServiceImpl<Q> {
186
194
& self ,
187
195
req : tonic:: Request < WriteRequest > ,
188
196
) -> Result < tonic:: Response < WriteResponse > , tonic:: Status > {
189
- let req = req. into_inner ( ) ;
190
- let proxy = self . proxy . clone ( ) ;
191
197
let ctx = Context {
192
198
runtime : self . runtimes . write_runtime . clone ( ) ,
193
199
timeout : self . timeout ,
194
200
enable_partition_table_access : false ,
201
+ forwarded_from : req
202
+ . metadata ( )
203
+ . get ( FORWARDED_FROM )
204
+ . map ( |value| value. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
195
205
} ;
206
+ let req = req. into_inner ( ) ;
207
+ let proxy = self . proxy . clone ( ) ;
196
208
197
209
let join_handle = self . runtimes . write_runtime . spawn ( async move {
198
210
if req. context . is_none ( ) {
@@ -226,13 +238,18 @@ impl<Q: QueryExecutor + 'static> StorageServiceImpl<Q> {
226
238
& self ,
227
239
req : tonic:: Request < SqlQueryRequest > ,
228
240
) -> Result < tonic:: Response < SqlQueryResponse > , tonic:: Status > {
229
- let req = req. into_inner ( ) ;
230
- let proxy = self . proxy . clone ( ) ;
231
241
let ctx = Context {
232
242
runtime : self . runtimes . read_runtime . clone ( ) ,
233
243
timeout : self . timeout ,
234
244
enable_partition_table_access : false ,
245
+ forwarded_from : req
246
+ . metadata ( )
247
+ . get ( FORWARDED_FROM )
248
+ . map ( |value| value. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
235
249
} ;
250
+ let req = req. into_inner ( ) ;
251
+ let proxy = self . proxy . clone ( ) ;
252
+
236
253
let join_handle = self
237
254
. runtimes
238
255
. read_runtime
@@ -289,13 +306,18 @@ impl<Q: QueryExecutor + 'static> StorageServiceImpl<Q> {
289
306
& self ,
290
307
req : tonic:: Request < PrometheusQueryRequest > ,
291
308
) -> Result < tonic:: Response < PrometheusQueryResponse > , tonic:: Status > {
292
- let req = req. into_inner ( ) ;
293
- let proxy = self . proxy . clone ( ) ;
294
309
let ctx = Context {
295
310
runtime : self . runtimes . read_runtime . clone ( ) ,
296
311
timeout : self . timeout ,
297
312
enable_partition_table_access : false ,
313
+ forwarded_from : req
314
+ . metadata ( )
315
+ . get ( FORWARDED_FROM )
316
+ . map ( |value| value. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
298
317
} ;
318
+ let req = req. into_inner ( ) ;
319
+ let proxy = self . proxy . clone ( ) ;
320
+
299
321
let join_handle = self . runtimes . read_runtime . spawn ( async move {
300
322
if req. context . is_none ( ) {
301
323
return PrometheusQueryResponse {
@@ -329,13 +351,17 @@ impl<Q: QueryExecutor + 'static> StorageServiceImpl<Q> {
329
351
) -> Result < tonic:: Response < WriteResponse > , tonic:: Status > {
330
352
let mut total_success = 0 ;
331
353
332
- let mut stream = req. into_inner ( ) ;
333
- let proxy = self . proxy . clone ( ) ;
334
354
let ctx = Context {
335
355
runtime : self . runtimes . write_runtime . clone ( ) ,
336
356
timeout : self . timeout ,
337
357
enable_partition_table_access : false ,
358
+ forwarded_from : req
359
+ . metadata ( )
360
+ . get ( FORWARDED_FROM )
361
+ . map ( |value| value. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
338
362
} ;
363
+ let mut stream = req. into_inner ( ) ;
364
+ let proxy = self . proxy . clone ( ) ;
339
365
340
366
let join_handle = self . runtimes . write_runtime . spawn ( async move {
341
367
let mut resp = WriteResponse :: default ( ) ;
0 commit comments