@@ -10,6 +10,7 @@ use sqlx::{
10
10
Pool , Postgres ,
11
11
postgres:: { PgConnectOptions , PgPoolOptions , PgSslMode } ,
12
12
} ;
13
+ use std:: fmt:: Debug ;
13
14
14
15
pub type NodeId = i32 ;
15
16
pub type MeasurementId = i32 ;
@@ -25,6 +26,7 @@ macro_rules! query {
25
26
}
26
27
27
28
impl DatabaseClient {
29
+ #[ tracing:: instrument( name = "DatabaseClient::init()" , level = "debug" , err, skip_all) ]
28
30
pub async fn new ( config : & Config ) -> Result < Self , Error > {
29
31
let mut opts = PgConnectOptions :: new ( )
30
32
. host ( & config. database . host )
@@ -45,6 +47,12 @@ impl DatabaseClient {
45
47
Ok ( Self ( pool) )
46
48
}
47
49
50
+ #[ tracing:: instrument(
51
+ name = "DatabaseClient::setup_timezone()" ,
52
+ level = "debug" ,
53
+ skip( self ) ,
54
+ err
55
+ ) ]
48
56
pub async fn setup_timezone ( & self , tz : & str ) -> Result < ( ) , Error > {
49
57
if !self . validate_timezone ( tz) . await ? {
50
58
return Err ( Error :: InvalidTimeZone ( tz. into ( ) ) ) ;
@@ -57,6 +65,13 @@ impl DatabaseClient {
57
65
Ok ( ( ) )
58
66
}
59
67
68
+ #[ tracing:: instrument(
69
+ name = "DatabaseClient::authorize_device()" ,
70
+ level = "debug" ,
71
+ skip( self ) ,
72
+ err,
73
+ ret
74
+ ) ]
60
75
pub async fn authorize_device ( & self , mac : & Mac ) -> Result < Option < NodeId > , Error > {
61
76
let mac = mac. to_string ( ) ;
62
77
@@ -68,6 +83,12 @@ impl DatabaseClient {
68
83
}
69
84
}
70
85
86
+ #[ tracing:: instrument(
87
+ name = "DatabaseClient::create_notification()" ,
88
+ level = "debug" ,
89
+ skip( self ) ,
90
+ err
91
+ ) ]
71
92
pub async fn create_notification ( & self , node_id : NodeId , content : & str ) -> Result < ( ) , Error > {
72
93
query ! (
73
94
self . 0 ,
@@ -80,6 +101,13 @@ impl DatabaseClient {
80
101
Ok ( ( ) )
81
102
}
82
103
104
+ #[ tracing:: instrument(
105
+ name = "DatabaseClient::get_settings()" ,
106
+ level = "debug" ,
107
+ skip( self ) ,
108
+ err,
109
+ ret
110
+ ) ]
83
111
pub async fn get_settings ( & self , node_id : NodeId ) -> Result < Option < NodeSettings > , Error > {
84
112
let result = query ! (
85
113
self . 0 ,
@@ -101,6 +129,13 @@ impl DatabaseClient {
101
129
}
102
130
}
103
131
132
+ #[ tracing:: instrument(
133
+ name = "DatabaseClient::post_results()" ,
134
+ level = "debug" ,
135
+ skip( self ) ,
136
+ err,
137
+ ret
138
+ ) ]
104
139
pub async fn post_results (
105
140
& self ,
106
141
node : NodeId ,
@@ -126,6 +161,12 @@ impl DatabaseClient {
126
161
Ok ( result. id )
127
162
}
128
163
164
+ #[ tracing:: instrument(
165
+ name = "DatabaseClient::post_stats()" ,
166
+ level = "debug" ,
167
+ skip( self ) ,
168
+ err
169
+ ) ]
129
170
pub async fn post_stats (
130
171
& self ,
131
172
measurement : MeasurementId ,
@@ -146,12 +187,24 @@ impl DatabaseClient {
146
187
Ok ( ( ) )
147
188
}
148
189
190
+ #[ tracing:: instrument(
191
+ name = "DatabaseClient::run_migrations()" ,
192
+ level = "debug" ,
193
+ skip( self ) ,
194
+ err
195
+ ) ]
149
196
pub async fn run_migrations ( & self ) -> Result < ( ) , Error > {
150
197
crate :: MIGRATOR . run ( & self . 0 ) . await ?;
151
198
152
199
Ok ( ( ) )
153
200
}
154
201
202
+ #[ tracing:: instrument(
203
+ name = "DatabaseClient::check_os_update()" ,
204
+ level = "debug" ,
205
+ skip( self ) ,
206
+ err
207
+ ) ]
155
208
pub async fn check_os_update (
156
209
& self ,
157
210
node : NodeId ,
@@ -183,6 +236,13 @@ impl DatabaseClient {
183
236
}
184
237
}
185
238
239
+ #[ tracing:: instrument(
240
+ name = "DatabaseClient::send_os_update_stat()" ,
241
+ level = "debug" ,
242
+ skip( self ) ,
243
+ err,
244
+ ret
245
+ ) ]
186
246
pub async fn send_os_update_stat (
187
247
& self ,
188
248
node_id : NodeId ,
@@ -208,6 +268,12 @@ impl DatabaseClient {
208
268
Ok ( result. id )
209
269
}
210
270
271
+ #[ tracing:: instrument(
272
+ name = "DatabaseClient::mark_os_update_stat()" ,
273
+ level = "debug" ,
274
+ skip( self ) ,
275
+ err
276
+ ) ]
211
277
pub async fn mark_os_update_stat ( & self , node_id : NodeId , success : bool ) -> Result < ( ) , Error > {
212
278
let last_update_id = self . get_last_os_update_stat ( node_id) . await ?;
213
279
query ! (
@@ -221,6 +287,7 @@ impl DatabaseClient {
221
287
Ok ( ( ) )
222
288
}
223
289
290
+ #[ tracing:: instrument( name = "DatabaseClient::erase()" , level = "debug" , skip( self ) , err) ]
224
291
pub async fn erase ( & self , content_only : bool , keep_devices : bool ) -> Result < ( ) , Error > {
225
292
if content_only {
226
293
if keep_devices {
@@ -247,6 +314,13 @@ impl DatabaseClient {
247
314
Ok ( ( ) )
248
315
}
249
316
317
+ #[ tracing:: instrument(
318
+ name = "DatabaseClient::get_last_os_update_stat()" ,
319
+ level = "debug" ,
320
+ skip( self ) ,
321
+ err,
322
+ ret
323
+ ) ]
250
324
async fn get_last_os_update_stat ( & self , node_id : NodeId ) -> Result < UpdateStatId , Error > {
251
325
Ok ( query ! (
252
326
self . 0 ,
@@ -257,6 +331,12 @@ impl DatabaseClient {
257
331
. id )
258
332
}
259
333
334
+ #[ tracing:: instrument(
335
+ name = "DatabaseClient::get_supported_time_zones()" ,
336
+ level = "debug" ,
337
+ skip( self ) ,
338
+ err
339
+ ) ]
260
340
async fn get_supported_time_zones ( & self ) -> Result < Vec < String > , Error > {
261
341
let results = query ! ( self . 0 , "queries/get_tz_names.sql" , fetch_all, ) ?;
262
342
let names: Vec < String > = results
@@ -267,7 +347,14 @@ impl DatabaseClient {
267
347
Ok ( names)
268
348
}
269
349
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 > {
271
358
let supported = self . get_supported_time_zones ( ) . await ?;
272
359
273
360
Ok ( supported. iter ( ) . any ( |candidate| tz. eq ( candidate) ) )
0 commit comments