Skip to content

Commit

Permalink
RUST-1501 Update faas metadata collection (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
abr-egn authored Apr 17, 2023
1 parent f80171e commit 573aa54
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/cmap/establish/handshake/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,9 @@ impl FaasEnvironment {
}
}
FaasEnvironmentName::Vercel => {
let url = env::var("VERCEL_URL").ok();
let region = env::var("VERCEL_REGION").ok();
Self {
name,
url,
region,
..Self::UNSET
}
Expand All @@ -225,24 +223,28 @@ fn var_set(name: &str) -> bool {
impl FaasEnvironmentName {
fn new() -> Option<Self> {
use FaasEnvironmentName::*;
let mut found = vec![];
let mut found: Option<Self> = None;
if var_set("AWS_EXECUTION_ENV") || var_set("AWS_LAMBDA_RUNTIME_API") {
found.push(AwsLambda);
found = Some(AwsLambda);
}
if var_set("VERCEL") {
// Vercel takes precedence over AwsLambda.
found = Some(Vercel);
}
// Any other conflict is treated as unset.
if var_set("FUNCTIONS_WORKER_RUNTIME") {
found.push(AzureFunc);
match found {
None => found = Some(AzureFunc),
_ => return None,
}
}
if var_set("K_SERVICE") || var_set("FUNCTION_NAME") {
found.push(GcpFunc);
}
if var_set("VERCEL") {
found.push(Vercel);
}
if found.len() != 1 {
None
} else {
Some(found[0])
match found {
None => found = Some(GcpFunc),
_ => return None,
}
}
found
}

fn name(&self) -> &'static str {
Expand Down Expand Up @@ -282,10 +284,6 @@ lazy_static! {
type Truncation = fn(&mut ClientMetadata);

const METADATA_TRUNCATIONS: &[Truncation] = &[
// truncate `platform`
|metadata| {
metadata.platform = rustc_version_runtime::version_meta().short_version_string;
},
// clear `env.*` except `name`
|metadata| {
if let Some(env) = &mut metadata.env {
Expand All @@ -308,6 +306,10 @@ const METADATA_TRUNCATIONS: &[Truncation] = &[
|metadata| {
metadata.env = None;
},
// truncate `platform`
|metadata| {
metadata.platform = rustc_version_runtime::version_meta().short_version_string;
},
];

/// Contains the logic needed to handshake a connection.
Expand Down

0 comments on commit 573aa54

Please sign in to comment.