Skip to content

Commit d1c0232

Browse files
authored
pageserver: use pub(crate) in metrics.rs, and clean up unused items (#6275)
## Problem Noticed while making other changes that there were `pub` items that were unused. ## Summary of changes - Make everything `pub(crate)` in metrics.rs, apart from items used from `bin/` - Fix the timelines eviction metric: it was never being incremented - Remove an unused ephemeral_bytes counter.
1 parent a41c412 commit d1c0232

File tree

2 files changed

+40
-45
lines changed

2 files changed

+40
-45
lines changed

pageserver/src/metrics.rs

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const CRITICAL_OP_BUCKETS: &[f64] = &[
2929
// Metrics collected on operations on the storage repository.
3030
#[derive(Debug, EnumVariantNames, IntoStaticStr)]
3131
#[strum(serialize_all = "kebab_case")]
32-
pub enum StorageTimeOperation {
32+
pub(crate) enum StorageTimeOperation {
3333
#[strum(serialize = "layer flush")]
3434
LayerFlush,
3535

@@ -55,7 +55,7 @@ pub enum StorageTimeOperation {
5555
CreateTenant,
5656
}
5757

58-
pub static STORAGE_TIME_SUM_PER_TIMELINE: Lazy<CounterVec> = Lazy::new(|| {
58+
pub(crate) static STORAGE_TIME_SUM_PER_TIMELINE: Lazy<CounterVec> = Lazy::new(|| {
5959
register_counter_vec!(
6060
"pageserver_storage_operations_seconds_sum",
6161
"Total time spent on storage operations with operation, tenant and timeline dimensions",
@@ -64,7 +64,7 @@ pub static STORAGE_TIME_SUM_PER_TIMELINE: Lazy<CounterVec> = Lazy::new(|| {
6464
.expect("failed to define a metric")
6565
});
6666

67-
pub static STORAGE_TIME_COUNT_PER_TIMELINE: Lazy<IntCounterVec> = Lazy::new(|| {
67+
pub(crate) static STORAGE_TIME_COUNT_PER_TIMELINE: Lazy<IntCounterVec> = Lazy::new(|| {
6868
register_int_counter_vec!(
6969
"pageserver_storage_operations_seconds_count",
7070
"Count of storage operations with operation, tenant and timeline dimensions",
@@ -150,7 +150,7 @@ pub(crate) static MATERIALIZED_PAGE_CACHE_HIT: Lazy<IntCounter> = Lazy::new(|| {
150150
.expect("failed to define a metric")
151151
});
152152

153-
pub struct PageCacheMetricsForTaskKind {
153+
pub(crate) struct PageCacheMetricsForTaskKind {
154154
pub read_accesses_materialized_page: IntCounter,
155155
pub read_accesses_immutable: IntCounter,
156156

@@ -159,7 +159,7 @@ pub struct PageCacheMetricsForTaskKind {
159159
pub read_hits_materialized_page_older_lsn: IntCounter,
160160
}
161161

162-
pub struct PageCacheMetrics {
162+
pub(crate) struct PageCacheMetrics {
163163
map: EnumMap<TaskKind, EnumMap<PageContentKind, PageCacheMetricsForTaskKind>>,
164164
}
165165

@@ -181,7 +181,7 @@ static PAGE_CACHE_READ_ACCESSES: Lazy<IntCounterVec> = Lazy::new(|| {
181181
.expect("failed to define a metric")
182182
});
183183

184-
pub static PAGE_CACHE: Lazy<PageCacheMetrics> = Lazy::new(|| PageCacheMetrics {
184+
pub(crate) static PAGE_CACHE: Lazy<PageCacheMetrics> = Lazy::new(|| PageCacheMetrics {
185185
map: EnumMap::from_array(std::array::from_fn(|task_kind| {
186186
let task_kind = <TaskKind as enum_map::Enum>::from_usize(task_kind);
187187
let task_kind: &'static str = task_kind.into();
@@ -243,10 +243,9 @@ impl PageCacheMetrics {
243243
}
244244
}
245245

246-
pub struct PageCacheSizeMetrics {
246+
pub(crate) struct PageCacheSizeMetrics {
247247
pub max_bytes: UIntGauge,
248248

249-
pub current_bytes_ephemeral: UIntGauge,
250249
pub current_bytes_immutable: UIntGauge,
251250
pub current_bytes_materialized_page: UIntGauge,
252251
}
@@ -260,31 +259,26 @@ static PAGE_CACHE_SIZE_CURRENT_BYTES: Lazy<UIntGaugeVec> = Lazy::new(|| {
260259
.expect("failed to define a metric")
261260
});
262261

263-
pub static PAGE_CACHE_SIZE: Lazy<PageCacheSizeMetrics> = Lazy::new(|| PageCacheSizeMetrics {
264-
max_bytes: {
265-
register_uint_gauge!(
266-
"pageserver_page_cache_size_max_bytes",
267-
"Maximum size of the page cache in bytes"
268-
)
269-
.expect("failed to define a metric")
270-
},
271-
272-
current_bytes_ephemeral: {
273-
PAGE_CACHE_SIZE_CURRENT_BYTES
274-
.get_metric_with_label_values(&["ephemeral"])
275-
.unwrap()
276-
},
277-
current_bytes_immutable: {
278-
PAGE_CACHE_SIZE_CURRENT_BYTES
279-
.get_metric_with_label_values(&["immutable"])
280-
.unwrap()
281-
},
282-
current_bytes_materialized_page: {
283-
PAGE_CACHE_SIZE_CURRENT_BYTES
284-
.get_metric_with_label_values(&["materialized_page"])
285-
.unwrap()
286-
},
287-
});
262+
pub(crate) static PAGE_CACHE_SIZE: Lazy<PageCacheSizeMetrics> =
263+
Lazy::new(|| PageCacheSizeMetrics {
264+
max_bytes: {
265+
register_uint_gauge!(
266+
"pageserver_page_cache_size_max_bytes",
267+
"Maximum size of the page cache in bytes"
268+
)
269+
.expect("failed to define a metric")
270+
},
271+
current_bytes_immutable: {
272+
PAGE_CACHE_SIZE_CURRENT_BYTES
273+
.get_metric_with_label_values(&["immutable"])
274+
.unwrap()
275+
},
276+
current_bytes_materialized_page: {
277+
PAGE_CACHE_SIZE_CURRENT_BYTES
278+
.get_metric_with_label_values(&["materialized_page"])
279+
.unwrap()
280+
},
281+
});
288282

289283
pub(crate) mod page_cache_eviction_metrics {
290284
use std::num::NonZeroUsize;
@@ -740,13 +734,13 @@ pub(crate) static TENANT: Lazy<TenantMetrics> = Lazy::new(|| {
740734

741735
/// Each `Timeline`'s [`EVICTIONS_WITH_LOW_RESIDENCE_DURATION`] metric.
742736
#[derive(Debug)]
743-
pub struct EvictionsWithLowResidenceDuration {
737+
pub(crate) struct EvictionsWithLowResidenceDuration {
744738
data_source: &'static str,
745739
threshold: Duration,
746740
counter: Option<IntCounter>,
747741
}
748742

749-
pub struct EvictionsWithLowResidenceDurationBuilder {
743+
pub(crate) struct EvictionsWithLowResidenceDurationBuilder {
750744
data_source: &'static str,
751745
threshold: Duration,
752746
}
@@ -1009,7 +1003,7 @@ pub enum SmgrQueryType {
10091003
}
10101004

10111005
#[derive(Debug)]
1012-
pub struct SmgrQueryTimePerTimeline {
1006+
pub(crate) struct SmgrQueryTimePerTimeline {
10131007
metrics: [GlobalAndPerTimelineHistogram; SmgrQueryType::COUNT],
10141008
}
10151009

@@ -1181,8 +1175,8 @@ static COMPUTE_STARTUP_BUCKETS: Lazy<[f64; 28]> = Lazy::new(|| {
11811175
.map(|ms| (ms as f64) / 1000.0)
11821176
});
11831177

1184-
pub struct BasebackupQueryTime(HistogramVec);
1185-
pub static BASEBACKUP_QUERY_TIME: Lazy<BasebackupQueryTime> = Lazy::new(|| {
1178+
pub(crate) struct BasebackupQueryTime(HistogramVec);
1179+
pub(crate) static BASEBACKUP_QUERY_TIME: Lazy<BasebackupQueryTime> = Lazy::new(|| {
11861180
BasebackupQueryTime({
11871181
register_histogram_vec!(
11881182
"pageserver_basebackup_query_seconds",
@@ -1202,7 +1196,7 @@ impl DurationResultObserver for BasebackupQueryTime {
12021196
}
12031197
}
12041198

1205-
pub static LIVE_CONNECTIONS_COUNT: Lazy<IntGaugeVec> = Lazy::new(|| {
1199+
pub(crate) static LIVE_CONNECTIONS_COUNT: Lazy<IntGaugeVec> = Lazy::new(|| {
12061200
register_int_gauge_vec!(
12071201
"pageserver_live_connections",
12081202
"Number of live network connections",
@@ -1667,7 +1661,7 @@ pub(crate) static WAL_REDO_PROCESS_COUNTERS: Lazy<WalRedoProcessCounters> =
16671661
Lazy::new(WalRedoProcessCounters::default);
16681662

16691663
/// Similar to `prometheus::HistogramTimer` but does not record on drop.
1670-
pub struct StorageTimeMetricsTimer {
1664+
pub(crate) struct StorageTimeMetricsTimer {
16711665
metrics: StorageTimeMetrics,
16721666
start: Instant,
16731667
}
@@ -1692,7 +1686,7 @@ impl StorageTimeMetricsTimer {
16921686
/// Timing facilities for an globally histogrammed metric, which is supported by per tenant and
16931687
/// timeline total sum and count.
16941688
#[derive(Clone, Debug)]
1695-
pub struct StorageTimeMetrics {
1689+
pub(crate) struct StorageTimeMetrics {
16961690
/// Sum of f64 seconds, per operation, tenant_id and timeline_id
16971691
timeline_sum: Counter,
16981692
/// Number of oeprations, per operation, tenant_id and timeline_id
@@ -1731,7 +1725,7 @@ impl StorageTimeMetrics {
17311725
}
17321726

17331727
#[derive(Debug)]
1734-
pub struct TimelineMetrics {
1728+
pub(crate) struct TimelineMetrics {
17351729
tenant_id: String,
17361730
shard_id: String,
17371731
timeline_id: String,
@@ -1939,7 +1933,7 @@ impl Drop for PerTimelineRemotePhysicalSizeGauge {
19391933
}
19401934
}
19411935

1942-
pub struct RemoteTimelineClientMetrics {
1936+
pub(crate) struct RemoteTimelineClientMetrics {
19431937
tenant_id: String,
19441938
timeline_id: String,
19451939
remote_physical_size_gauge: Mutex<Option<PerTimelineRemotePhysicalSizeGauge>>,
@@ -2237,7 +2231,7 @@ impl Drop for RemoteTimelineClientMetrics {
22372231

22382232
/// Wrapper future that measures the time spent by a remote storage operation,
22392233
/// and records the time and success/failure as a prometheus metric.
2240-
pub trait MeasureRemoteOp: Sized {
2234+
pub(crate) trait MeasureRemoteOp: Sized {
22412235
fn measure_remote_op(
22422236
self,
22432237
tenant_id: TenantId,
@@ -2262,7 +2256,7 @@ pub trait MeasureRemoteOp: Sized {
22622256
impl<T: Sized> MeasureRemoteOp for T {}
22632257

22642258
pin_project! {
2265-
pub struct MeasuredRemoteOp<F>
2259+
pub(crate) struct MeasuredRemoteOp<F>
22662260
{
22672261
#[pin]
22682262
inner: F,

pageserver/src/tenant/storage_layer/layer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ impl LayerInner {
11181118
tracing::info!("evicted layer after unknown residence period");
11191119
}
11201120
}
1121+
timeline.metrics.evictions.inc();
11211122
timeline
11221123
.metrics
11231124
.resident_physical_size_sub(self.desc.file_size);

0 commit comments

Comments
 (0)