Skip to content

Commit 4c3a355

Browse files
test
1 parent 8667213 commit 4c3a355

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

dogstatsd/src/aggregator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::metric::{self, Metric, MetricValue, SortedTags};
1010
use crate::origins::get_origin;
1111
use std::time;
1212

13-
use datadog_protos::metrics::{Dogsketch, Sketch, SketchPayload, Metadata};
13+
use datadog_protos::metrics::{Dogsketch, Metadata, Sketch, SketchPayload};
1414
use ddsketch_agent::DDSketch;
1515
use hashbrown::hash_table;
1616
use protobuf::Message;
@@ -270,7 +270,7 @@ fn build_sketch(now: i64, entry: &Metric, mut base_tag_vec: SortedTags) -> Optio
270270
}
271271
sketch.set_tags(base_tag_vec.to_chars());
272272

273-
let metadata: Option<Metadata> = get_origin(&name);
273+
let metadata: Option<Metadata> = get_origin(&entry);
274274
if let Some(metadata) = metadata {
275275
sketch.set_metadata(metadata);
276276
}

dogstatsd/src/metric.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ impl SortedTags {
134134
}
135135
resources
136136
}
137+
138+
// TODO Dylan: TEST THIS
139+
pub fn contains(&self, key: &str) -> bool {
140+
self.values.iter().any(|(k, _)| k.as_str() == key)
141+
}
137142
}
138143

139144
/// Representation of a dogstatsd Metric

dogstatsd/src/origins.rs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use crate::metric::Metric;
45
use datadog_protos::metrics::{Metadata, Origin};
56
use protobuf::MessageField;
67

@@ -11,7 +12,7 @@ const AWS_LAMBDA_PREFIX: &str = "aws.lambda";
1112
const AWS_STEP_FUNCTIONS_PREFIX: &str = "aws.states";
1213

1314
/// Represents the product origin of a metric.
14-
/// The full enum is exhaustive so we only include what we need. Please reference the corresponding enum for all possible values
15+
/// The full enum is exhaustive so we only include what we need. Please reference the corresponding enum for all possible values
1516
/// https://github.com/DataDog/dd-source/blob/573dee9b5f7ee13935cb3ad11b16dde970528983/domains/metrics/shared/libs/proto/origin/origin.proto#L161
1617
pub enum OriginProduct {
1718
Serverless = 1,
@@ -24,7 +25,7 @@ impl From<OriginProduct> for u32 {
2425
}
2526

2627
/// Represents the category origin of a metric.
27-
/// The full enum is exhaustive so we only include what we need. Please reference the corresponding enum for all possible values
28+
/// The full enum is exhaustive so we only include what we need. Please reference the corresponding enum for all possible values
2829
/// https://github.com/DataDog/dd-source/blob/573dee9b5f7ee13935cb3ad11b16dde970528983/domains/metrics/shared/libs/proto/origin/origin.proto#L276
2930
pub enum OriginCategory {
3031
AppServicesMetrics = 35,
@@ -41,7 +42,7 @@ impl From<OriginCategory> for u32 {
4142
}
4243

4344
/// Represents the service origin of a metric.
44-
/// The full enum is exhaustive so we only include what we need. Please reference the corresponding enum for all possible values
45+
/// The full enum is exhaustive so we only include what we need. Please reference the corresponding enum for all possible values
4546
/// https://github.com/DataDog/dd-source/blob/573dee9b5f7ee13935cb3ad11b16dde970528983/domains/metrics/shared/libs/proto/origin/origin.proto#L417
4647
pub enum OriginService {
4748
Other = 0,
@@ -53,9 +54,16 @@ impl From<OriginService> for u32 {
5354
}
5455
}
5556

56-
pub fn get_origin(name: &str) -> Option<Metadata> {
57+
pub fn get_origin(metric: &Metric) -> Option<Metadata> {
58+
let name = metric.name.to_string();
5759
let prefix = name.split('.').take(2).collect::<Vec<&str>>().join(".");
5860

61+
if let Some(tags) = &metric.tags {
62+
if tags.contains("function_arn") {
63+
println!("======================== FOUND FUNCTION ARN TAG ========================");
64+
}
65+
}
66+
5967
match prefix {
6068
_ if prefix == AZURE_APP_SERVICES_PREFIX => Some(Metadata {
6169
origin: MessageField::some(Origin {
@@ -131,8 +139,35 @@ mod tests {
131139
#[test]
132140
fn test_get_origin() {
133141
let origin = get_origin("aws.lambda.enhanced.invocations");
134-
assert_eq!(origin.as_ref().unwrap().origin.as_ref().unwrap().origin_product, 1);
135-
assert_eq!(origin.as_ref().unwrap().origin.as_ref().unwrap().origin_category, 38);
136-
assert_eq!(origin.as_ref().unwrap().origin.as_ref().unwrap().origin_service, 0);
142+
assert_eq!(
143+
origin
144+
.as_ref()
145+
.unwrap()
146+
.origin
147+
.as_ref()
148+
.unwrap()
149+
.origin_product,
150+
1
151+
);
152+
assert_eq!(
153+
origin
154+
.as_ref()
155+
.unwrap()
156+
.origin
157+
.as_ref()
158+
.unwrap()
159+
.origin_category,
160+
38
161+
);
162+
assert_eq!(
163+
origin
164+
.as_ref()
165+
.unwrap()
166+
.origin
167+
.as_ref()
168+
.unwrap()
169+
.origin_service,
170+
0
171+
);
137172
}
138-
}
173+
}

0 commit comments

Comments
 (0)