Skip to content

Commit 2c514b8

Browse files
committed
Merge remote-tracking branch 'origin/tobz/datadog-metrics-v3-payload-support' into rayz/metrics-v3-resource-mapping
2 parents c35c34d + 99bb658 commit 2c514b8

8 files changed

Lines changed: 734 additions & 81 deletions

File tree

lib/saluki-components/src/common/datadog/io.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ async fn run_io_loop<B>(
288288

289289
// Listen for transactions to forward, and send a copy of each one to the matching endpoint I/O tasks.
290290
while let Some(transaction) = transactions_rx.recv().await {
291-
let is_metrics_request = is_metrics_request_uri(transaction.request_uri());
291+
let is_metrics_request =
292+
is_metrics_request_uri(transaction.request_uri(), config.v3_api().series.beta_route.as_str());
292293
for endpoint_sender in &endpoint_txs {
293294
if !should_route_to_endpoint(is_metrics_request, has_metrics_primary, endpoint_sender.route) {
294295
continue;
@@ -332,8 +333,8 @@ where
332333
tx: mpsc::Sender<Transaction<B>>,
333334
}
334335

335-
fn is_metrics_request_uri(uri: &Uri) -> bool {
336-
METRIC_INTAKE_PATHS.contains(&uri.path())
336+
fn is_metrics_request_uri(uri: &Uri, v3_beta_series_route: &str) -> bool {
337+
METRIC_INTAKE_PATHS.contains(&uri.path()) || uri.path() == v3_beta_series_route
337338
}
338339

339340
fn should_route_to_endpoint(is_metrics_request: bool, has_metrics_primary: bool, route: EndpointRoute) -> bool {
@@ -888,23 +889,45 @@ mod tests {
888889

889890
use super::*;
890891
use crate::common::datadog::transaction::{Metadata as TxnMetadata, Transaction};
891-
use crate::common::datadog::{METRICS_SERIES_V1_PATH, METRICS_SERIES_V2_PATH, METRICS_SKETCHES_PATH};
892+
use crate::common::datadog::{
893+
METRICS_SERIES_V1_PATH, METRICS_SERIES_V2_PATH, METRICS_SERIES_V3_BETA_PATH, METRICS_SERIES_V3_PATH,
894+
METRICS_SKETCHES_PATH, METRICS_SKETCHES_V3_PATH,
895+
};
892896

893897
fn uri(path: &'static str) -> Uri {
894898
Uri::from_static(path)
895899
}
896900

901+
fn is_metrics_request_path(path: &'static str) -> bool {
902+
is_metrics_request_uri(&uri(path), METRICS_SERIES_V3_BETA_PATH)
903+
}
904+
897905
fn forwarder_config_from_value(value: serde_json::Value) -> ForwarderConfiguration {
898906
serde_json::from_value(value).expect("ForwarderConfiguration should deserialize")
899907
}
900908

901909
#[test]
902910
fn identifies_metrics_request_paths() {
903-
assert!(is_metrics_request_uri(&uri(METRICS_SERIES_V1_PATH)));
904-
assert!(is_metrics_request_uri(&uri(METRICS_SERIES_V2_PATH)));
905-
assert!(is_metrics_request_uri(&uri(METRICS_SKETCHES_PATH)));
906-
assert!(!is_metrics_request_uri(&uri("/api/v2/logs")));
907-
assert!(!is_metrics_request_uri(&uri("/api/v0.2/traces")));
911+
assert!(is_metrics_request_path(METRICS_SERIES_V1_PATH));
912+
assert!(is_metrics_request_path(METRICS_SERIES_V2_PATH));
913+
assert!(is_metrics_request_path(METRICS_SERIES_V3_PATH));
914+
assert!(is_metrics_request_path(METRICS_SERIES_V3_BETA_PATH));
915+
assert!(is_metrics_request_path(METRICS_SKETCHES_PATH));
916+
assert!(is_metrics_request_path(METRICS_SKETCHES_V3_PATH));
917+
assert!(!is_metrics_request_path("/api/v2/logs"));
918+
assert!(!is_metrics_request_path("/api/v0.2/traces"));
919+
}
920+
921+
#[test]
922+
fn identifies_configured_v3_beta_series_route_as_metrics_path() {
923+
assert!(is_metrics_request_uri(
924+
&uri("/custom/v3beta/series"),
925+
"/custom/v3beta/series"
926+
));
927+
assert!(!is_metrics_request_uri(
928+
&uri("/custom/v3beta/series"),
929+
METRICS_SERIES_V3_BETA_PATH
930+
));
908931
}
909932

910933
#[test]

lib/saluki-components/src/common/datadog/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,29 @@ pub(crate) const METRICS_SERIES_V1_PATH: &str = "/api/v1/series";
4646
/// V2 metric series intake path.
4747
pub(crate) const METRICS_SERIES_V2_PATH: &str = "/api/v2/series";
4848

49+
/// V3 metric series intake path.
50+
pub(crate) const METRICS_SERIES_V3_PATH: &str = "/api/intake/metrics/v3/series";
51+
52+
/// V3 beta metric series intake path.
53+
pub(crate) const METRICS_SERIES_V3_BETA_PATH: &str = "/api/intake/metrics/v3beta/series";
54+
4955
/// Metric sketches intake path.
5056
pub(crate) const METRICS_SKETCHES_PATH: &str = "/api/beta/sketches";
5157

58+
/// V3 metric sketches intake path.
59+
pub(crate) const METRICS_SKETCHES_V3_PATH: &str = "/api/intake/metrics/v3/sketches";
60+
5261
/// Metric intake paths emitted by the encoder and matched by OPW routing.
5362
///
5463
/// Keep these paths in one place so metric encoding and OPW routing don't drift.
55-
pub(crate) const METRIC_INTAKE_PATHS: [&str; 3] =
56-
[METRICS_SERIES_V1_PATH, METRICS_SERIES_V2_PATH, METRICS_SKETCHES_PATH];
64+
pub(crate) const METRIC_INTAKE_PATHS: [&str; 6] = [
65+
METRICS_SERIES_V1_PATH,
66+
METRICS_SERIES_V2_PATH,
67+
METRICS_SERIES_V3_PATH,
68+
METRICS_SERIES_V3_BETA_PATH,
69+
METRICS_SKETCHES_PATH,
70+
METRICS_SKETCHES_V3_PATH,
71+
];
5772

5873
/// Metadata tag used to store the sampling decision maker (`_dd.p.dm`).
5974
pub const TAG_DECISION_MAKER: &str = "_dd.p.dm";

lib/saluki-components/src/common/datadog/protocol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
use facet::Facet;
44
use serde::{Deserialize, Serialize};
55

6-
const DEFAULT_V3_BETA_SERIES_ROUTE: &str = "/api/intake/metrics/v3beta/series";
6+
use super::METRICS_SERIES_V3_BETA_PATH;
77

88
fn default_v3_beta_series_route() -> String {
9-
DEFAULT_V3_BETA_SERIES_ROUTE.to_owned()
9+
METRICS_SERIES_V3_BETA_PATH.to_owned()
1010
}
1111

1212
/// The type of metrics payload.

0 commit comments

Comments
 (0)