Skip to content

Commit

Permalink
Merge branch 'main' into 31-char-shm
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi authored Oct 17, 2024
2 parents 8141084 + 92272e9 commit eca6525
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 67 deletions.
1 change: 0 additions & 1 deletion .github/workflows/all-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ jobs:
delay: '3'
retries: '30'
polling_interval: '1'
checks_exclude: 'coverage'
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov@0.6.9,nextest@0.9.68
tool: cargo-llvm-cov@0.6.13,nextest@0.9.81
- name: Generate code coverage (including doc tests)
run: |
cargo llvm-cov --all-features --workspace --no-report nextest
Expand Down
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 26 additions & 30 deletions LICENSE-3rdparty.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dogstatsd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ license.workspace = true
bench = false

[dependencies]
datadog-protos = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki-backport/" }
ddsketch-agent = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki-backport/" }
datadog-protos = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki-backport/", rev = "3c5d87ab82dea4a1a98ef0c60fb3659ca35c2751" }
ddsketch-agent = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki-backport/", rev = "3c5d87ab82dea4a1a98ef0c60fb3659ca35c2751" }
hashbrown = { version = "0.14.3", default-features = false, features = ["inline-more"] }
protobuf = { version = "3.5.0", default-features = false }
ustr = { version = "1.0.0", default-features = false }
Expand Down
21 changes: 18 additions & 3 deletions dogstatsd/src/datadog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use protobuf::Message;
use reqwest;
use serde::{Serialize, Serializer};
use serde_json;
use tracing::debug;
use tracing::{debug, error};

/// Interface for the `DogStatsD` metrics intake API.
#[derive(Debug)]
Expand All @@ -20,11 +20,18 @@ pub struct DdApi {

impl DdApi {
#[must_use]
pub fn new(api_key: String, site: String) -> Self {
pub fn new(api_key: String, site: String, https_proxy: Option<String>) -> Self {
let client = match Self::build_client(https_proxy) {
Ok(client) => client,
Err(e) => {
error!("Unable to parse proxy URL, no proxy will be used. {:?}", e);
reqwest::Client::new()
}
};
DdApi {
api_key,
fqdn_site: site,
client: reqwest::Client::new(),
client,
}
}

Expand Down Expand Up @@ -96,6 +103,14 @@ impl DdApi {
}
};
}

fn build_client(https_proxy: Option<String>) -> Result<reqwest::Client, reqwest::Error> {
let mut builder = reqwest::Client::builder();
if let Some(proxy) = https_proxy {
builder = builder.proxy(reqwest::Proxy::https(proxy)?);
}
builder.build()
}
}

#[derive(Debug, Serialize, Clone, Copy)]
Expand Down
9 changes: 7 additions & 2 deletions dogstatsd/src/flusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ pub fn build_fqdn_metrics(site: String) -> String {

#[allow(clippy::await_holding_lock)]
impl Flusher {
pub fn new(api_key: String, aggregator: Arc<Mutex<Aggregator>>, site: String) -> Self {
let dd_api = datadog::DdApi::new(api_key, site);
pub fn new(
api_key: String,
aggregator: Arc<Mutex<Aggregator>>,
site: String,
https_proxy: Option<String>,
) -> Self {
let dd_api = datadog::DdApi::new(api_key, site, https_proxy);
Flusher { dd_api, aggregator }
}

Expand Down
1 change: 1 addition & 0 deletions dogstatsd/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async fn dogstatsd_server_ships_series() {
"mock-api-key".to_string(),
Arc::clone(&metrics_aggr),
mock_server.url(),
None,
);

let server_address = "127.0.0.1:18125";
Expand Down
2 changes: 1 addition & 1 deletion serverless/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datadog-serverless-trace-mini-agent"
version = "0.7.2"
version = "0.8.0"
edition = "2021"

[dependencies]
Expand Down
8 changes: 7 additions & 1 deletion serverless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub async fn main() {
.map(|val| val.to_lowercase() != "false")
.unwrap_or(true);

let https_proxy = env::var("DD_PROXY_HTTPS")
.or_else(|_| env::var("HTTPS_PROXY"))
.ok();
debug!("Starting serverless trace mini agent");

let mini_agent_version = env!("CARGO_PKG_VERSION").to_string();
Expand Down Expand Up @@ -79,7 +82,8 @@ pub async fn main() {

let mut metrics_flusher = if dd_use_dogstatsd {
debug!("Starting dogstatsd");
let (_, metrics_flusher) = start_dogstatsd(dd_dogstatsd_port, dd_api_key, dd_site).await;
let (_, metrics_flusher) =
start_dogstatsd(dd_dogstatsd_port, dd_api_key, dd_site, https_proxy).await;
info!("dogstatsd-udp: starting to listen on port {dd_dogstatsd_port}");
metrics_flusher
} else {
Expand All @@ -104,6 +108,7 @@ async fn start_dogstatsd(
port: u16,
dd_api_key: Option<String>,
dd_site: String,
https_proxy: Option<String>,
) -> (CancellationToken, Option<Flusher>) {
let metrics_aggr = Arc::new(Mutex::new(
MetricsAggregator::new(EMPTY_TAGS, CONTEXTS).expect("Failed to create metrics aggregator"),
Expand Down Expand Up @@ -131,6 +136,7 @@ async fn start_dogstatsd(
dd_api_key,
Arc::clone(&metrics_aggr),
build_fqdn_metrics(dd_site),
https_proxy,
);
Some(metrics_flusher)
}
Expand Down
10 changes: 6 additions & 4 deletions trace-mini-agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Config {
pub dd_site: String,
pub dd_dogstatsd_port: u16,
pub env_type: trace_utils::EnvironmentType,
pub function_name: Option<String>,
pub app_name: Option<String>,
pub max_request_content_length: usize,
pub obfuscation_config: obfuscation_config::ObfuscationConfig,
pub os: String,
Expand All @@ -41,7 +41,7 @@ impl Config {
.map_err(|_| anyhow::anyhow!("DD_API_KEY environment variable is not set"))?
.into();

let (function_name, env_type) = read_cloud_env().ok_or_else(|| {
let (app_name, env_type) = read_cloud_env().ok_or_else(|| {
anyhow::anyhow!("Unable to identify environment. Shutting down Mini Agent.")
})?;

Expand Down Expand Up @@ -70,7 +70,7 @@ impl Config {
})?;

Ok(Config {
function_name: Some(function_name),
app_name: Some(app_name),
env_type,
os: env::consts::OS.to_string(),
max_request_content_length: 10 * 1024 * 1024, // 10MB in Bytes
Expand All @@ -90,7 +90,9 @@ impl Config {
..Default::default()
},
obfuscation_config,
proxy_url: env::var("HTTPS_PROXY").ok(),
proxy_url: env::var("DD_PROXY_HTTPS")
.or_else(|_| env::var("HTTPS_PROXY"))
.ok(),
})
}
}
Expand Down
16 changes: 13 additions & 3 deletions trace-mini-agent/src/env_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use async_trait::async_trait;
use hyper::{Body, Client, Method, Request, Response};
use log::{debug, error};
use serde::{Deserialize, Serialize};
use std::env;
use std::fs;
use std::path::Path;
use std::process;
Expand Down Expand Up @@ -113,6 +114,9 @@ impl ServerlessEnvVerifier {
}
};
trace_utils::MiniAgentMetadata {
azure_spring_app_hostname: trace_utils::MiniAgentMetadata::default()
.azure_spring_app_hostname,
azure_spring_app_name: trace_utils::MiniAgentMetadata::default().azure_spring_app_name,
gcp_project_id: Some(gcp_metadata.project.project_id),
gcp_region: Some(get_region_from_gcp_region_string(
gcp_metadata.instance.region,
Expand Down Expand Up @@ -140,9 +144,13 @@ impl EnvVerifier for ServerlessEnvVerifier {
.verify_gcp_environment_or_exit(verify_env_timeout)
.await;
}
trace_utils::EnvironmentType::AzureSpringApp => {
trace_utils::MiniAgentMetadata::default()
}
trace_utils::EnvironmentType::AzureSpringApp => trace_utils::MiniAgentMetadata {
azure_spring_app_hostname: env::var("HOSTNAME").ok(),
azure_spring_app_name: env::var("ASCSVCRT_SPRING__APPLICATION__NAME").ok(),
gcp_project_id: trace_utils::MiniAgentMetadata::default().gcp_project_id,
gcp_region: trace_utils::MiniAgentMetadata::default().gcp_region,
version: trace_utils::MiniAgentMetadata::default().version,
},
trace_utils::EnvironmentType::LambdaFunction => {
trace_utils::MiniAgentMetadata::default()
}
Expand Down Expand Up @@ -468,6 +476,8 @@ mod tests {
assert_eq!(
res,
trace_utils::MiniAgentMetadata {
azure_spring_app_hostname: None,
azure_spring_app_name: None,
gcp_project_id: Some("unknown".to_string()),
gcp_region: Some("unknown".to_string()),
version: None
Expand Down
6 changes: 3 additions & 3 deletions trace-mini-agent/src/trace_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ impl TraceChunkProcessor for ChunkProcessor {
fn process(&mut self, chunk: &mut pb::TraceChunk, root_span_index: usize) {
trace_utils::set_serverless_root_span_tags(
&mut chunk.spans[root_span_index],
self.config.function_name.clone(),
self.config.app_name.clone(),
&self.config.env_type,
);
for span in chunk.spans.iter_mut() {
trace_utils::enrich_span_with_mini_agent_metadata(span, &self.mini_agent_metadata);
trace_utils::enrich_span_with_azure_metadata(span);
trace_utils::enrich_span_with_azure_function_metadata(span);
obfuscate_span(span, &self.config.obfuscation_config);
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ mod tests {

fn create_test_config() -> Config {
Config {
function_name: Some("dummy_function_name".to_string()),
app_name: Some("dummy_function_name".to_string()),
max_request_content_length: 10 * 1024 * 1024,
trace_flush_interval: 3,
stats_flush_interval: 3,
Expand Down
31 changes: 27 additions & 4 deletions trace-utils/src/trace_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ fn set_top_level_span(span: &mut pb::Span, is_top_level: bool) {

pub fn set_serverless_root_span_tags(
span: &mut pb::Span,
function_name: Option<String>,
app_name: Option<String>,
env_type: &EnvironmentType,
) {
span.r#type = "serverless".to_string();
Expand All @@ -450,8 +450,15 @@ pub fn set_serverless_root_span_tags(
span.meta
.insert("origin".to_string(), origin_tag.to_string());

if let Some(function_name) = function_name {
span.meta.insert("functionname".to_string(), function_name);
if let Some(function_name) = app_name {
match env_type {
EnvironmentType::CloudFunction
| EnvironmentType::AzureFunction
| EnvironmentType::LambdaFunction => {
span.meta.insert("functionname".to_string(), function_name);
}
_ => {}
}
}
}

Expand All @@ -471,6 +478,8 @@ pub enum EnvironmentType {

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MiniAgentMetadata {
pub azure_spring_app_hostname: Option<String>,
pub azure_spring_app_name: Option<String>,
pub gcp_project_id: Option<String>,
pub gcp_region: Option<String>,
pub version: Option<String>,
Expand All @@ -479,6 +488,8 @@ pub struct MiniAgentMetadata {
impl Default for MiniAgentMetadata {
fn default() -> Self {
MiniAgentMetadata {
azure_spring_app_hostname: Default::default(),
azure_spring_app_name: Default::default(),
gcp_project_id: Default::default(),
gcp_region: Default::default(),
version: env::var("DD_MINI_AGENT_VERSION").ok(),
Expand All @@ -490,6 +501,18 @@ pub fn enrich_span_with_mini_agent_metadata(
span: &mut pb::Span,
mini_agent_metadata: &MiniAgentMetadata,
) {
if let Some(azure_spring_app_hostname) = &mini_agent_metadata.azure_spring_app_hostname {
span.meta.insert(
"azurespringapp.hostname".to_string(),
azure_spring_app_hostname.to_string(),
);
}
if let Some(azure_spring_app_name) = &mini_agent_metadata.azure_spring_app_name {
span.meta.insert(
"azurespringapp.name".to_string(),
azure_spring_app_name.to_string(),
);
}
if let Some(gcp_project_id) = &mini_agent_metadata.gcp_project_id {
span.meta
.insert("project_id".to_string(), gcp_project_id.to_string());
Expand All @@ -506,7 +529,7 @@ pub fn enrich_span_with_mini_agent_metadata(
}
}

pub fn enrich_span_with_azure_metadata(span: &mut pb::Span) {
pub fn enrich_span_with_azure_function_metadata(span: &mut pb::Span) {
if let Some(aas_metadata) = azure_app_services::get_function_metadata() {
let aas_tags = [
("aas.resource.id", aas_metadata.get_resource_id()),
Expand Down

0 comments on commit eca6525

Please sign in to comment.