1// Copyright 2025 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.
1415use std::sync::LazyLock;
1617use prometheus::core::{AtomicU64, GenericCounter};
18use prometheus::{
19 Histogram, Registry, exponential_buckets, histogram_opts, register_histogram_with_registry,
20 register_int_counter_with_registry,
21};
22use risingwave_common::monitor::GLOBAL_METRICS_REGISTRY;
2324/// [`HummockMetrics`] stores the performance and IO metrics of hummock storage.
25#[derive(Debug, Clone)]
26pub struct HummockMetrics {
27pub get_new_sst_ids_counts: GenericCounter<AtomicU64>,
28pub report_compaction_task_counts: GenericCounter<AtomicU64>,
29pub get_new_sst_ids_latency: Histogram,
30pub report_compaction_task_latency: Histogram,
31}
3233pub static GLOBAL_HUMMOCK_METRICS: LazyLock<HummockMetrics> =
34 LazyLock::new(|| HummockMetrics::new(&GLOBAL_METRICS_REGISTRY));
3536impl HummockMetrics {
37fn new(registry: &Registry) -> Self {
38// ----- Hummock -----
39let get_new_sst_ids_counts = register_int_counter_with_registry!(
40"state_store_get_new_sst_ids_counts",
41"Total number of get_new_table_id requests that have been issued to state store",
42 registry
43 )
44 .unwrap();
45let report_compaction_task_counts = register_int_counter_with_registry!(
46"state_store_report_compaction_task_counts",
47"Total number of report_compaction_task requests that have been issued to state store",
48 registry
49 )
50 .unwrap();
5152// 10ms ~ max 2.7h
53let time_buckets = exponential_buckets(0.01, 10.0, 7).unwrap();
54// gRPC latency
5556 // --
57let get_new_sst_ids_latency_opts = histogram_opts!(
58"state_store_get_new_sst_ids_latency",
59"Total latency of get new table id that have been issued to state store",
60 time_buckets.clone()
61 );
62let get_new_sst_ids_latency =
63register_histogram_with_registry!(get_new_sst_ids_latency_opts, registry).unwrap();
6465// --
66let report_compaction_task_latency_opts = histogram_opts!(
67"state_store_report_compaction_task_latency",
68"Total latency of report compaction task that have been issued to state store",
69 time_buckets
70 );
71let report_compaction_task_latency =
72register_histogram_with_registry!(report_compaction_task_latency_opts, registry)
73 .unwrap();
7475Self {
76 get_new_sst_ids_counts,
77 report_compaction_task_counts,
78 get_new_sst_ids_latency,
79 report_compaction_task_latency,
80 }
81 }
8283/// Creates a new `HummockStateStoreMetrics` instance used in tests or other places.
84pub fn unused() -> Self {
85 GLOBAL_HUMMOCK_METRICS.clone()
86 }
87}