Skip to content

Commit

Permalink
Add logging for what endpoints are added and removed
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Aug 14, 2023
1 parent d742f1d commit 7a97a20
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ impl ClusterMap {

pub fn merge(&self, map: Self) {
for cluster in map.iter() {
let span = tracing::info_span!("applied_cluster", cluster = cluster.name,);
let _entered = span.enter();

let cluster = cluster.value();
self.default_entry(cluster.name.clone()).merge(cluster);
}
Expand Down
1 change: 0 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ impl Config {
tracing::trace!(resource=?response, "applying resource");

let apply_cluster = |cluster: Cluster| {
tracing::trace!(endpoints = %serde_json::to_value(&cluster).unwrap(), "applying new endpoints");
self.clusters
.write()
.default_entry(cluster.name.clone())
Expand Down
41 changes: 41 additions & 0 deletions src/endpoint/locality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ impl Locality {
self
}

pub fn colon_separated_string(&self) -> String {
let mut string = String::from(&*self.region);

if !self.zone.is_empty() {
string += ":";
string += &*self.zone;
}

if !self.sub_zone.is_empty() {
string += ":";
string += &*self.sub_zone;
}

string
}

pub fn sub_zone(mut self, sub_zone: impl Into<String>) -> Self {
self.sub_zone = sub_zone.into();
self
Expand Down Expand Up @@ -262,6 +278,31 @@ impl LocalitySet {

pub fn merge(&mut self, cluster: &Self) {
for (key, value) in &cluster.0 {
if tracing::enabled!(tracing::Level::INFO) {
let span = tracing::info_span!(
"applied_locality",
locality = &*key
.as_ref()
.map(|locality| locality.colon_separated_string())
.unwrap_or_else(|| String::from("<none>"))
);

let _entered = span.enter();
if value.endpoints.is_empty() {
tracing::info!("removing all endpoints");
} else if let Some(original_endpoints) = self.0.get(key) {
for endpoint in &original_endpoints.endpoints {
if !value.endpoints.contains(endpoint) {
tracing::info!(%endpoint.address, ?endpoint.metadata.known.tokens, "removing endpoint");
}
}
}

for endpoint in &value.endpoints {
tracing::info!(%endpoint.address, ?endpoint.metadata.known.tokens, "applying endpoint");
}
}

let entry = self.0.entry(key.clone()).or_default();
*entry = value.clone();
}
Expand Down

0 comments on commit 7a97a20

Please sign in to comment.