Skip to content

Commit 4c6a10a

Browse files
committed
Revert "feat: No longer launch Go-based agent for compatibility/OTLP/AAP config (#788)"
This reverts commit 0f59845.
1 parent 0f59845 commit 4c6a10a

File tree

5 files changed

+105
-186
lines changed

5 files changed

+105
-186
lines changed

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use bottlecap::{
3737
},
3838
logger,
3939
logs::{agent::LogsAgent, flusher::LogsFlusher},
40-
metrics::enhanced::lambda::Lambda as enhanced_metrics,
4140
otlp::{agent::Agent as OtlpAgent, should_enable_otlp_agent},
4241
proxy::{interceptor, should_start_proxy},
4342
secrets::decrypt,
@@ -85,7 +84,9 @@ use std::{
8584
collections::{HashMap, hash_map},
8685
env,
8786
io::{Error, Result},
87+
os::unix::process::CommandExt,
8888
path::Path,
89+
process::Command,
8990
sync::{Arc, Mutex},
9091
time::{Duration, Instant},
9192
};
@@ -401,7 +402,14 @@ fn load_configs(start_time: Instant) -> (AwsConfig, AwsCredentials, Arc<Config>)
401402
let aws_credentials = AwsCredentials::from_env();
402403
let lambda_directory: String =
403404
env::var("LAMBDA_TASK_ROOT").unwrap_or_else(|_| "/var/task".to_string());
404-
let config = Arc::new(config::get_config(Path::new(&lambda_directory)));
405+
let config = match config::get_config(Path::new(&lambda_directory)) {
406+
Ok(config) => Arc::new(config),
407+
Err(_e) => {
408+
let err = Command::new("/opt/datadog-agent-go").exec();
409+
panic!("Error starting the extension: {err:?}");
410+
}
411+
};
412+
405413
(aws_config, aws_credentials, config)
406414
}
407415

@@ -500,22 +508,12 @@ async fn extension_loop_active(
500508
.as_micros()
501509
.to_string()
502510
);
503-
let metrics_intake_url = create_metrics_intake_url_prefix(config);
511+
504512
let metrics_flushers = Arc::new(TokioMutex::new(start_metrics_flushers(
505513
Arc::clone(&api_key_factory),
506514
&metrics_aggr,
507-
&metrics_intake_url,
508515
config,
509516
)));
510-
511-
// Create lambda enhanced metrics instance once
512-
let lambda_enhanced_metrics =
513-
enhanced_metrics::new(Arc::clone(&metrics_aggr), Arc::clone(config));
514-
515-
// Send config issue metrics
516-
let config_issues = config::fallback(config);
517-
send_config_issue_metric(&config_issues, &lambda_enhanced_metrics);
518-
519517
// Lifecycle Invocation Processor
520518
let invocation_processor = Arc::new(TokioMutex::new(InvocationProcessor::new(
521519
Arc::clone(&tags_provider),
@@ -1008,33 +1006,33 @@ fn start_logs_agent(
10081006
(logs_agent_channel, logs_flusher)
10091007
}
10101008

1011-
fn create_metrics_intake_url_prefix(config: &Config) -> MetricsIntakeUrlPrefix {
1012-
if !config.dd_url.is_empty() {
1009+
fn start_metrics_flushers(
1010+
api_key_factory: Arc<ApiKeyFactory>,
1011+
metrics_aggr: &Arc<Mutex<MetricsAggregator>>,
1012+
config: &Arc<Config>,
1013+
) -> Vec<MetricsFlusher> {
1014+
let mut flushers = Vec::new();
1015+
1016+
let metrics_intake_url = if !config.dd_url.is_empty() {
10131017
let dd_dd_url = DdDdUrl::new(config.dd_url.clone()).expect("can't parse DD_DD_URL");
1018+
10141019
let prefix_override = MetricsIntakeUrlPrefixOverride::maybe_new(None, Some(dd_dd_url));
1015-
MetricsIntakeUrlPrefix::new(None, prefix_override).expect("can't parse DD_DD_URL prefix")
1020+
MetricsIntakeUrlPrefix::new(None, prefix_override)
10161021
} else if !config.url.is_empty() {
10171022
let dd_url = DdUrl::new(config.url.clone()).expect("can't parse DD_URL");
1023+
10181024
let prefix_override = MetricsIntakeUrlPrefixOverride::maybe_new(Some(dd_url), None);
1019-
MetricsIntakeUrlPrefix::new(None, prefix_override).expect("can't parse DD_URL prefix")
1025+
MetricsIntakeUrlPrefix::new(None, prefix_override)
10201026
} else {
1027+
// use site
10211028
let metrics_site = MetricsSite::new(config.site.clone()).expect("can't parse site");
1022-
MetricsIntakeUrlPrefix::new(Some(metrics_site), None).expect("can't parse site prefix")
1023-
}
1024-
}
1025-
1026-
fn start_metrics_flushers(
1027-
api_key_factory: Arc<ApiKeyFactory>,
1028-
metrics_aggr: &Arc<Mutex<MetricsAggregator>>,
1029-
metrics_intake_url: &MetricsIntakeUrlPrefix,
1030-
config: &Arc<Config>,
1031-
) -> Vec<MetricsFlusher> {
1032-
let mut flushers = Vec::new();
1029+
MetricsIntakeUrlPrefix::new(Some(metrics_site), None)
1030+
};
10331031

10341032
let flusher_config = MetricsFlusherConfig {
10351033
api_key_factory,
10361034
aggregator: Arc::clone(metrics_aggr),
1037-
metrics_intake_url_prefix: metrics_intake_url.clone(),
1035+
metrics_intake_url_prefix: metrics_intake_url.expect("can't parse site or override"),
10381036
https_proxy: config.proxy_https.clone(),
10391037
timeout: Duration::from_secs(config.flush_timeout),
10401038
retry_strategy: DsdRetryStrategy::Immediate(3),
@@ -1159,28 +1157,6 @@ fn start_trace_agent(
11591157
)
11601158
}
11611159

1162-
/// Sends metrics indicating issue with configuration.
1163-
///
1164-
/// # Arguments
1165-
/// * `issue_reasons` - Vector of messages describing the issue with the configurations
1166-
/// * `lambda_enhanced_metrics` - The lambda enhanced metrics instance
1167-
fn send_config_issue_metric(issue_reasons: &[String], lambda_enhanced_metrics: &enhanced_metrics) {
1168-
if issue_reasons.is_empty() {
1169-
return;
1170-
}
1171-
let now = std::time::UNIX_EPOCH
1172-
.elapsed()
1173-
.expect("can't poll clock")
1174-
.as_secs()
1175-
.try_into()
1176-
.unwrap_or_default();
1177-
1178-
// Setup a separate metric for each config issue reason
1179-
for issue_reason in issue_reasons {
1180-
lambda_enhanced_metrics.set_config_load_issue_metric(now, issue_reason);
1181-
}
1182-
}
1183-
11841160
async fn start_dogstatsd(metrics_aggr: &Arc<Mutex<MetricsAggregator>>) -> CancellationToken {
11851161
let dogstatsd_config = DogStatsDConfig {
11861162
host: EXTENSION_HOST.to_string(),

0 commit comments

Comments
 (0)