11// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/ 
22// SPDX-License-Identifier: Apache-2.0 
33
4+ use  crate :: metric:: Metric ; 
45use  datadog_protos:: metrics:: { Metadata ,  Origin } ; 
56use  protobuf:: MessageField ; 
67
@@ -11,7 +12,7 @@ const AWS_LAMBDA_PREFIX: &str = "aws.lambda";
1112const  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 
1617pub  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 
2930pub  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 
4647pub  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