Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove mozsvc-common #394

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}