add ability to have fake metrics (needed in next patch so we can have to Timeline objects with the same id in memory)

This commit is contained in:
Christian Schwarz
2023-05-25 22:06:50 +02:00
parent a0c2a85505
commit 6fe39ecbf7
2 changed files with 22 additions and 6 deletions

View File

@@ -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]);

View File

@@ -1366,6 +1366,7 @@ impl Timeline {
ancestor_lsn: metadata.ancestor_lsn(),
metrics: TimelineMetrics::new(
false,
&tenant_id,
&timeline_id,
crate::metrics::EvictionsWithLowResidenceDurationBuilder::new(