@@ -14,23 +14,23 @@ use std::{
1414use crossbeam_queue:: SegQueue ;
1515use dashmap:: { DashMap , DashSet } ;
1616use tonic:: { service:: Interceptor , * } ;
17- use tracing:: { debug_span, instrument, Instrument } ;
17+ use tracing:: { debug_span, instrument, Instrument , Span } ;
1818use uuid:: Uuid ;
1919
20- use crate :: config:: { self , Judger as JudgerConfig } ;
20+ use crate :: config:: { self , Judger as JudgeConfig } ;
2121use grpc:: judger:: { judger_client:: * , * } ;
2222
2323// TODO: add tracing
2424
2525// about health score:
2626//
2727// health score is a number in range [-1,HEALTH_MAX_SCORE)
28- // Upstream with negitive health score is consider unhealthy, and should disconnect immediately
28+ // Upstream with negative health score is consider unhealthy, and should disconnect immediately
2929
3030/// Max score a health Upstream can reach
3131const HEALTH_MAX_SCORE : isize = 100 ;
3232
33- /// Judger Client intercepted by BasicAuthInterceptor
33+ /// Judge Client intercepted by BasicAuthInterceptor
3434type AuthJudgerClient = JudgerClient <
3535 service:: interceptor:: InterceptedService < transport:: Channel , BasicAuthInterceptor > ,
3636> ;
@@ -54,12 +54,12 @@ impl Interceptor for BasicAuthInterceptor {
5454 }
5555}
5656
57- #[ derive( Clone ) ]
57+ #[ derive( Clone , Debug ) ]
5858/// Info necessary to create connection, implement reuse logic
5959pub struct ConnectionDetail {
6060 pub uri : String ,
6161 pub secret : Option < String > ,
62- // TODO: reuse logic shouldn't be binded with connection creation logic
62+ // TODO: reuse logic shouldn't be bound with connection creation logic
6363 pub reuse : bool ,
6464}
6565
@@ -128,9 +128,10 @@ impl Drop for ConnGuard {
128128/// occupy future, should generally be spawn in a green thread
129129#[ instrument( skip( router) , level = "info" ) ]
130130async fn discover < I : Routable + Send > (
131- config : JudgerConfig ,
131+ config : JudgeConfig ,
132132 router : Weak < Router > ,
133133) -> Result < ( ) , Error > {
134+ let parent = Span :: current ( ) ;
134135 let mut instance = I :: new ( config. clone ( ) ) ?;
135136 loop {
136137 match instance. discover ( ) . in_current_span ( ) . await {
@@ -141,7 +142,7 @@ async fn discover<I: Routable + Send>(
141142 } ;
142143 let uri = detail. uri . clone ( ) ;
143144 let ( upstream, langs) = Upstream :: new ( detail) . in_current_span ( ) . await ?;
144- let _ = debug_span ! ( "connected" , uri = uri) . entered ( ) ;
145+ let _ = debug_span ! ( parent : parent . clone ( ) , "connected" , uri = uri) . entered ( ) ;
145146 for ( uuid, lang) in langs. into_iter ( ) {
146147 router. langs . insert ( lang) ;
147148 loop {
@@ -175,8 +176,8 @@ pub struct Router {
175176
176177impl Router {
177178 // skip because config contain basic auth secret
178- #[ instrument( name = "router_construct" , level = "info " , skip_all) ]
179- pub fn new ( config : Vec < JudgerConfig > ) -> Result < Arc < Self > , Error > {
179+ #[ instrument( name = "router_construct" , level = "debug " , skip_all) ]
180+ pub fn new ( config : Vec < JudgeConfig > ) -> Result < Arc < Self > , Error > {
180181 let self_ = Arc :: new ( Self {
181182 routing_table : DashMap :: default ( ) ,
182183 langs : DashSet :: default ( ) ,
@@ -235,6 +236,7 @@ pub struct Upstream {
235236
236237impl Upstream {
237238 /// create new Upstream
239+ #[ instrument( name = "connecting_upstream" , err, level = "info" ) ]
238240 async fn new ( detail : ConnectionDetail ) -> Result < ( Arc < Self > , Vec < ( Uuid , LangInfo ) > ) , Error > {
239241 let mut client = detail. connect ( ) . await ?;
240242 let info = client. judger_info ( ( ) ) . await ?;
@@ -245,7 +247,7 @@ impl Upstream {
245247 let uuid = match Uuid :: parse_str ( & lang. lang_uid ) {
246248 Ok ( x) => x,
247249 Err ( err) => {
248- log:: warn!( "invalid lang_uid from judger : {}" , err) ;
250+ log:: warn!( "invalid lang_uid from judge : {}" , err) ;
249251 continue ;
250252 }
251253 } ;
@@ -304,7 +306,7 @@ where
304306 // return new connection when available, will immediately retry true is returned
305307 async fn route ( & mut self ) -> Result < RouteStatus , Error > ;
306308 /// create from config
307- fn new ( config : JudgerConfig ) -> Result < Self , Error > ;
309+ fn new ( config : JudgeConfig ) -> Result < Self , Error > ;
308310}
309311
310312/// wrapper for Routable(Error handling)
0 commit comments