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

feat: Report bridge status via __heartbeat__ #295

Merged
merged 2 commits into from
Feb 24, 2022
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
894 changes: 458 additions & 436 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.55-buster as builder
FROM rust:1.58-buster as builder
ARG CRATE

ADD . /app
Expand Down
9 changes: 8 additions & 1 deletion autoendpoint/src/routers/adm/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ impl AdmRouter {
ddb: Box<dyn DbClient>,
) -> Result<Self, AdmError> {
let profiles = settings.profiles()?;
let clients = profiles

let clients: HashMap<String, AdmClient> = profiles
.into_iter()
.map(|(name, profile)| (name, AdmClient::new(&settings, profile, http.clone())))
.collect();
trace!("Initialized {} ADM clients", clients.len());

Ok(Self {
settings,
Expand All @@ -49,6 +51,11 @@ impl AdmRouter {
clients,
})
}

/// if we have any clients defined, this connection is "active"
pub fn active(&self) -> bool {
!self.clients.is_empty()
}
}

#[async_trait(?Send)]
Expand Down
8 changes: 7 additions & 1 deletion autoendpoint/src/routers/apns/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ impl ApnsRouter {
) -> Result<Self, ApnsError> {
let channels = settings.channels()?;

let clients = futures::stream::iter(channels)
let clients: HashMap<String, ApnsClientData> = futures::stream::iter(channels)
.then(|(name, settings)| Self::create_client(name, settings))
.try_collect()
.await?;

trace!("Initialized {} APNs clients", clients.len());
Ok(Self {
clients,
settings,
Expand Down Expand Up @@ -165,6 +166,11 @@ impl ApnsRouter {
.for_each(Self::convert_value_float_to_int);
}
}

/// if we have any clients defined, this connection is "active"
pub fn active(&self) -> bool {
!self.clients.is_empty()
}
}

#[async_trait(?Send)]
Expand Down
9 changes: 7 additions & 2 deletions autoendpoint/src/routers/fcm/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl FcmRouter {
let clients = Self::create_clients(&settings, credentials, http.clone())
.await
.map_err(FcmError::OAuthClientBuild)?;

Ok(Self {
settings,
endpoint_url,
Expand All @@ -63,9 +62,14 @@ impl FcmRouter {
FcmClient::new(settings, credential, http.clone()).await?,
);
}

trace!("Initialized {} FCM clients", clients.len());
Ok(clients)
}

/// if we have any clients defined, this connection is "active"
pub fn active(&self) -> bool {
!self.clients.is_empty()
}
}

#[async_trait(?Send)]
Expand Down Expand Up @@ -204,6 +208,7 @@ mod tests {
async fn successful_routing_no_data() {
let ddb = MockDbClient::new().into_boxed_arc();
let router = make_router(String::from_utf8(make_service_key()).unwrap(), ddb).await;
assert!(router.active());
let _token_mock = mock_token_endpoint();
let fcm_mock = mock_fcm_endpoint_builder()
.match_body(
Expand Down
7 changes: 6 additions & 1 deletion autoendpoint/src/routes/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ pub async fn health_route(state: Data<ServerState>) -> Json<serde_json::Value> {
"status": "OK",
"version": env!("CARGO_PKG_VERSION"),
"router_table": router_health,
"message_table": message_health
"message_table": message_health,
"routers": {
"adm": state.adm_router.active(),
"apns": state.apns_router.active(),
"fcm": state.fcm_router.active(),
}
}))
}

Expand Down
11 changes: 1 addition & 10 deletions autoendpoint/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@ use serde::{
};
use serde_json::value::Value;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct Tags {
pub tags: HashMap<String, String>,
pub extra: HashMap<String, String>,
}

impl Default for Tags {
fn default() -> Tags {
Tags {
tags: HashMap::new(),
extra: HashMap::new(),
}
}
}

impl Serialize for Tags {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
8 changes: 2 additions & 6 deletions autopush-common/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ mod tests {
#[test]
fn test_parse_sort_key_ver1() {
let chid = Uuid::new_v4();
let chidmessageid = format!("01:{}:mytopic", chid.to_hyphenated().to_string());
let chidmessageid = format!("01:{}:mytopic", chid.to_hyphenated());
let key = DynamoDbNotification::parse_sort_key(&chidmessageid).unwrap();
assert_eq!(key.topic, Some("mytopic".to_string()));
assert_eq!(key.channel_id, chid);
Expand All @@ -261,11 +261,7 @@ mod tests {
fn test_parse_sort_key_ver2() {
let chid = Uuid::new_v4();
let sortkey_timestamp = us_since_epoch();
let chidmessageid = format!(
"02:{}:{}",
sortkey_timestamp,
chid.to_hyphenated().to_string()
);
let chidmessageid = format!("02:{}:{}", sortkey_timestamp, chid.to_hyphenated());
let key = DynamoDbNotification::parse_sort_key(&chidmessageid).unwrap();
assert_eq!(key.topic, None);
assert_eq!(key.channel_id, chid);
Expand Down