Skip to content

Commit

Permalink
Remove metric to avoid cardinality issues, leave it in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Jan 28, 2025
1 parent bb2a78c commit 8d82bc3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
15 changes: 15 additions & 0 deletions src/domain/account_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ impl From<&PublicKey> for FriendlyId {
}
}

impl FriendlyId {
pub fn enriched_display(&self, npub: Option<&str>) -> String {
match self {
FriendlyId::Npub(_) | FriendlyId::PublicKey(_) => self.to_string(),
_ => {
if let Some(npub) = npub {
format!("{} ({})", self, npub)
} else {
self.to_string()
}
}
}
}
}

#[derive(Debug, Clone)]
pub struct AccountInfo {
pub public_key: PublicKey,
Expand Down
10 changes: 10 additions & 0 deletions src/domain/follow_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ impl FollowChange {
pub fn followed_at(&self) -> DateTime<Utc> {
self.followed_at
}

pub fn enriched_follower_display(&self) -> String {
let npub = self.follower.to_bech32().ok();
self.friendly_follower.enriched_display(npub.as_deref())
}

pub fn enriched_followee_display(&self) -> String {
let npub = self.followee.to_bech32().ok();
self.friendly_followee.enriched_display(npub.as_deref())
}
}

impl fmt::Display for FollowChange {
Expand Down
16 changes: 4 additions & 12 deletions src/domain/notification_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ impl NotificationFactory {
// lower values cause faster forgetting of infrequent items)
let top_followees: TopK<Vec<u8>> = TopK::new(100, 500, 3, 0.5);

// Initialize metrics with 0 values
for node in top_followees.list() {
if let Ok(friendly_id) = String::from_utf8(node.item.to_vec()) {
metrics::top_followee_count(friendly_id).set(0.0);
}
}

Self {
followee_maps: OrderMap::with_capacity(1_000),
burst,
Expand All @@ -61,10 +54,9 @@ impl NotificationFactory {
FolloweeNotificationFactory::new(self.burst, self.min_seconds_between_messages)
});

// Add to TopK tracking when it's a follow (not unfollow)
// Add to TopK tracking only when it's a follow (not unfollow)
if follow_change.is_follower() {
// Convert friendly_followee to bytes for TopK tracking
let friendly_id = follow_change.friendly_followee().to_string();
let friendly_id = follow_change.enriched_followee_display();
self.top_followees.add(friendly_id.as_bytes().to_vec());
}

Expand Down Expand Up @@ -142,8 +134,8 @@ impl NotificationFactory {

info!("Top 100 most followed accounts:");
for node in self.top_followees.list() {
if let Ok(friendly_id) = String::from_utf8(node.item.to_vec()) {
metrics::top_followee_count(friendly_id.clone()).set(node.count as f64);
if let Ok(id_str) = String::from_utf8(node.item.to_vec()) {
info!(" {}: {} follows", id_str, node.count);
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ pub fn pagerank_seconds() -> Gauge {
metrics::gauge!("pagerank_seconds")
}

pub fn top_followee_count(followee_id: String) -> Gauge {
metrics::gauge!("top_followee_count", "followee" => followee_id)
}

pub fn setup_metrics() -> Result<PrometheusHandle, BuildError> {
describe_counter!(
"pubsub_messages",
Expand Down Expand Up @@ -122,7 +118,6 @@ pub fn setup_metrics() -> Result<PrometheusHandle, BuildError> {
"Number of retained follow changes"
);
describe_gauge!("pagerank_seconds", "Seconds it takes to calculate pagerank");
describe_gauge!("top_followee_count", "Number of follows for top followees");

let prometheus_builder = PrometheusBuilder::new();
let prometheus_handle = prometheus_builder.install_recorder()?;
Expand Down

0 comments on commit 8d82bc3

Please sign in to comment.