Skip to content

Commit ed26904

Browse files
committed
perf: remove filter specific measurement
1 parent 0b944af commit ed26904

File tree

2 files changed

+3
-87
lines changed

2 files changed

+3
-87
lines changed

src/filters/chain.rs

+3-72
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
use prometheus::{exponential_buckets, Histogram};
18-
1917
use 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)]
4629
pub struct FilterChain {
4730
filters: Vec<(String, FilterInstance)>,
48-
filter_read_duration_seconds: Vec<Histogram>,
49-
filter_write_duration_seconds: Vec<Histogram>,
5031
}
5132

5233
impl 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

275219
impl 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) => {

src/metrics.rs

-15
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use prometheus::{
2121
IntCounterVec, IntGauge, IntGaugeVec, Opts, Registry, DEFAULT_BUCKETS,
2222
};
2323

24-
pub use prometheus::Result;
25-
2624
/// "event" is used as a label for Metrics that can apply to both Filter
2725
/// `read` and `write` executions.
2826
pub const DIRECTION_LABEL: &str = "event";
@@ -269,19 +267,6 @@ pub fn register<T: Collector + Sized + Clone + 'static>(collector: T) -> T {
269267
.unwrap()
270268
}
271269

272-
pub trait CollectorExt: Collector + Clone + Sized + 'static {
273-
/// Registers the current metric collector with the provided registry
274-
/// if not already registered.
275-
fn register_if_not_exists(self) -> Result<Self> {
276-
match registry().register(Box::from(self.clone())) {
277-
Ok(_) | Err(prometheus::Error::AlreadyReg) => Ok(self),
278-
Err(err) => Err(err),
279-
}
280-
}
281-
}
282-
283-
impl<C: Collector + Clone + 'static> CollectorExt for C {}
284-
285270
/// A local instance of all of the metrics related to packet processing.
286271
pub struct ProcessingMetrics {
287272
pub read_processing_time: LocalHistogram,

0 commit comments

Comments
 (0)