Skip to content

Commit b39b0a6

Browse files
authored
Merge branch 'main' into zarir/base_service
2 parents 12d610c + 27d495f commit b39b0a6

File tree

33 files changed

+1652
-110
lines changed

33 files changed

+1652
-110
lines changed

.github/workflows/nightly-serverless-init.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ jobs:
3636
run: |
3737
STAMP=$(date -u +%Y%m%d)
3838
SHORT_SHA=$(git -C datadog-agent rev-parse --short=8 HEAD)
39+
AGENT_VERSION=$(grep -m 1 -E '^[0-9]+\.[0-9]+\.[0-9]+$' datadog-agent/CHANGELOG.rst) || { echo "ERROR: could not detect agent version from datadog-agent's CHANGELOG.rst"; exit 1; }
3940
echo "stamp=${STAMP}" >> "$GITHUB_OUTPUT"
4041
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
4142
echo "version=nightly-${STAMP}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
43+
echo "agent_version=${AGENT_VERSION}" >> "$GITHUB_OUTPUT"
4244
4345
# Pin QEMU to a known-good version. See release-serverless-init.yml
4446
# and test-qemu-versions.yml for context on QEMU breakage history.
@@ -56,6 +58,7 @@ jobs:
5658
env:
5759
AGENT_PATH: datadog-agent
5860
VERSION: ${{ steps.meta.outputs.version }}
61+
AGENT_VERSION: ${{ steps.meta.outputs.agent_version }}
5962
SERVERLESS_INIT: "true"
6063
ALPINE: ${{ matrix.arrays.isAlpine }}
6164

.github/workflows/release-serverless-init.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
- "no"
2323
agentVersion:
2424
type: string
25-
description: Datadog agent version
25+
description: Datadog agent version (default latest release tag from Datadog agent branch)
2626
agentBranch:
2727
type: string
2828
description: Datadog agent branch or tag name (default main)
@@ -53,6 +53,15 @@ jobs:
5353
ref: ${{ github.event.inputs.agentBranch }}
5454
path: datadog-agent
5555

56+
- name: Compute agent version
57+
id: meta
58+
run: |
59+
AGENT_VERSION="${{ github.event.inputs.agentVersion }}"
60+
if [ -z "$AGENT_VERSION" ]; then
61+
AGENT_VERSION=$(grep -m 1 -E '^[0-9]+\.[0-9]+\.[0-9]+$' datadog-agent/CHANGELOG.rst) || { echo "ERROR: could not detect agent version from datadog-agent's CHANGELOG.rst; set the Datadog agent version manually"; exit 1; }
62+
fi
63+
echo "agent_version=${AGENT_VERSION}" >> "$GITHUB_OUTPUT"
64+
5665
# Pin QEMU to a known-good version. The default (binfmt:latest) has broken
5766
# arm64 emulation multiple times due to QEMU segfaults in libc-bin triggers:
5867
# - Feb 2025: qemu-v9.2.0 — PR #571 pinned, PR #581 reverted to :latest
@@ -76,7 +85,7 @@ jobs:
7685
VERSION: ${{ github.event.inputs.tag }}
7786
SERVERLESS_INIT: true
7887
ALPINE: ${{ matrix.arrays.isAlpine }}
79-
AGENT_VERSION: ${{ github.event.inputs.agentVersion }}
88+
AGENT_VERSION: ${{ steps.meta.outputs.agent_version }}
8089

8190
- name: Set up build directory and copy binaries
8291
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ integration-tests/cdk.context.json
3030

3131
.gitlab/pipeline*
3232
/CLAUDE.md
33+
/AGENTS.md

.gitlab/datasources/test-suites.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ test_suites:
33
- name: otlp
44
- name: snapstart
55
- name: lmi
6+
- name: auth

.gitlab/scripts/get_secrets.sh

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,15 @@ fi
2121

2222
printf "Getting AWS External ID...\n"
2323

24-
EXTERNAL_ID=$(aws ssm get-parameter \
25-
--region us-east-1 \
26-
--name "ci.datadog-lambda-extension.$EXTERNAL_ID_NAME" \
27-
--with-decryption \
28-
--query "Parameter.Value" \
29-
--out text)
24+
EXTERNAL_ID=$(vault kv get -field="$EXTERNAL_ID_NAME" kv/k8s/gitlab-runner/datadog-lambda-extension/secrets)
3025

3126
printf "Getting DD API KEY...\n"
3227

33-
export DD_API_KEY=$(aws ssm get-parameter \
34-
--region us-east-1 \
35-
--name ci.datadog-lambda-extension.dd-api-key \
36-
--with-decryption \
37-
--query "Parameter.Value" \
38-
--out text)
39-
40-
printf "Getting DD API KEY Secret ARN...\n"
41-
42-
export DATADOG_API_SECRET_ARN=$(aws ssm get-parameter \
43-
--region us-east-1 \
44-
--name ci.datadog-lambda-extension.dd-api-key-secret-arn \
45-
--with-decryption \
46-
--query "Parameter.Value" \
47-
--out text)
28+
export DD_API_KEY=$(vault kv get -field=dd-api-key kv/k8s/gitlab-runner/datadog-lambda-extension/secrets)
4829

4930
printf "Getting DD APP KEY...\n"
5031

51-
export DD_APP_KEY=$(aws ssm get-parameter \
52-
--region us-east-1 \
53-
--name ci.datadog-lambda-extension.dd-app-key \
54-
--with-decryption \
55-
--query "Parameter.Value" \
56-
--out text)
32+
export DD_APP_KEY=$(vault kv get -field=dd-app-key kv/k8s/gitlab-runner/datadog-lambda-extension/secrets)
5733

5834
printf "Assuming role...\n"
5935

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ integration-suite:
508508
- export CDK_DEFAULT_ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
509509
- export CDK_DEFAULT_REGION=us-east-1
510510
- npm run build
511-
- npx cdk deploy "integ-${IDENTIFIER}-${TEST_SUITE}" --require-approval never
511+
- npx cdk deploy "integ-${IDENTIFIER}-${TEST_SUITE}" --require-approval never --import-existing-resources
512512
- echo "Running ${TEST_SUITE} integration tests with identifier ${IDENTIFIER}..."
513513
- export TEST_SUITE=${TEST_SUITE}
514514
- npx jest tests/${TEST_SUITE}.test.ts

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ For `v67` through `v87`, you can opt out of the next-generation Lambda Extension
2121

2222
Today, all workloads using Logs and Metrics are supported.
2323

24-
APM Tracing is supported for Python, NodeJS, Go, Java, and .NET runtimes.
24+
APM Tracing is supported for Python, NodeJS, Go, Java, .NET, and Ruby runtimes.
2525

2626
### Feedback
2727

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use bottlecap::{
5151
AggregatorHandle as LogsAggregatorHandle, AggregatorService as LogsAggregatorService,
5252
},
5353
flusher::LogsFlusher,
54+
lambda::DurableContextUpdate,
5455
},
5556
otlp::{agent::Agent as OtlpAgent, should_enable_otlp_agent},
5657
proxy::{interceptor, should_start_proxy},
@@ -149,7 +150,11 @@ async fn main() -> anyhow::Result<()> {
149150
let config = Arc::new(config::get_config(Path::new(&lambda_directory)));
150151

151152
let aws_config = Arc::new(aws_config);
152-
let api_key_factory = create_api_key_factory(&config, &aws_config);
153+
// Build one shared reqwest::Client for metrics, logs, trace proxy flushing, and calls to
154+
// Datadog APIs (e.g. delegated auth). reqwest::Client is Arc-based internally, so cloning
155+
// just increments a refcount and shares the connection pool.
156+
let shared_client = bottlecap::http::get_client(&config);
157+
let api_key_factory = create_api_key_factory(&config, &aws_config, &shared_client);
153158

154159
let r = response
155160
.await
@@ -160,6 +165,7 @@ async fn main() -> anyhow::Result<()> {
160165
Arc::clone(&aws_config),
161166
&config,
162167
&client,
168+
shared_client,
163169
&r,
164170
Arc::clone(&api_key_factory),
165171
start_time,
@@ -245,17 +251,23 @@ fn get_flush_strategy_for_mode(
245251
}
246252
}
247253

248-
fn create_api_key_factory(config: &Arc<Config>, aws_config: &Arc<AwsConfig>) -> Arc<ApiKeyFactory> {
254+
fn create_api_key_factory(
255+
config: &Arc<Config>,
256+
aws_config: &Arc<AwsConfig>,
257+
client: &reqwest::Client,
258+
) -> Arc<ApiKeyFactory> {
249259
let config = Arc::clone(config);
250260
let aws_config = Arc::clone(aws_config);
261+
let client = client.clone();
251262
let api_key_secret_reload_interval = config.api_key_secret_reload_interval;
252263

253264
Arc::new(ApiKeyFactory::new_from_resolver(
254265
Arc::new(move || {
255266
let config = Arc::clone(&config);
256267
let aws_config = Arc::clone(&aws_config);
268+
let client = client.clone();
257269

258-
Box::pin(async move { resolve_secrets(config, aws_config).await })
270+
Box::pin(async move { resolve_secrets(config, aws_config, client).await })
259271
}),
260272
api_key_secret_reload_interval,
261273
))
@@ -284,6 +296,7 @@ async fn extension_loop_active(
284296
aws_config: Arc<AwsConfig>,
285297
config: &Arc<Config>,
286298
client: &Client,
299+
shared_client: reqwest::Client,
287300
r: &RegisterResponse,
288301
api_key_factory: Arc<ApiKeyFactory>,
289302
start_time: Instant,
@@ -293,20 +306,20 @@ async fn extension_loop_active(
293306
let account_id = r.account_id.as_ref().unwrap_or(&"none".to_string()).clone();
294307
let tags_provider = setup_tag_provider(&Arc::clone(&aws_config), config, &account_id);
295308

296-
// Build one shared reqwest::Client for metrics, logs, and trace proxy flushing.
297-
// reqwest::Client is Arc-based internally, so cloning just increments a refcount
298-
// and shares the connection pool.
299-
let shared_client = bottlecap::http::get_client(config);
300-
301-
let (logs_agent_channel, logs_flusher, logs_agent_cancel_token, logs_aggregator_handle) =
302-
start_logs_agent(
303-
config,
304-
Arc::clone(&api_key_factory),
305-
&tags_provider,
306-
event_bus_tx.clone(),
307-
aws_config.is_managed_instance_mode(),
308-
&shared_client,
309-
);
309+
let (
310+
logs_agent_channel,
311+
logs_flusher,
312+
logs_agent_cancel_token,
313+
logs_aggregator_handle,
314+
durable_context_tx,
315+
) = start_logs_agent(
316+
config,
317+
Arc::clone(&api_key_factory),
318+
&tags_provider,
319+
event_bus_tx.clone(),
320+
aws_config.is_managed_instance_mode(),
321+
&shared_client,
322+
);
310323

311324
let (metrics_flushers, metrics_aggregator_handle, dogstatsd_cancel_token) = start_dogstatsd(
312325
tags_provider.clone(),
@@ -325,6 +338,7 @@ async fn extension_loop_active(
325338
Arc::clone(&aws_config),
326339
metrics_aggregator_handle.clone(),
327340
Arc::clone(&propagator),
341+
durable_context_tx,
328342
);
329343
tokio::spawn(async move {
330344
invocation_processor_service.run().await;
@@ -1039,14 +1053,15 @@ fn start_logs_agent(
10391053
LogsFlusher,
10401054
CancellationToken,
10411055
LogsAggregatorHandle,
1056+
Sender<DurableContextUpdate>,
10421057
) {
10431058
let (aggregator_service, aggregator_handle) = LogsAggregatorService::default();
10441059
// Start service in background
10451060
tokio::spawn(async move {
10461061
aggregator_service.run().await;
10471062
});
10481063

1049-
let (mut agent, tx) = LogsAgent::new(
1064+
let (mut agent, tx, durable_context_tx) = LogsAgent::new(
10501065
Arc::clone(tags_provider),
10511066
Arc::clone(config),
10521067
event_bus,
@@ -1068,7 +1083,13 @@ fn start_logs_agent(
10681083
config.clone(),
10691084
client.clone(),
10701085
);
1071-
(tx, flusher, cancel_token, aggregator_handle)
1086+
(
1087+
tx,
1088+
flusher,
1089+
cancel_token,
1090+
aggregator_handle,
1091+
durable_context_tx,
1092+
)
10721093
}
10731094

10741095
#[allow(clippy::type_complexity)]

bottlecap/src/config/env.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ pub struct EnvConfig {
482482
/// The delay between two samples of the API Security schema collection, in seconds.
483483
#[serde(deserialize_with = "deserialize_optional_duration_from_seconds")]
484484
pub api_security_sample_delay: Option<Duration>,
485+
486+
/// @env `DD_ORG_UUID`
487+
///
488+
/// The Datadog organization UUID. When set, delegated auth is auto-enabled.
489+
#[serde(deserialize_with = "deserialize_string_or_int")]
490+
pub org_uuid: Option<String>,
485491
}
486492

487493
#[allow(clippy::too_many_lines)]
@@ -684,6 +690,8 @@ fn merge_config(config: &mut Config, env_config: &EnvConfig) {
684690
merge_option_to_value!(config, env_config, appsec_waf_timeout);
685691
merge_option_to_value!(config, env_config, api_security_enabled);
686692
merge_option_to_value!(config, env_config, api_security_sample_delay);
693+
694+
merge_string!(config, dd_org_uuid, env_config, org_uuid);
687695
}
688696

689697
#[derive(Debug, PartialEq, Clone, Copy)]
@@ -1044,6 +1052,8 @@ mod tests {
10441052
appsec_waf_timeout: Duration::from_secs(1),
10451053
api_security_enabled: false,
10461054
api_security_sample_delay: Duration::from_secs(60),
1055+
1056+
dd_org_uuid: String::default(),
10471057
};
10481058

10491059
assert_eq!(config, expected_config);

bottlecap/src/config/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ pub struct Config {
364364
pub span_dedup_timeout: Option<Duration>,
365365
pub api_key_secret_reload_interval: Option<Duration>,
366366

367+
pub dd_org_uuid: String,
368+
367369
pub serverless_appsec_enabled: bool,
368370
pub appsec_rules: Option<String>,
369371
pub appsec_waf_timeout: Duration,
@@ -479,6 +481,8 @@ impl Default for Config {
479481
span_dedup_timeout: None,
480482
api_key_secret_reload_interval: None,
481483

484+
dd_org_uuid: String::default(),
485+
482486
serverless_appsec_enabled: false,
483487
appsec_rules: None,
484488
appsec_waf_timeout: Duration::from_millis(5),

0 commit comments

Comments
 (0)