@@ -10,6 +10,7 @@ use sqlx::{
1010 Pool , Postgres ,
1111 postgres:: { PgConnectOptions , PgPoolOptions , PgSslMode } ,
1212} ;
13+ use std:: fmt:: Debug ;
1314
1415pub type NodeId = i32 ;
1516pub type MeasurementId = i32 ;
@@ -25,6 +26,7 @@ macro_rules! query {
2526}
2627
2728impl DatabaseClient {
29+ #[ tracing:: instrument( name = "DatabaseClient::init()" , level = "debug" , err, skip_all) ]
2830 pub async fn new ( config : & Config ) -> Result < Self , Error > {
2931 let mut opts = PgConnectOptions :: new ( )
3032 . host ( & config. database . host )
@@ -45,6 +47,12 @@ impl DatabaseClient {
4547 Ok ( Self ( pool) )
4648 }
4749
50+ #[ tracing:: instrument(
51+ name = "DatabaseClient::setup_timezone()" ,
52+ level = "debug" ,
53+ skip( self ) ,
54+ err
55+ ) ]
4856 pub async fn setup_timezone ( & self , tz : & str ) -> Result < ( ) , Error > {
4957 if !self . validate_timezone ( tz) . await ? {
5058 return Err ( Error :: InvalidTimeZone ( tz. into ( ) ) ) ;
@@ -57,6 +65,13 @@ impl DatabaseClient {
5765 Ok ( ( ) )
5866 }
5967
68+ #[ tracing:: instrument(
69+ name = "DatabaseClient::authorize_device()" ,
70+ level = "debug" ,
71+ skip( self ) ,
72+ err,
73+ ret
74+ ) ]
6075 pub async fn authorize_device ( & self , mac : & Mac ) -> Result < Option < NodeId > , Error > {
6176 let mac = mac. to_string ( ) ;
6277
@@ -68,6 +83,12 @@ impl DatabaseClient {
6883 }
6984 }
7085
86+ #[ tracing:: instrument(
87+ name = "DatabaseClient::create_notification()" ,
88+ level = "debug" ,
89+ skip( self ) ,
90+ err
91+ ) ]
7192 pub async fn create_notification ( & self , node_id : NodeId , content : & str ) -> Result < ( ) , Error > {
7293 query ! (
7394 self . 0 ,
@@ -80,6 +101,13 @@ impl DatabaseClient {
80101 Ok ( ( ) )
81102 }
82103
104+ #[ tracing:: instrument(
105+ name = "DatabaseClient::get_settings()" ,
106+ level = "debug" ,
107+ skip( self ) ,
108+ err,
109+ ret
110+ ) ]
83111 pub async fn get_settings ( & self , node_id : NodeId ) -> Result < Option < NodeSettings > , Error > {
84112 let result = query ! (
85113 self . 0 ,
@@ -101,6 +129,13 @@ impl DatabaseClient {
101129 }
102130 }
103131
132+ #[ tracing:: instrument(
133+ name = "DatabaseClient::post_results()" ,
134+ level = "debug" ,
135+ skip( self ) ,
136+ err,
137+ ret
138+ ) ]
104139 pub async fn post_results (
105140 & self ,
106141 node : NodeId ,
@@ -126,6 +161,12 @@ impl DatabaseClient {
126161 Ok ( result. id )
127162 }
128163
164+ #[ tracing:: instrument(
165+ name = "DatabaseClient::post_stats()" ,
166+ level = "debug" ,
167+ skip( self ) ,
168+ err
169+ ) ]
129170 pub async fn post_stats (
130171 & self ,
131172 measurement : MeasurementId ,
@@ -146,12 +187,24 @@ impl DatabaseClient {
146187 Ok ( ( ) )
147188 }
148189
190+ #[ tracing:: instrument(
191+ name = "DatabaseClient::run_migrations()" ,
192+ level = "debug" ,
193+ skip( self ) ,
194+ err
195+ ) ]
149196 pub async fn run_migrations ( & self ) -> Result < ( ) , Error > {
150197 crate :: MIGRATOR . run ( & self . 0 ) . await ?;
151198
152199 Ok ( ( ) )
153200 }
154201
202+ #[ tracing:: instrument(
203+ name = "DatabaseClient::check_os_update()" ,
204+ level = "debug" ,
205+ skip( self ) ,
206+ err
207+ ) ]
155208 pub async fn check_os_update (
156209 & self ,
157210 node : NodeId ,
@@ -183,6 +236,13 @@ impl DatabaseClient {
183236 }
184237 }
185238
239+ #[ tracing:: instrument(
240+ name = "DatabaseClient::send_os_update_stat()" ,
241+ level = "debug" ,
242+ skip( self ) ,
243+ err,
244+ ret
245+ ) ]
186246 pub async fn send_os_update_stat (
187247 & self ,
188248 node_id : NodeId ,
@@ -208,6 +268,12 @@ impl DatabaseClient {
208268 Ok ( result. id )
209269 }
210270
271+ #[ tracing:: instrument(
272+ name = "DatabaseClient::mark_os_update_stat()" ,
273+ level = "debug" ,
274+ skip( self ) ,
275+ err
276+ ) ]
211277 pub async fn mark_os_update_stat ( & self , node_id : NodeId , success : bool ) -> Result < ( ) , Error > {
212278 let last_update_id = self . get_last_os_update_stat ( node_id) . await ?;
213279 query ! (
@@ -221,6 +287,7 @@ impl DatabaseClient {
221287 Ok ( ( ) )
222288 }
223289
290+ #[ tracing:: instrument( name = "DatabaseClient::erase()" , level = "debug" , skip( self ) , err) ]
224291 pub async fn erase ( & self , content_only : bool , keep_devices : bool ) -> Result < ( ) , Error > {
225292 if content_only {
226293 if keep_devices {
@@ -247,6 +314,13 @@ impl DatabaseClient {
247314 Ok ( ( ) )
248315 }
249316
317+ #[ tracing:: instrument(
318+ name = "DatabaseClient::get_last_os_update_stat()" ,
319+ level = "debug" ,
320+ skip( self ) ,
321+ err,
322+ ret
323+ ) ]
250324 async fn get_last_os_update_stat ( & self , node_id : NodeId ) -> Result < UpdateStatId , Error > {
251325 Ok ( query ! (
252326 self . 0 ,
@@ -257,6 +331,12 @@ impl DatabaseClient {
257331 . id )
258332 }
259333
334+ #[ tracing:: instrument(
335+ name = "DatabaseClient::get_supported_time_zones()" ,
336+ level = "debug" ,
337+ skip( self ) ,
338+ err
339+ ) ]
260340 async fn get_supported_time_zones ( & self ) -> Result < Vec < String > , Error > {
261341 let results = query ! ( self . 0 , "queries/get_tz_names.sql" , fetch_all, ) ?;
262342 let names: Vec < String > = results
@@ -267,7 +347,14 @@ impl DatabaseClient {
267347 Ok ( names)
268348 }
269349
270- async fn validate_timezone < S : PartialEq < String > > ( & self , tz : S ) -> Result < bool , Error > {
350+ #[ tracing:: instrument(
351+ name = "DatabaseClient::validate_timezone()" ,
352+ level = "debug" ,
353+ skip( self , tz) ,
354+ err,
355+ ret /* this will print `tz` too */
356+ ) ]
357+ async fn validate_timezone < S : PartialEq < String > + Debug > ( & self , tz : S ) -> Result < bool , Error > {
271358 let supported = self . get_supported_time_zones ( ) . await ?;
272359
273360 Ok ( supported. iter ( ) . any ( |candidate| tz. eq ( candidate) ) )
0 commit comments