1
1
use arc_swap:: ArcSwap ;
2
2
/// Statistics and reporting.
3
- use log:: info;
3
+ use log:: { error , info, trace } ;
4
4
use once_cell:: sync:: Lazy ;
5
5
use parking_lot:: Mutex ;
6
6
use std:: collections:: HashMap ;
7
+ use tokio:: sync:: mpsc:: error:: TrySendError ;
7
8
use tokio:: sync:: mpsc:: { channel, Receiver , Sender } ;
8
9
9
10
use crate :: pool:: get_number_of_addresses;
@@ -43,7 +44,7 @@ enum EventName {
43
44
44
45
/// Event data sent to the collector
45
46
/// from clients and servers.
46
- #[ derive( Debug ) ]
47
+ #[ derive( Debug , Clone ) ]
47
48
pub struct Event {
48
49
/// The name of the event being reported.
49
50
name : EventName ,
@@ -79,6 +80,25 @@ impl Reporter {
79
80
Reporter { tx : tx }
80
81
}
81
82
83
+ /// Send statistics to the task keeping track of stats.
84
+ fn send ( & self , event : Event ) {
85
+ let name = event. name ;
86
+ let result = self . tx . try_send ( event) ;
87
+
88
+ match result {
89
+ Ok ( _) => trace ! (
90
+ "{:?} event reported successfully, capacity: {}" ,
91
+ name,
92
+ self . tx. capacity( )
93
+ ) ,
94
+
95
+ Err ( err) => match err {
96
+ TrySendError :: Full { .. } => error ! ( "{:?} event dropped, buffer full" , name) ,
97
+ TrySendError :: Closed { .. } => error ! ( "{:?} event dropped, channel closed" , name) ,
98
+ } ,
99
+ } ;
100
+ }
101
+
82
102
/// Report a query executed by a client against
83
103
/// a server identified by the `address_id`.
84
104
pub fn query ( & self , process_id : i32 , address_id : usize ) {
@@ -89,7 +109,7 @@ impl Reporter {
89
109
address_id : address_id,
90
110
} ;
91
111
92
- let _ = self . tx . try_send ( event) ;
112
+ self . send ( event) ;
93
113
}
94
114
95
115
/// Report a transaction executed by a client against
@@ -102,7 +122,7 @@ impl Reporter {
102
122
address_id : address_id,
103
123
} ;
104
124
105
- let _ = self . tx . try_send ( event) ;
125
+ self . send ( event)
106
126
}
107
127
108
128
/// Report data sent to a server identified by `address_id`.
@@ -115,7 +135,7 @@ impl Reporter {
115
135
address_id : address_id,
116
136
} ;
117
137
118
- let _ = self . tx . try_send ( event) ;
138
+ self . send ( event)
119
139
}
120
140
121
141
/// Report data received from a server identified by `address_id`.
@@ -128,7 +148,7 @@ impl Reporter {
128
148
address_id : address_id,
129
149
} ;
130
150
131
- let _ = self . tx . try_send ( event) ;
151
+ self . send ( event)
132
152
}
133
153
134
154
/// Time spent waiting to get a healthy connection from the pool
@@ -142,7 +162,7 @@ impl Reporter {
142
162
address_id : address_id,
143
163
} ;
144
164
145
- let _ = self . tx . try_send ( event) ;
165
+ self . send ( event)
146
166
}
147
167
148
168
/// Reports a client identified by `process_id` waiting for a connection
@@ -155,7 +175,7 @@ impl Reporter {
155
175
address_id : address_id,
156
176
} ;
157
177
158
- let _ = self . tx . try_send ( event) ;
178
+ self . send ( event)
159
179
}
160
180
161
181
/// Reports a client identified by `process_id` is done waiting for a connection
@@ -168,7 +188,7 @@ impl Reporter {
168
188
address_id : address_id,
169
189
} ;
170
190
171
- let _ = self . tx . try_send ( event) ;
191
+ self . send ( event)
172
192
}
173
193
174
194
/// Reports a client identified by `process_id` is done querying the server
@@ -181,7 +201,7 @@ impl Reporter {
181
201
address_id : address_id,
182
202
} ;
183
203
184
- let _ = self . tx . try_send ( event) ;
204
+ self . send ( event)
185
205
}
186
206
187
207
/// Reports a client identified by `process_id` is disconecting from the pooler.
@@ -194,7 +214,7 @@ impl Reporter {
194
214
address_id : address_id,
195
215
} ;
196
216
197
- let _ = self . tx . try_send ( event) ;
217
+ self . send ( event)
198
218
}
199
219
200
220
/// Reports a server connection identified by `process_id` for
@@ -208,7 +228,7 @@ impl Reporter {
208
228
address_id : address_id,
209
229
} ;
210
230
211
- let _ = self . tx . try_send ( event) ;
231
+ self . send ( event)
212
232
}
213
233
214
234
/// Reports a server connection identified by `process_id` for
@@ -222,7 +242,7 @@ impl Reporter {
222
242
address_id : address_id,
223
243
} ;
224
244
225
- let _ = self . tx . try_send ( event) ;
245
+ self . send ( event)
226
246
}
227
247
228
248
/// Reports a server connection identified by `process_id` for
@@ -236,7 +256,7 @@ impl Reporter {
236
256
address_id : address_id,
237
257
} ;
238
258
239
- let _ = self . tx . try_send ( event) ;
259
+ self . send ( event)
240
260
}
241
261
242
262
/// Reports a server connection identified by `process_id` for
@@ -250,7 +270,7 @@ impl Reporter {
250
270
address_id : address_id,
251
271
} ;
252
272
253
- let _ = self . tx . try_send ( event) ;
273
+ self . send ( event)
254
274
}
255
275
256
276
/// Reports a server connection identified by `process_id` is disconecting from the pooler.
@@ -263,7 +283,7 @@ impl Reporter {
263
283
address_id : address_id,
264
284
} ;
265
285
266
- let _ = self . tx . try_send ( event) ;
286
+ self . send ( event)
267
287
}
268
288
}
269
289
0 commit comments