11use crate :: layers:: Layer ;
2- use aho_corasick:: { AhoCorasick , AhoCorasickBuilder } ;
2+ use aho_corasick:: { AhoCorasick , AhoCorasickBuilder , AhoCorasickKind } ;
33use metrics:: { Counter , Gauge , Histogram , Key , KeyName , Recorder , SharedString , Unit } ;
44
55/// Filters and discards metrics matching certain name patterns.
@@ -123,7 +123,7 @@ impl FilterLayer {
123123 /// searches from O(n + p) to O(n), where n is the length of the haystack.
124124 ///
125125 /// In general, it's a good idea to enable this if you're searching a small number of fairly
126- /// short patterns (~1000) , or if you want the fastest possible search without regard to
126+ /// short patterns, or if you want the fastest possible search without regard to
127127 /// compilation time or space usage.
128128 ///
129129 /// Defaults to `true`.
@@ -140,9 +140,13 @@ impl<R> Layer<R> for FilterLayer {
140140 let mut automaton_builder = AhoCorasickBuilder :: new ( ) ;
141141 let automaton = automaton_builder
142142 . ascii_case_insensitive ( self . case_insensitive )
143- . dfa ( self . use_dfa )
144- . auto_configure ( & self . patterns )
145- . build ( & self . patterns ) ;
143+ . kind ( self . use_dfa . then ( || AhoCorasickKind :: DFA ) )
144+ . build ( & self . patterns )
145+ // Documentation for `AhoCorasickBuilder::build` states that the error here will be
146+ // related to exceeding some internal limits, but that those limits should generally be
147+ // large enough for most use cases.. so I'm making the executive decision to consider
148+ // that "good enough" and treat this as an exceptional error if it does occur.
149+ . expect ( "should not fail to build filter automaton" ) ;
146150 Filter { inner, automaton }
147151 }
148152}
0 commit comments