Skip to main content

risingwave_storage/monitor/
cache_refill_metrics.rs

1// Copyright 2026 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::LazyLock;
16
17use prometheus::core::{AtomicU64, GenericCounter, GenericCounterVec};
18use prometheus::{
19    Histogram, HistogramVec, IntGauge, Registry, register_histogram_vec_with_registry,
20    register_int_counter_vec_with_registry, register_int_gauge_with_registry,
21};
22use risingwave_common::monitor::GLOBAL_METRICS_REGISTRY;
23
24pub static GLOBAL_CACHE_REFILL_METRICS: LazyLock<CacheRefillMetrics> =
25    LazyLock::new(|| CacheRefillMetrics::new(&GLOBAL_METRICS_REGISTRY));
26
27pub struct CacheRefillMetrics {
28    pub refill_duration: HistogramVec,
29    pub refill_total: GenericCounterVec<AtomicU64>,
30    pub refill_bytes: GenericCounterVec<AtomicU64>,
31
32    pub data_refill_success_duration: Histogram,
33    pub meta_refill_success_duration: Histogram,
34
35    pub data_refill_filtered_total: GenericCounter<AtomicU64>,
36    pub data_refill_attempts_total: GenericCounter<AtomicU64>,
37    pub data_refill_started_total: GenericCounter<AtomicU64>,
38    pub meta_refill_attempts_total: GenericCounter<AtomicU64>,
39
40    pub data_refill_parent_meta_lookup_hit_total: GenericCounter<AtomicU64>,
41    pub data_refill_parent_meta_lookup_miss_total: GenericCounter<AtomicU64>,
42    pub data_refill_unit_inheritance_hit_total: GenericCounter<AtomicU64>,
43    pub data_refill_unit_inheritance_miss_total: GenericCounter<AtomicU64>,
44
45    pub data_refill_block_unfiltered_total: GenericCounter<AtomicU64>,
46    pub data_refill_block_success_total: GenericCounter<AtomicU64>,
47
48    pub data_refill_ideal_bytes: GenericCounter<AtomicU64>,
49    pub data_refill_success_bytes: GenericCounter<AtomicU64>,
50
51    pub refill_queue_total: IntGauge,
52}
53
54impl CacheRefillMetrics {
55    pub fn new(registry: &Registry) -> Self {
56        let refill_duration = register_histogram_vec_with_registry!(
57            "refill_duration",
58            "refill duration",
59            &["type", "op"],
60            registry,
61        )
62        .unwrap();
63        let refill_total = register_int_counter_vec_with_registry!(
64            "refill_total",
65            "refill total",
66            &["type", "op"],
67            registry,
68        )
69        .unwrap();
70        let refill_bytes = register_int_counter_vec_with_registry!(
71            "refill_bytes",
72            "refill bytes",
73            &["type", "op"],
74            registry,
75        )
76        .unwrap();
77
78        let data_refill_success_duration = refill_duration
79            .get_metric_with_label_values(&["data", "success"])
80            .unwrap();
81        let meta_refill_success_duration = refill_duration
82            .get_metric_with_label_values(&["meta", "success"])
83            .unwrap();
84
85        let data_refill_filtered_total = refill_total
86            .get_metric_with_label_values(&["data", "filtered"])
87            .unwrap();
88        let data_refill_attempts_total = refill_total
89            .get_metric_with_label_values(&["data", "attempts"])
90            .unwrap();
91        let data_refill_started_total = refill_total
92            .get_metric_with_label_values(&["data", "started"])
93            .unwrap();
94        let meta_refill_attempts_total = refill_total
95            .get_metric_with_label_values(&["meta", "attempts"])
96            .unwrap();
97
98        let data_refill_parent_meta_lookup_hit_total = refill_total
99            .get_metric_with_label_values(&["parent_meta", "hit"])
100            .unwrap();
101        let data_refill_parent_meta_lookup_miss_total = refill_total
102            .get_metric_with_label_values(&["parent_meta", "miss"])
103            .unwrap();
104        let data_refill_unit_inheritance_hit_total = refill_total
105            .get_metric_with_label_values(&["unit_inheritance", "hit"])
106            .unwrap();
107        let data_refill_unit_inheritance_miss_total = refill_total
108            .get_metric_with_label_values(&["unit_inheritance", "miss"])
109            .unwrap();
110
111        let data_refill_block_unfiltered_total = refill_total
112            .get_metric_with_label_values(&["block", "unfiltered"])
113            .unwrap();
114        let data_refill_block_success_total = refill_total
115            .get_metric_with_label_values(&["block", "success"])
116            .unwrap();
117
118        let data_refill_ideal_bytes = refill_bytes
119            .get_metric_with_label_values(&["data", "ideal"])
120            .unwrap();
121        let data_refill_success_bytes = refill_bytes
122            .get_metric_with_label_values(&["data", "success"])
123            .unwrap();
124
125        let refill_queue_total = register_int_gauge_with_registry!(
126            "refill_queue_total",
127            "refill queue total",
128            registry,
129        )
130        .unwrap();
131
132        Self {
133            refill_duration,
134            refill_total,
135            refill_bytes,
136
137            data_refill_success_duration,
138            meta_refill_success_duration,
139            data_refill_filtered_total,
140            data_refill_attempts_total,
141            data_refill_started_total,
142            meta_refill_attempts_total,
143
144            data_refill_parent_meta_lookup_hit_total,
145            data_refill_parent_meta_lookup_miss_total,
146            data_refill_unit_inheritance_hit_total,
147            data_refill_unit_inheritance_miss_total,
148
149            data_refill_block_unfiltered_total,
150            data_refill_block_success_total,
151
152            data_refill_ideal_bytes,
153            data_refill_success_bytes,
154
155            refill_queue_total,
156        }
157    }
158}