From 5eaeeee278581cdbd41f91f7e503514578cf8ebd Mon Sep 17 00:00:00 2001 From: Jaya Kasa Date: Thu, 3 Sep 2026 10:30:12 -0400 Subject: [PATCH 1/2] [feature](cloud) Expose approximate rowset metric ### What problem does this PR solve? Issue Number: close #67458 Related PR: N/A Problem Summary: Cloud write admission checks each tablet's _approximate_num_rowsets, but Prometheus exposed only the materialized version-count distribution and omitted recently accessed tablets. Register a separate histogram from the exact admission counter before the inactive-tablet filter so active tablets are included. A focused unit test verifies an active tablet is excluded from the existing report yet included in the new metric. ### Release note Add tablet_approximate_num_rowsets_distribution for cloud-mode tablet version-limit monitoring. ### Check List (For Author) - Test: Header hygiene and formatting checks passed. Focused BE unit test was attempted but local configuration cannot proceed without third-party artifacts; Docker build image extraction also fails on this host. - Behavior changed: Yes. Cloud BEs expose a new Prometheus histogram. - Does this need documentation: No. --- be/src/cloud/cloud_tablet_mgr.cpp | 4 ++++ be/src/common/metrics/doris_metrics.cpp | 3 +++ be/src/common/metrics/doris_metrics.h | 1 + be/test/cloud/cloud_tablet_mgr_test.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/be/src/cloud/cloud_tablet_mgr.cpp b/be/src/cloud/cloud_tablet_mgr.cpp index 82dd46a924dbdc..d8dc19b1559bbe 100644 --- a/be/src/cloud/cloud_tablet_mgr.cpp +++ b/be/src/cloud/cloud_tablet_mgr.cpp @@ -555,11 +555,13 @@ void CloudTabletMgr::build_all_report_tablets_info(std::map* VLOG_NOTICE << "begin to build all report cloud tablets info"; HistogramStat tablet_version_num_hist; + HistogramStat tablet_approximate_num_rowsets_hist; auto handler = [&](const std::weak_ptr& tablet_wk) { auto tablet = tablet_wk.lock(); if (!tablet) return; (*tablet_num)++; + tablet_approximate_num_rowsets_hist.add(tablet->fetch_add_approximate_num_rowsets(0)); TTabletInfo tablet_info; tablet->build_tablet_report_info(&tablet_info); using namespace std::chrono; @@ -581,6 +583,8 @@ void CloudTabletMgr::build_all_report_tablets_info(std::map* DorisMetrics::instance()->tablet_version_num_distribution->set_histogram( tablet_version_num_hist); + DorisMetrics::instance()->tablet_approximate_num_rowsets_distribution->set_histogram( + tablet_approximate_num_rowsets_hist); LOG(INFO) << "success to build all cloud report tablets info. all_tablet_count=" << *tablet_num << " exceed drop time limit count=" << tablets_info->size(); } diff --git a/be/src/common/metrics/doris_metrics.cpp b/be/src/common/metrics/doris_metrics.cpp index 3799a95da05e25..07fe8b859a8cf0 100644 --- a/be/src/common/metrics/doris_metrics.cpp +++ b/be/src/common/metrics/doris_metrics.cpp @@ -207,6 +207,8 @@ DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_used_permits, MetricUnit::NOUNIT); DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_waitting_permits, MetricUnit::NOUNIT); DEFINE_HISTOGRAM_METRIC_PROTOTYPE_2ARG(tablet_version_num_distribution, MetricUnit::NOUNIT); +DEFINE_HISTOGRAM_METRIC_PROTOTYPE_2ARG(tablet_approximate_num_rowsets_distribution, + MetricUnit::NOUNIT); DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_scan_bytes_per_second, MetricUnit::BYTES); @@ -406,6 +408,7 @@ DorisMetrics::DorisMetrics() : _metric_registry(_s_registry_name) { INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_waitting_permits); HISTOGRAM_METRIC_REGISTER(_server_metric_entity, tablet_version_num_distribution); + HISTOGRAM_METRIC_REGISTER(_server_metric_entity, tablet_approximate_num_rowsets_distribution); INT_GAUGE_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_per_second); diff --git a/be/src/common/metrics/doris_metrics.h b/be/src/common/metrics/doris_metrics.h index d50354f24d548d..05d2c4f11ff3a6 100644 --- a/be/src/common/metrics/doris_metrics.h +++ b/be/src/common/metrics/doris_metrics.h @@ -182,6 +182,7 @@ class DorisMetrics { IntGauge* compaction_waitting_permits = nullptr; HistogramMetric* tablet_version_num_distribution = nullptr; + HistogramMetric* tablet_approximate_num_rowsets_distribution = nullptr; // The following metrics will be calculated // by metric calculator diff --git a/be/test/cloud/cloud_tablet_mgr_test.cpp b/be/test/cloud/cloud_tablet_mgr_test.cpp index c893b72a475c7f..4b8ebcce3e0369 100644 --- a/be/test/cloud/cloud_tablet_mgr_test.cpp +++ b/be/test/cloud/cloud_tablet_mgr_test.cpp @@ -28,6 +28,8 @@ #include #include "cloud/cloud_storage_engine.h" +#include "cloud/cloud_tablet.h" +#include "common/metrics/doris_metrics.h" #include "cpp/sync_point.h" #include "storage/tablet/tablet_meta.h" #include "util/uid_util.h" @@ -210,4 +212,26 @@ TEST_F(CloudTabletMgrTest, TestGetTabletIfCachedOnlyReturnsCachedTablet) { sp->clear_all_call_backs(); } +TEST_F(CloudTabletMgrTest, TestApproximateRowsetsMetricIncludesActiveTablets) { + CloudTabletMgr mgr(_engine); + auto tablet = std::make_shared(_engine, _tablet_meta); + auto* metric = DorisMetrics::instance()->tablet_approximate_num_rowsets_distribution; + metric->clear(); + tablet->reset_approximate_stats(0, 0, 0, 0); + tablet->fetch_add_approximate_num_rowsets(8); + tablet->last_access_time_ms = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); + mgr.put_tablet_for_UT(tablet); + + std::map tablets_info; + uint64_t tablet_num = 0; + mgr.build_all_report_tablets_info(&tablets_info, &tablet_num); + + EXPECT_EQ(1, tablet_num); + EXPECT_TRUE(tablets_info.empty()); + EXPECT_EQ(1, metric->num()); + EXPECT_EQ(8, metric->max()); +} + } // namespace doris From 0d0429644b182fc41268564ef8b4146ad2a13d12 Mon Sep 17 00:00:00 2001 From: Jaya Kasa Date: Thu, 3 Sep 2026 13:53:49 -0400 Subject: [PATCH 2/2] [test](cloud) Set active tablet report window Set a nonzero inactive-report window in the approximate-rowsets metric test so the test tablet takes the active-tablet path. Restore the global after the assertion to avoid changing later tests. --- be/test/cloud/cloud_tablet_mgr_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/be/test/cloud/cloud_tablet_mgr_test.cpp b/be/test/cloud/cloud_tablet_mgr_test.cpp index 4b8ebcce3e0369..ba244807c2640a 100644 --- a/be/test/cloud/cloud_tablet_mgr_test.cpp +++ b/be/test/cloud/cloud_tablet_mgr_test.cpp @@ -213,6 +213,8 @@ TEST_F(CloudTabletMgrTest, TestGetTabletIfCachedOnlyReturnsCachedTablet) { } TEST_F(CloudTabletMgrTest, TestApproximateRowsetsMetricIncludesActiveTablets) { + const uint64_t previous_inactive_duration = g_tablet_report_inactive_duration_ms; + g_tablet_report_inactive_duration_ms = 1000; CloudTabletMgr mgr(_engine); auto tablet = std::make_shared(_engine, _tablet_meta); auto* metric = DorisMetrics::instance()->tablet_approximate_num_rowsets_distribution; @@ -232,6 +234,7 @@ TEST_F(CloudTabletMgrTest, TestApproximateRowsetsMetricIncludesActiveTablets) { EXPECT_TRUE(tablets_info.empty()); EXPECT_EQ(1, metric->num()); EXPECT_EQ(8, metric->max()); + g_tablet_report_inactive_duration_ms = previous_inactive_duration; } } // namespace doris