Skip to content

Commit

Permalink
feat: put old AWS crap behind a feature flag (#606)
Browse files Browse the repository at this point in the history
Co-authored-by: Philip Jenvey <pjenvey@underboss.org>
  • Loading branch information
jrconlin and pjenvey committed Feb 8, 2024
1 parent 978bc15 commit 04df79e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions autopush-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ actix-rt = "2.8"
bigtable = ["dep:google-cloud-rust-raw", "dep:grpcio", "dep:protobuf"]
dynamodb = ["dep:rusoto_core", "dep:rusoto_credential", "dep:rusoto_dynamodb"]
dual = ["dynamodb", "bigtable"]
aws = []
emulator = [
"bigtable",
] # used for testing big table, requires an external bigtable emulator running.
24 changes: 19 additions & 5 deletions autopush-common/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use std::{io, sync::OnceLock, time::Duration};
use std::io;
#[cfg(feature = "aws")]
use std::{sync::OnceLock, time::Duration};

use gethostname::gethostname;
use slog::{self, Drain};
use slog_mozlog_json::MozLogJson;

use crate::errors::Result;

#[cfg(feature = "aws")]
static EC2_INSTANCE_ID: OnceLock<Option<String>> = OnceLock::new();

pub fn init_logging(json: bool, name: &str, version: &str) -> Result<()> {
let logger = if json {
let ec2_instance_id = EC2_INSTANCE_ID.get_or_init(|| get_ec2_instance_id().ok());
let hostname = ec2_instance_id
.clone()
.unwrap_or_else(|| gethostname().to_string_lossy().to_string());
let hostname = {
#[cfg(feature = "aws")]
let result = ec2_instance_id();
#[cfg(not(feature = "aws"))]
let result = gethostname().to_string_lossy().to_string();
result
};
let drain = MozLogJson::new(io::stdout())
.logger_name(format!("{}-{}", name, version))
.msg_type(format!("{}:log", name))
Expand Down Expand Up @@ -56,9 +62,17 @@ pub fn init_test_logging() {
slog_stdlog::init().ok();
}

#[cfg(feature = "aws")]
fn ec2_instance_id() -> String {
let ec2_instance_id = EC2_INSTANCE_ID.get_or_init(|| get_ec2_instance_id().ok());
ec2_instance_id
.clone()
.unwrap_or_else(|| gethostname().to_string_lossy().to_string())
}
/// Fetch the EC2 instance-id
///
/// NOTE: This issues a blocking web request
#[cfg(feature = "aws")]
fn get_ec2_instance_id() -> reqwest::Result<String> {
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(1))
Expand Down

0 comments on commit 04df79e

Please sign in to comment.