From 6fe39ecbf758340236fe86b52de7483e17e88c8b Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Thu, 25 May 2023 22:06:50 +0200 Subject: [PATCH] add ability to have fake metrics (needed in next patch so we can have to Timeline objects with the same id in memory) --- pageserver/src/metrics.rs | 27 +++++++++++++++++++++------ pageserver/src/tenant/timeline.rs | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pageserver/src/metrics.rs b/pageserver/src/metrics.rs index 75bea9dbab..2a7f87cd34 100644 --- a/pageserver/src/metrics.rs +++ b/pageserver/src/metrics.rs @@ -720,6 +720,7 @@ impl StorageTimeMetrics { #[derive(Debug)] pub struct TimelineMetrics { + fake: bool, tenant_id: String, timeline_id: String, pub reconstruct_time_histo: Histogram, @@ -744,6 +745,7 @@ pub struct TimelineMetrics { impl TimelineMetrics { pub fn new( + fake: bool, tenant_id: &TenantId, timeline_id: &TimelineId, evictions_with_low_residence_duration_builder: EvictionsWithLowResidenceDurationBuilder, @@ -797,7 +799,8 @@ impl TimelineMetrics { let evictions_with_low_residence_duration = evictions_with_low_residence_duration_builder.build(&tenant_id, &timeline_id); - TimelineMetrics { + let m = TimelineMetrics { + fake, tenant_id, timeline_id, reconstruct_time_histo, @@ -819,12 +822,16 @@ impl TimelineMetrics { evictions_with_low_residence_duration: std::sync::RwLock::new( evictions_with_low_residence_duration, ), - } - } -} + }; -impl Drop for TimelineMetrics { - fn drop(&mut self) { + if fake { + m.remove_metrics(); + } + + m + } + + fn remove_metrics(&self) { let tenant_id = &self.tenant_id; let timeline_id = &self.timeline_id; let _ = RECONSTRUCT_TIME.remove_label_values(&[tenant_id, timeline_id]); @@ -860,6 +867,14 @@ impl Drop for TimelineMetrics { } } +impl Drop for TimelineMetrics { + fn drop(&mut self) { + if !self.fake { + self.remove_metrics(); + } + } +} + pub fn remove_tenant_metrics(tenant_id: &TenantId) { let tid = tenant_id.to_string(); let _ = TENANT_SYNTHETIC_SIZE_METRIC.remove_label_values(&[&tid]); diff --git a/pageserver/src/tenant/timeline.rs b/pageserver/src/tenant/timeline.rs index b0aca45882..d48c247c21 100644 --- a/pageserver/src/tenant/timeline.rs +++ b/pageserver/src/tenant/timeline.rs @@ -1366,6 +1366,7 @@ impl Timeline { ancestor_lsn: metadata.ancestor_lsn(), metrics: TimelineMetrics::new( + false, &tenant_id, &timeline_id, crate::metrics::EvictionsWithLowResidenceDurationBuilder::new(