forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appsignal sink): Normalize metrics (vectordotdev#18217)
* feat(appsignal sink): Normalize metrics Implement a normaliser for the AppSignal sink to convert absolute counter metrics to incremental counters, and incremental gauges to absolute gauges. The AppSignal API ignores absolute counters and incremental gauges, so this change adds support for absolute counters and incremental gauges. This normaliser is inspired by the DataDog normaliser. * Refactor metric normalizer tests Move the methods that generate test metrics and the code that compares metric inputs and normalized outputs to the `test_util` metrics module. Previously these test helpers were duplicated across DataDog, StatsD and AppSignal's metric sinks. Rename the `run_comparisons` method to `assert_normalize`, as it asserts the results of running a normalizer's `.normalize` method. Move the duplicated test implementations to the `test_util::metrics` module, in a separate tests sub-module, and make them generic over the normalizer. Use these test definitions in the DataDog, StatsD and AppSignal's metric sink tests. * Fix integration tests Since the AppSignal sink now normalises counters from absolute to incremental, absolute counters that are only emitted once do not result in an outgoing HTTP request being emitted by the sink. Address this by emitting the absolute counters in the tests at least twice. This also implicitly tests the metrics' normalisation.
- Loading branch information
Showing
7 changed files
with
476 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
mod config; | ||
mod encoder; | ||
mod normalizer; | ||
mod request_builder; | ||
mod service; | ||
mod sink; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use vector_core::event::{Metric, MetricValue}; | ||
|
||
use crate::sinks::util::buffer::metrics::{MetricNormalize, MetricSet}; | ||
|
||
#[derive(Default)] | ||
pub(crate) struct AppsignalMetricsNormalizer; | ||
|
||
impl MetricNormalize for AppsignalMetricsNormalizer { | ||
fn normalize(&mut self, state: &mut MetricSet, metric: Metric) -> Option<Metric> { | ||
// We only care about making sure that counters are incremental, and that gauges are | ||
// always absolute. Other metric types are currently unsupported. | ||
match &metric.value() { | ||
// We always send counters as incremental and gauges as absolute. Realistically, any | ||
// system sending an incremental gauge update is kind of doing it wrong, but alas. | ||
MetricValue::Counter { .. } => state.make_incremental(metric), | ||
MetricValue::Gauge { .. } => state.make_absolute(metric), | ||
// Otherwise, send it through as-is. | ||
_ => Some(metric), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::collections::BTreeSet; | ||
|
||
use crate::event::{Metric, MetricKind, MetricValue}; | ||
|
||
use super::AppsignalMetricsNormalizer; | ||
use crate::test_util::metrics::{assert_normalize, tests}; | ||
|
||
#[test] | ||
fn absolute_counter() { | ||
tests::absolute_counter_normalize_to_incremental(AppsignalMetricsNormalizer); | ||
} | ||
|
||
#[test] | ||
fn incremental_counter() { | ||
tests::incremental_counter_normalize_to_incremental(AppsignalMetricsNormalizer); | ||
} | ||
|
||
#[test] | ||
fn mixed_counter() { | ||
tests::mixed_counter_normalize_to_incremental(AppsignalMetricsNormalizer); | ||
} | ||
|
||
#[test] | ||
fn absolute_gauge() { | ||
tests::absolute_gauge_normalize_to_absolute(AppsignalMetricsNormalizer); | ||
} | ||
|
||
#[test] | ||
fn incremental_gauge() { | ||
tests::incremental_gauge_normalize_to_absolute(AppsignalMetricsNormalizer); | ||
} | ||
|
||
#[test] | ||
fn mixed_gauge() { | ||
tests::mixed_gauge_normalize_to_absolute(AppsignalMetricsNormalizer); | ||
} | ||
|
||
#[test] | ||
fn other_metrics() { | ||
let metric = Metric::new( | ||
"set", | ||
MetricKind::Incremental, | ||
MetricValue::Set { | ||
values: BTreeSet::new(), | ||
}, | ||
); | ||
|
||
assert_normalize( | ||
AppsignalMetricsNormalizer, | ||
vec![metric.clone()], | ||
vec![Some(metric)], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.