Skip to content

Commit

Permalink
Update aho-corasick to 1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz committed Jun 5, 2023
1 parent c15c0ed commit a4b2fc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions metrics-util/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a new helper type, `RecoverableRecorder`, that allows installing a recorder and then
recovering it later.

### Changed

- Update `aho-corasick` to `1.0`.

## [0.15.0] - 2023-04-16

### Changed
Expand Down
2 changes: 1 addition & 1 deletion metrics-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ required-features = ["handles"]
metrics = { version = "^0.21", path = "../metrics" }
crossbeam-epoch = { version = "0.9.2", default-features = false, optional = true, features = ["alloc", "std"] }
crossbeam-utils = { version = "0.8", default-features = false, optional = true }
aho-corasick = { version = "0.7", default-features = false, optional = true, features = ["std"] }
aho-corasick = { version = "1", default-features = false, optional = true, features = ["std"] }
indexmap = { version = "1", default-features = false, optional = true }
quanta = { version = "0.11", default-features = false, optional = true }
sketches-ddsketch = { version = "0.2", default-features = false, optional = true }
Expand Down
14 changes: 9 additions & 5 deletions metrics-util/src/layers/filter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::layers::Layer;
use aho_corasick::{AhoCorasick, AhoCorasickBuilder};
use aho_corasick::{AhoCorasick, AhoCorasickBuilder, AhoCorasickKind};
use metrics::{Counter, Gauge, Histogram, Key, KeyName, Recorder, SharedString, Unit};

/// Filters and discards metrics matching certain name patterns.
Expand Down Expand Up @@ -123,7 +123,7 @@ impl FilterLayer {
/// searches from O(n + p) to O(n), where n is the length of the haystack.
///
/// In general, it's a good idea to enable this if you're searching a small number of fairly
/// short patterns (~1000), or if you want the fastest possible search without regard to
/// short patterns, or if you want the fastest possible search without regard to
/// compilation time or space usage.
///
/// Defaults to `true`.
Expand All @@ -140,9 +140,13 @@ impl<R> Layer<R> for FilterLayer {
let mut automaton_builder = AhoCorasickBuilder::new();
let automaton = automaton_builder
.ascii_case_insensitive(self.case_insensitive)
.dfa(self.use_dfa)
.auto_configure(&self.patterns)
.build(&self.patterns);
.kind(self.use_dfa.then(|| AhoCorasickKind::DFA))
.build(&self.patterns)
// Documentation for `AhoCorasickBuilder::build` states that the error here will be
// related to exceeding some internal limits, but that those limits should generally be
// large enough for most use cases.. so I'm making the executive decision to consider
// that "good enough" and treat this as an exceptional error if it does occur.
.expect("should not fail to build filter automaton");
Filter { inner, automaton }
}
}
Expand Down

0 comments on commit a4b2fc1

Please sign in to comment.