Skip to content

Commit

Permalink
fix: remove mozsvc-common (mozilla-services#394)
Browse files Browse the repository at this point in the history
its older get_ec2_instance_id isn't compat w/ modern tokio (and the crate's
deprecated)

SYNC-3449
  • Loading branch information
pjenvey authored Jun 29, 2023
1 parent ab3614b commit 66bb74f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defaults:
jobs:
audit:
docker:
- image: rust:latest
- image: rust:1.70
auth:
username: $DOCKER_USER
password: $DOCKER_PASS
Expand Down
12 changes: 11 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM rust:1.68-buster as builder
# NOTE: Ensure builder's Rust version matches CI's in .circleci/config.yml
FROM rust:1.70-buster as builder
ARG CRATE

ADD . /app
Expand Down
2 changes: 1 addition & 1 deletion autopush-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ url.workspace = true

again = "0.1"
async-trait = "0.1"
gethostname = "0.4"
futures-backoff = "0.1.0"
mozsvc-common = "0.2"
woothee = "0.13"

[dev-dependencies]
Expand Down
32 changes: 22 additions & 10 deletions autopush-common/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use std::io;
use std::{io, sync::OnceLock, time::Duration};

use mozsvc_common::{aws::get_ec2_instance_id, get_hostname};
use gethostname::gethostname;
use slog::{self, Drain};
use slog_mozlog_json::MozLogJson;

use crate::errors::Result;

static EC2_INSTANCE_ID: OnceLock<Option<String>> = OnceLock::new();

pub fn init_logging(json: bool) -> Result<()> {
let logger = if json {
let hostname = match get_ec2_instance_id() {
Some(v) => v.to_owned(),
None => match get_hostname() {
Ok(v) => v.to_string_lossy().to_string(),
Err(e) => return Err(e.into()),
},
};

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 drain = MozLogJson::new(io::stdout())
.logger_name(format!(
"{}-{}",
Expand Down Expand Up @@ -59,3 +57,17 @@ pub fn init_test_logging() {
slog_scope::set_global_logger(logger).cancel_reset();
slog_stdlog::init().ok();
}

/// Fetch the EC2 instance-id
///
/// NOTE: This issues a blocking web request
fn get_ec2_instance_id() -> reqwest::Result<String> {
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(1))
.build()?;
client
.get("http://169.254.169.254/latest/meta-data/instance-id")
.send()?
.error_for_status()?
.text()
}

0 comments on commit 66bb74f

Please sign in to comment.