Skip to content

Commit 13d5bb1

Browse files
litianningdatadogshreyamalpaniduncanistaastuyvejchrostek-dd
authored
Merge Lambda Managed Instance feature branch (#947)
https://datadoghq.atlassian.net/browse/SVLS-8080 ## Overview Merge Lambda Managed Instance feature branch ## Testing Covered by individual commits Co-authored-by: shreyamalpani <shreya.malpani@datadoghq.com> Co-authored-by: duncanista <30836115+duncanista@users.noreply.github.com> Co-authored-by: astuyve <aj.stuyvenberg@datadoghq.com> Co-authored-by: jchrostek-dd <john.chrostek@datadoghq.com> Co-authored-by: tianning.li <tianning.li@datadoghq.com>
1 parent 3409263 commit 13d5bb1

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

aws.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const AWS_LAMBDA_FUNCTION_NAME: &str = "AWS_LAMBDA_FUNCTION_NAME";
1111
const AWS_LAMBDA_RUNTIME_API: &str = "AWS_LAMBDA_RUNTIME_API";
1212
const AWS_LWA_LAMBDA_RUNTIME_API_PROXY: &str = "AWS_LWA_LAMBDA_RUNTIME_API_PROXY";
1313
const AWS_LAMBDA_EXEC_WRAPPER: &str = "AWS_LAMBDA_EXEC_WRAPPER";
14+
const AWS_LAMBDA_INITIALIZATION_TYPE: &str = "AWS_LAMBDA_INITIALIZATION_TYPE";
15+
16+
pub const LAMBDA_MANAGED_INSTANCES_INIT_TYPE: &str = "lambda-managed-instances";
1417

1518
#[allow(clippy::module_name_repetitions)]
1619
#[derive(Debug, Clone)]
@@ -21,6 +24,7 @@ pub struct AwsConfig {
2124
pub runtime_api: String,
2225
pub sandbox_init_time: Instant,
2326
pub exec_wrapper: Option<String>,
27+
pub initialization_type: String,
2428
}
2529

2630
impl AwsConfig {
@@ -33,8 +37,15 @@ impl AwsConfig {
3337
runtime_api: env::var(AWS_LAMBDA_RUNTIME_API).unwrap_or_default(),
3438
sandbox_init_time: start_time,
3539
exec_wrapper: env::var(AWS_LAMBDA_EXEC_WRAPPER).ok(),
40+
initialization_type: env::var(AWS_LAMBDA_INITIALIZATION_TYPE).unwrap_or_default(),
3641
}
3742
}
43+
44+
#[must_use]
45+
pub fn is_managed_instance_mode(&self) -> bool {
46+
self.initialization_type
47+
.eq(LAMBDA_MANAGED_INSTANCES_INIT_TYPE)
48+
}
3849
}
3950

4051
#[allow(clippy::module_name_repetitions)]

flush_strategy.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ pub enum FlushStrategy {
2121
Continuously(PeriodicStrategy),
2222
}
2323

24+
impl FlushStrategy {
25+
/// Returns the name of the flush strategy as a string slice.
26+
#[must_use]
27+
pub const fn name(&self) -> &'static str {
28+
match self {
29+
FlushStrategy::Default => "default",
30+
FlushStrategy::End => "end",
31+
FlushStrategy::Periodically(_) => "periodically",
32+
FlushStrategy::EndPeriodically(_) => "end-periodically",
33+
FlushStrategy::Continuously(_) => "continuously",
34+
}
35+
}
36+
}
37+
2438
// A restricted subset of `FlushStrategy`. The Default strategy is now allowed, which is required to be
2539
// translated into a concrete strategy.
2640
#[allow(clippy::module_name_repetitions)]
@@ -121,4 +135,34 @@ mod tests {
121135
let flush_strategy: FlushStrategy = serde_json::from_str("\"end,invalid\"").unwrap();
122136
assert_eq!(flush_strategy, FlushStrategy::Default);
123137
}
138+
139+
#[test]
140+
fn test_flush_strategy_name_default() {
141+
let strategy = FlushStrategy::Default;
142+
assert_eq!(strategy.name(), "default");
143+
}
144+
145+
#[test]
146+
fn test_flush_strategy_name_end() {
147+
let strategy = FlushStrategy::End;
148+
assert_eq!(strategy.name(), "end");
149+
}
150+
151+
#[test]
152+
fn test_flush_strategy_name_periodically() {
153+
let strategy = FlushStrategy::Periodically(PeriodicStrategy { interval: 1000 });
154+
assert_eq!(strategy.name(), "periodically");
155+
}
156+
157+
#[test]
158+
fn test_flush_strategy_name_end_periodically() {
159+
let strategy = FlushStrategy::EndPeriodically(PeriodicStrategy { interval: 2000 });
160+
assert_eq!(strategy.name(), "end-periodically");
161+
}
162+
163+
#[test]
164+
fn test_flush_strategy_name_continuously() {
165+
let strategy = FlushStrategy::Continuously(PeriodicStrategy { interval: 30000 });
166+
assert_eq!(strategy.name(), "continuously");
167+
}
124168
}

0 commit comments

Comments
 (0)