From a4b2fc1605e4cc2c2d98d829ef8261d891673d7d Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Mon, 5 Jun 2023 12:05:02 -0400 Subject: [PATCH] Update aho-corasick to 1.0. --- metrics-util/CHANGELOG.md | 4 ++++ metrics-util/Cargo.toml | 2 +- metrics-util/src/layers/filter.rs | 14 +++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/metrics-util/CHANGELOG.md b/metrics-util/CHANGELOG.md index 5385c4ee..2ce3c741 100644 --- a/metrics-util/CHANGELOG.md +++ b/metrics-util/CHANGELOG.md @@ -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 diff --git a/metrics-util/Cargo.toml b/metrics-util/Cargo.toml index 9e831b89..50eef3b4 100644 --- a/metrics-util/Cargo.toml +++ b/metrics-util/Cargo.toml @@ -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 } diff --git a/metrics-util/src/layers/filter.rs b/metrics-util/src/layers/filter.rs index b76e5695..bfe38665 100644 --- a/metrics-util/src/layers/filter.rs +++ b/metrics-util/src/layers/filter.rs @@ -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. @@ -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`. @@ -140,9 +140,13 @@ impl Layer 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 } } }