1414 * limitations under the License.
1515 */
1616
17- use prometheus:: { exponential_buckets, Histogram } ;
18-
1917use crate :: {
2018 config:: Filter as FilterConfig ,
2119 filters:: { prelude:: * , FilterRegistry } ,
22- metrics:: { histogram_opts, CollectorExt } ,
2320} ;
2421
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-
3922/// A chain of [`Filter`]s to be executed in order.
4023///
4124/// Executes each filter, passing the [`ReadContext`] and [`WriteContext`]
@@ -45,50 +28,11 @@ const BUCKET_COUNT: usize = 11;
4528#[ derive( Clone , Default ) ]
4629pub struct FilterChain {
4730 filters : Vec < ( String , FilterInstance ) > ,
48- filter_read_duration_seconds : Vec < Histogram > ,
49- filter_write_duration_seconds : Vec < Histogram > ,
5031}
5132
5233impl FilterChain {
5334 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 } )
9236 }
9337
9438 #[ inline]
@@ -274,15 +218,9 @@ impl schemars::JsonSchema for FilterChain {
274218
275219impl Filter for FilterChain {
276220 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 ( ) {
282222 tracing:: trace!( %id, "read filtering packet" ) ;
283- let timer = histogram. start_timer ( ) ;
284223 let result = instance. filter ( ) . read ( ctx) ;
285- timer. stop_and_record ( ) ;
286224 match result {
287225 Ok ( ( ) ) => tracing:: trace!( %id, "read passing packet" ) ,
288226 Err ( error) => {
@@ -304,16 +242,9 @@ impl Filter for FilterChain {
304242 }
305243
306244 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 ( ) {
313246 tracing:: trace!( %id, "write filtering packet" ) ;
314- let timer = histogram. start_timer ( ) ;
315247 let result = instance. filter ( ) . write ( ctx) ;
316- timer. stop_and_record ( ) ;
317248 match result {
318249 Ok ( ( ) ) => tracing:: trace!( %id, "write passing packet" ) ,
319250 Err ( error) => {
0 commit comments