aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/consul.rs11
-rw-r--r--src/main.rs1
-rw-r--r--src/proxy_config.rs11
3 files changed, 19 insertions, 4 deletions
diff --git a/src/consul.rs b/src/consul.rs
index 240c177..eb7aafd 100644
--- a/src/consul.rs
+++ b/src/consul.rs
@@ -9,13 +9,18 @@ use serde::{Deserialize, Serialize};
// ---- Watch and retrieve Consul catalog ----
//
#[derive(Serialize, Deserialize, Debug)]
-pub struct ConsulNodeListNode {
+pub struct ConsulNode {
#[serde(rename = "Node")]
pub node: String,
+ #[serde(rename = "Address")]
+ pub address: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ConsulServiceEntry {
+ #[serde(rename = "Service")]
+ pub service: String,
+
#[serde(rename = "Address")]
pub address: String,
@@ -28,6 +33,8 @@ pub struct ConsulServiceEntry {
#[derive(Serialize, Deserialize, Debug)]
pub struct ConsulNodeCatalog {
+ #[serde(rename = "Node")]
+ pub node: ConsulNode,
#[serde(rename = "Services")]
pub services: HashMap<String, ConsulServiceEntry>,
}
@@ -84,7 +91,7 @@ impl Consul {
let url = format!("{}/v1/catalog/nodes", self.url);
let http = self.client.get(&url).send().await?;
- let resp: Vec<ConsulNodeListNode> = http.json().await?;
+ let resp: Vec<ConsulNode> = http.json().await?;
Ok(resp.into_iter().map(|n| n.node).collect::<Vec<_>>())
}
diff --git a/src/main.rs b/src/main.rs
index 3a51702..f38767e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -38,6 +38,7 @@ struct Opt {
pub https_bind_addr: SocketAddr,
}
+
#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
async fn main() {
if std::env::var("RUST_LOG").is_err() {
diff --git a/src/proxy_config.rs b/src/proxy_config.rs
index 9d07604..3e3e62f 100644
--- a/src/proxy_config.rs
+++ b/src/proxy_config.rs
@@ -86,7 +86,13 @@ fn parse_consul_catalog(catalog: &ConsulNodeCatalog) -> Vec<ProxyEntry> {
for (_, svc) in catalog.services.iter() {
let ip_addr = match svc.address.parse() {
Ok(ip) => ip,
- _ => continue,
+ _ => match catalog.node.address.parse() {
+ Ok(ip) => ip,
+ _ => {
+ warn!("Could not get address for service {} at node {}", svc.service, catalog.node.node);
+ continue;
+ }
+ }
};
let addr = SocketAddr::new(ip_addr, svc.port);
@@ -178,7 +184,8 @@ pub fn spawn_proxy_config_task(consul: Consul) -> watch::Receiver<Arc<ProxyConfi
let will_retry_in = retry_to_time(watch_state.retries, Duration::from_secs(600));
error!(
- "Failed to query consul. Will retry in {}s. {}",
+ "Failed to query consul for node {}. Will retry in {}s. {}",
+ node,
will_retry_in.as_secs(),
e
);