diff --git a/internal/core/src/exec/operator/RandomSampleNode.cpp b/internal/core/src/exec/operator/RandomSampleNode.cpp index b3d46f98f9..d95e89ef04 100644 --- a/internal/core/src/exec/operator/RandomSampleNode.cpp +++ b/internal/core/src/exec/operator/RandomSampleNode.cpp @@ -101,6 +101,10 @@ PhyRandomSampleNode::GetOutput() { return nullptr; } + std::chrono::high_resolution_clock::time_point start = + std::chrono::high_resolution_clock::now(); + + RowVectorPtr result = nullptr; if (!is_source_node_) { auto input_col = GetColumnVector(input_); TargetBitmapView input_data(input_col->GetRawData(), input_col->size()); @@ -126,8 +130,7 @@ PhyRandomSampleNode::GetOutput() { } } - is_finished_ = true; - return std::make_shared(std::vector{input_col}); + result = std::make_shared(std::vector{input_col}); } else { auto sample_output = std::make_shared( TargetBitmap(active_count_), TargetBitmap(active_count_)); @@ -152,10 +155,18 @@ PhyRandomSampleNode::GetOutput() { data.flip(); } - is_finished_ = true; - return std::make_shared( - std::vector{sample_output}); + result = + std::make_shared(std::vector{sample_output}); } + + std::chrono::high_resolution_clock::time_point end = + std::chrono::high_resolution_clock::now(); + double duration = + std::chrono::duration(end - start).count(); + monitor::internal_core_search_latency_random_sample.Observe(duration / + 1000); + is_finished_ = true; + return result; } bool diff --git a/internal/core/src/monitor/prometheus_client.cpp b/internal/core/src/monitor/prometheus_client.cpp index bab294c4e3..50027dc4c0 100644 --- a/internal/core/src/monitor/prometheus_client.cpp +++ b/internal/core/src/monitor/prometheus_client.cpp @@ -208,6 +208,8 @@ std::map retrieveGetTargetEntryLatencyLabels{ {"type", "retrieve_get_target_entry_latency"}}; std::map searchGetTargetEntryLatencyLabels{ {"type", "search_get_target_entry_latency"}}; +std::map randomSampleLatencyLabels{ + {"type", "random_sample_latency"}}; DEFINE_PROMETHEUS_HISTOGRAM_FAMILY(internal_core_search_latency, "[cpp]latency(us) of search on segment") @@ -237,6 +239,10 @@ DEFINE_PROMETHEUS_HISTOGRAM(internal_core_retrieve_get_target_entry_latency, DEFINE_PROMETHEUS_HISTOGRAM(internal_core_search_get_target_entry_latency, internal_core_search_latency, searchGetTargetEntryLatencyLabels) +DEFINE_PROMETHEUS_HISTOGRAM(internal_core_search_latency_random_sample, + internal_core_search_latency, + randomSampleLatencyLabels) + // mmap metrics std::map mmapAllocatedSpaceAnonLabel = { {"type", "anon"}}; diff --git a/internal/core/src/monitor/prometheus_client.h b/internal/core/src/monitor/prometheus_client.h index e10bc2618b..758815a290 100644 --- a/internal/core/src/monitor/prometheus_client.h +++ b/internal/core/src/monitor/prometheus_client.h @@ -141,6 +141,7 @@ DECLARE_PROMETHEUS_HISTOGRAM(internal_core_search_latency_scalar_proportion); DECLARE_PROMETHEUS_HISTOGRAM(internal_core_get_vector_latency); DECLARE_PROMETHEUS_HISTOGRAM(internal_core_retrieve_get_target_entry_latency); DECLARE_PROMETHEUS_HISTOGRAM(internal_core_search_get_target_entry_latency); +DECLARE_PROMETHEUS_HISTOGRAM(internal_core_search_latency_random_sample); // async cgo metrics DECLARE_PROMETHEUS_HISTOGRAM_FAMILY(internal_cgo_queue_duration_seconds);