14
14
* limitations under the License.
15
15
*/
16
16
17
- use prometheus:: { exponential_buckets, Histogram } ;
18
-
19
17
use crate :: {
20
18
config:: Filter as FilterConfig ,
21
19
filters:: { prelude:: * , FilterRegistry } ,
22
- metrics:: { histogram_opts, CollectorExt } ,
23
20
} ;
24
21
25
- const FILTER_LABEL : & str = "filter" ;
26
-
27
- /// Start the histogram bucket at an eighth of a millisecond, as we bucketed the full filter
28
- /// chain processing starting at a quarter of a millisecond, so we we will want finer granularity
29
- /// here.
30
- const BUCKET_START : f64 = 0.000125 ;
31
-
32
- const BUCKET_FACTOR : f64 = 2.5 ;
33
-
34
- /// At an exponential factor of 2.5 (BUCKET_FACTOR), 11 iterations gets us to just over half a
35
- /// second. Any processing that occurs over half a second is far too long, so we end
36
- /// the bucketing there as we don't care about granularity past this value.
37
- const BUCKET_COUNT : usize = 11 ;
38
-
39
22
/// A chain of [`Filter`]s to be executed in order.
40
23
///
41
24
/// Executes each filter, passing the [`ReadContext`] and [`WriteContext`]
@@ -45,50 +28,11 @@ const BUCKET_COUNT: usize = 11;
45
28
#[ derive( Clone , Default ) ]
46
29
pub struct FilterChain {
47
30
filters : Vec < ( String , FilterInstance ) > ,
48
- filter_read_duration_seconds : Vec < Histogram > ,
49
- filter_write_duration_seconds : Vec < Histogram > ,
50
31
}
51
32
52
33
impl FilterChain {
53
34
pub fn new ( filters : Vec < ( String , FilterInstance ) > ) -> Result < Self , CreationError > {
54
- let subsystem = "filter" ;
55
-
56
- Ok ( Self {
57
- filter_read_duration_seconds : filters
58
- . iter ( )
59
- . map ( |( name, _) | {
60
- Histogram :: with_opts (
61
- histogram_opts (
62
- "read_duration_seconds" ,
63
- subsystem,
64
- "Seconds taken to execute a given filter's `read`." ,
65
- Some (
66
- exponential_buckets ( BUCKET_START , BUCKET_FACTOR , BUCKET_COUNT )
67
- . unwrap ( ) ,
68
- ) ,
69
- )
70
- . const_label ( FILTER_LABEL , name) ,
71
- )
72
- . and_then ( |histogram| histogram. register_if_not_exists ( ) )
73
- } )
74
- . collect :: < Result < _ , prometheus:: Error > > ( ) ?,
75
- filter_write_duration_seconds : filters
76
- . iter ( )
77
- . map ( |( name, _) | {
78
- Histogram :: with_opts (
79
- histogram_opts (
80
- "write_duration_seconds" ,
81
- subsystem,
82
- "Seconds taken to execute a given filter's `write`." ,
83
- Some ( exponential_buckets ( 0.000125 , 2.5 , 11 ) . unwrap ( ) ) ,
84
- )
85
- . const_label ( FILTER_LABEL , name) ,
86
- )
87
- . and_then ( |histogram| histogram. register_if_not_exists ( ) )
88
- } )
89
- . collect :: < Result < _ , prometheus:: Error > > ( ) ?,
90
- filters,
91
- } )
35
+ Ok ( Self { filters } )
92
36
}
93
37
94
38
#[ inline]
@@ -274,15 +218,9 @@ impl schemars::JsonSchema for FilterChain {
274
218
275
219
impl Filter for FilterChain {
276
220
fn read ( & self , ctx : & mut ReadContext < ' _ > ) -> Result < ( ) , FilterError > {
277
- for ( ( id, instance) , histogram) in self
278
- . filters
279
- . iter ( )
280
- . zip ( self . filter_read_duration_seconds . iter ( ) )
281
- {
221
+ for ( id, instance) in self . filters . iter ( ) {
282
222
tracing:: trace!( %id, "read filtering packet" ) ;
283
- let timer = histogram. start_timer ( ) ;
284
223
let result = instance. filter ( ) . read ( ctx) ;
285
- timer. stop_and_record ( ) ;
286
224
match result {
287
225
Ok ( ( ) ) => tracing:: trace!( %id, "read passing packet" ) ,
288
226
Err ( error) => {
@@ -304,16 +242,9 @@ impl Filter for FilterChain {
304
242
}
305
243
306
244
fn write ( & self , ctx : & mut WriteContext ) -> Result < ( ) , FilterError > {
307
- for ( ( id, instance) , histogram) in self
308
- . filters
309
- . iter ( )
310
- . rev ( )
311
- . zip ( self . filter_write_duration_seconds . iter ( ) . rev ( ) )
312
- {
245
+ for ( id, instance) in self . filters . iter ( ) . rev ( ) {
313
246
tracing:: trace!( %id, "write filtering packet" ) ;
314
- let timer = histogram. start_timer ( ) ;
315
247
let result = instance. filter ( ) . write ( ctx) ;
316
- timer. stop_and_record ( ) ;
317
248
match result {
318
249
Ok ( ( ) ) => tracing:: trace!( %id, "write passing packet" ) ,
319
250
Err ( error) => {
0 commit comments