Skip to content

Commit bb82314

Browse files
authored
drop: add NaN matcher (#103)
Signed-off-by: Matt Klein <mklein@bitdrift.io>
1 parent 5b441e8 commit bb82314

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+186
-75
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Test (single): `cargo test test_name` or `cargo nextest run test_name`
77
- Test (specific crate): `cargo test -p crate-name`
88
- Clippy: `cargo clippy --workspace --bins --examples --tests -- --no-deps`
9+
- Format: `cargo +nightly fmt`
910

1011
## Important Notes
1112
- Do NOT prefix cargo commands with `SKIP_PROTO_GEN=1` unless specifically needed

pulse-metrics/src/pipeline/processor/drop/mod.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,21 @@ impl TranslatedDropCondition {
117117
return false;
118118
};
119119

120-
let Some(Value_match_type::SimpleValue(simple_value_match)) = &value_match.value_match_type
121-
else {
122-
return false;
123-
};
124-
125-
match simple_value_match.operator.enum_value_or_default() {
126-
ValueMatchOperator::EQUAL => (value - simple_value_match.target).abs() < f64::EPSILON,
127-
ValueMatchOperator::NOT_EQUAL => (value - simple_value_match.target).abs() >= f64::EPSILON,
128-
ValueMatchOperator::GREATER => value > simple_value_match.target,
129-
ValueMatchOperator::GREATER_OR_EQUAL => value >= simple_value_match.target,
130-
ValueMatchOperator::LESS => value < simple_value_match.target,
131-
ValueMatchOperator::LESS_OR_EQUAL => value <= simple_value_match.target,
120+
match value_match.value_match_type.as_ref() {
121+
Some(Value_match_type::SimpleValue(simple_value_match)) => {
122+
match simple_value_match.operator.enum_value_or_default() {
123+
ValueMatchOperator::EQUAL => (value - simple_value_match.target).abs() < f64::EPSILON,
124+
ValueMatchOperator::NOT_EQUAL => {
125+
(value - simple_value_match.target).abs() >= f64::EPSILON
126+
},
127+
ValueMatchOperator::GREATER => value > simple_value_match.target,
128+
ValueMatchOperator::GREATER_OR_EQUAL => value >= simple_value_match.target,
129+
ValueMatchOperator::LESS => value < simple_value_match.target,
130+
ValueMatchOperator::LESS_OR_EQUAL => value <= simple_value_match.target,
131+
}
132+
},
133+
Some(Value_match_type::IsNan(is_nan)) => value.is_nan() == *is_nan,
134+
None => false,
132135
}
133136
}
134137

pulse-metrics/src/pipeline/processor/drop/mod_test.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
use crate::pipeline::processor::PipelineProcessor;
99
use crate::pipeline::processor::drop::DropProcessor;
10-
use crate::test::{make_metric, processor_factory_context_for_test};
10+
use crate::protos::metric::{DownstreamId, MetricSource, MetricValue};
11+
use crate::test::{make_metric, make_metric_ex, processor_factory_context_for_test};
1112
use bd_test_helpers::make_mut;
1213
use drop::drop_processor_config::Config_source;
1314
use drop::drop_rule::drop_condition::Condition_type;
@@ -527,3 +528,62 @@ async fn warn_interval() {
527528
&labels! { "rule_name" => "rule1", "mode" => "enabled" },
528529
);
529530
}
531+
532+
#[tokio::test]
533+
async fn nan_match() {
534+
let (mut helper, context) = processor_factory_context_for_test();
535+
let processor = Arc::new(
536+
DropProcessor::new(
537+
DropProcessorConfig {
538+
config_source: Some(Config_source::Inline(DropConfig {
539+
rules: vec![DropRule {
540+
name: "rule1".into(),
541+
mode: DropMode::ENABLED.into(),
542+
conditions: vec![DropCondition {
543+
condition_type: Some(Condition_type::ValueMatch(ValueMatch {
544+
value_match_type: Some(Value_match_type::IsNan(true)),
545+
..Default::default()
546+
})),
547+
..Default::default()
548+
}],
549+
..Default::default()
550+
}],
551+
..Default::default()
552+
})),
553+
..Default::default()
554+
},
555+
context,
556+
)
557+
.await
558+
.unwrap(),
559+
);
560+
561+
make_mut(&mut helper.dispatcher)
562+
.expect_send()
563+
.times(1)
564+
.returning(|metrics| {
565+
assert_eq!(metrics, vec![make_metric("not_nan", &[], 100)]);
566+
});
567+
568+
let nan_metric = make_metric_ex(
569+
"nan_metric",
570+
&[],
571+
0,
572+
None,
573+
None,
574+
MetricValue::Simple(f64::NAN),
575+
MetricSource::PromRemoteWrite,
576+
DownstreamId::LocalOrigin,
577+
None,
578+
);
579+
580+
processor
581+
.clone()
582+
.recv_samples(vec![make_metric("not_nan", &[], 100), nan_metric])
583+
.await;
584+
helper.stats_helper.assert_counter_eq(
585+
1,
586+
"processor:dropped",
587+
&labels! { "rule_name" => "rule1", "mode" => "enabled" },
588+
);
589+
}

pulse-protobuf/proto/pulse/config/processor/v1/drop.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ message DropRule {
7171
// Matches against "simple" metrics that have a single value. I.e., not histograms or
7272
// summaries.
7373
SimpleValueMatch simple_value = 1;
74+
75+
// Match against NaN values.
76+
bool is_nan = 2;
7477
}
7578
}
7679

pulse-protobuf/src/protos/opentelemetry/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt
77

88
// This file is generated by rust-protobuf 4.0.0-alpha.0. Do not edit
9-
// .proto file is parsed by protoc 33.1
9+
// .proto file is parsed by protoc 33.2
1010
// @generated
1111

1212
// https://github.com/rust-lang/rust-clippy/issues/702

pulse-protobuf/src/protos/opentelemetry/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt
77

88
// This file is generated by rust-protobuf 4.0.0-alpha.0. Do not edit
9-
// .proto file is parsed by protoc 33.1
9+
// .proto file is parsed by protoc 33.2
1010
// @generated
1111

1212
// https://github.com/rust-lang/rust-clippy/issues/702

pulse-protobuf/src/protos/opentelemetry/metrics_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt
77

88
// This file is generated by rust-protobuf 4.0.0-alpha.0. Do not edit
9-
// .proto file is parsed by protoc 33.1
9+
// .proto file is parsed by protoc 33.2
1010
// @generated
1111

1212
// https://github.com/rust-lang/rust-clippy/issues/702

pulse-protobuf/src/protos/opentelemetry/resource.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt
77

88
// This file is generated by rust-protobuf 4.0.0-alpha.0. Do not edit
9-
// .proto file is parsed by protoc 33.1
9+
// .proto file is parsed by protoc 33.2
1010
// @generated
1111

1212
// https://github.com/rust-lang/rust-clippy/issues/702

pulse-protobuf/src/protos/pulse/config/bootstrap/v1/bootstrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt
77

88
// This file is generated by rust-protobuf 4.0.0-alpha.0. Do not edit
9-
// .proto file is parsed by protoc 33.1
9+
// .proto file is parsed by protoc 33.2
1010
// @generated
1111

1212
// https://github.com/rust-lang/rust-clippy/issues/702

pulse-protobuf/src/protos/pulse/config/common/v1/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt
77

88
// This file is generated by rust-protobuf 4.0.0-alpha.0. Do not edit
9-
// .proto file is parsed by protoc 33.1
9+
// .proto file is parsed by protoc 33.2
1010
// @generated
1111

1212
// https://github.com/rust-lang/rust-clippy/issues/702

0 commit comments

Comments
 (0)