Skip to content

Commit

Permalink
Add a metric to track the number of managed files per column family i…
Browse files Browse the repository at this point in the history
…n RocksDb (#19214)

We don't add more detailed level to control the cardinality of the
metrics.

Manually tested in local cluster:

<img width="1971" alt="Screenshot 2024-09-04 at 3 11 22 PM"
src="https://github.com/user-attachments/assets/968bb0ac-321f-4749-bc13-e5f852c93ea1">

## Description 

Describe the changes or additions included in this PR.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
halfprice authored and suiwombat committed Sep 16, 2024
1 parent 36711ca commit 49f893f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions crates/typed-store/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl SamplingInterval {
pub struct ColumnFamilyMetrics {
pub rocksdb_total_sst_files_size: IntGaugeVec,
pub rocksdb_total_blob_files_size: IntGaugeVec,
pub rocksdb_total_num_files: IntGaugeVec,
pub rocksdb_current_size_active_mem_tables: IntGaugeVec,
pub rocksdb_size_all_mem_tables: IntGaugeVec,
pub rocksdb_num_snapshots: IntGaugeVec,
Expand Down Expand Up @@ -116,6 +117,13 @@ impl ColumnFamilyMetrics {
registry,
)
.unwrap(),
rocksdb_total_num_files: register_int_gauge_vec_with_registry!(
"rocksdb_total_num_files",
"Total number of files used in the column family",
&["cf_name"],
registry,
)
.unwrap(),
rocksdb_current_size_active_mem_tables: register_int_gauge_vec_with_registry!(
"rocksdb_current_size_active_mem_tables",
"The current approximate size of active memtable (bytes).",
Expand Down
16 changes: 15 additions & 1 deletion crates/typed-store/src/rocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use bincode::Options;
use collectable::TryExtend;
use itertools::Itertools;
use prometheus::{Histogram, HistogramTimer};
use rocksdb::properties::num_files_at_level;
use rocksdb::{
checkpoint::Checkpoint, BlockBasedOptions, BottommostLevelCompaction, Cache, CompactOptions,
DBPinnableSlice, LiveFile, OptimisticTransactionDB, SnapshotWithThreadMode,
Expand Down Expand Up @@ -911,7 +912,7 @@ impl<K, V> DBMap<K, V> {
fn get_int_property(
rocksdb: &RocksDB,
cf: &impl AsColumnFamilyRef,
property_name: &'static std::ffi::CStr,
property_name: &std::ffi::CStr,
) -> Result<i64, TypedStoreError> {
match rocksdb.property_int_value_cf(cf, property_name) {
Ok(Some(value)) => Ok(value.try_into().unwrap()),
Expand Down Expand Up @@ -992,6 +993,19 @@ impl<K, V> DBMap<K, V> {
Self::get_int_property(rocksdb, &cf, ROCKSDB_PROPERTY_TOTAL_BLOB_FILES_SIZE)
.unwrap_or(METRICS_ERROR),
);
// 7 is the default number of levels in RocksDB. If we ever change the number of levels using `set_num_levels`,
// we need to update here as well. Note that there isn't an API to query the DB to get the number of levels (yet).
let total_num_files: i64 = (0..=6)
.map(|level| {
Self::get_int_property(rocksdb, &cf, &num_files_at_level(level))
.unwrap_or(METRICS_ERROR)
})
.sum();
db_metrics
.cf_metrics
.rocksdb_total_num_files
.with_label_values(&[cf_name])
.set(total_num_files);
db_metrics
.cf_metrics
.rocksdb_current_size_active_mem_tables
Expand Down

0 comments on commit 49f893f

Please sign in to comment.