Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions be/src/cloud/cloud_tablet_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,13 @@ void CloudTabletMgr::build_all_report_tablets_info(std::map<TTabletId, TTablet>*
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<CloudTablet>& 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;
Expand All @@ -581,6 +583,8 @@ void CloudTabletMgr::build_all_report_tablets_info(std::map<TTabletId, TTablet>*

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();
}
Expand Down
3 changes: 3 additions & 0 deletions be/src/common/metrics/doris_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions be/src/common/metrics/doris_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions be/test/cloud/cloud_tablet_mgr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <thread>

#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"
Expand Down Expand Up @@ -210,4 +212,29 @@ TEST_F(CloudTabletMgrTest, TestGetTabletIfCachedOnlyReturnsCachedTablet) {
sp->clear_all_call_backs();
}

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<CloudTablet>(_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::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
mgr.put_tablet_for_UT(tablet);

std::map<TTabletId, TTablet> 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());
g_tablet_report_inactive_duration_ms = previous_inactive_duration;
}

} // namespace doris