add more event for segcore search(#26277) (#26688)

Signed-off-by: MrPresent-Han <chun.han@zilliz.com>
pull/26710/head
MrPresent-Han 2023-08-30 14:15:01 +08:00 committed by GitHub
parent 95dcf7fa06
commit 7d5a4b2994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 11 deletions

View File

@ -625,7 +625,8 @@ trace:
# Fractions >= 1 will always sample. Fractions < 0 are treated as zero. # Fractions >= 1 will always sample. Fractions < 0 are treated as zero.
sampleFraction: 0 sampleFraction: 0
jaeger: jaeger:
url: # when exporter is jaeger should set the jaeger's URL url: # "http://127.0.0.1:14268/api/traces"
# when exporter is jaeger should set the jaeger's URL
autoIndex: autoIndex:
params: params:

View File

@ -47,10 +47,12 @@ initTelementry(TraceConfig* config) {
opts.transport_format = jaeger::TransportFormat::kThriftHttp; opts.transport_format = jaeger::TransportFormat::kThriftHttp;
opts.endpoint = config->jaegerURL; opts.endpoint = config->jaegerURL;
exporter = jaeger::JaegerExporterFactory::Create(opts); exporter = jaeger::JaegerExporterFactory::Create(opts);
LOG_SEGCORE_INFO_ << "init jaeger exporter, endpoint:" << opts.endpoint;
} else if (config->exporter == "otlp") { } else if (config->exporter == "otlp") {
auto opts = otlp::OtlpGrpcExporterOptions{}; auto opts = otlp::OtlpGrpcExporterOptions{};
opts.endpoint = config->otlpEndpoint; opts.endpoint = config->otlpEndpoint;
exporter = otlp::OtlpGrpcExporterFactory::Create(opts); exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
LOG_SEGCORE_INFO_ << "init otlp exporter, endpoint:" << opts.endpoint;
} else { } else {
LOG_SEGCORE_INFO_ << "Empty Trace"; LOG_SEGCORE_INFO_ << "Empty Trace";
enable_trace = false; enable_trace = false;
@ -111,6 +113,13 @@ GetRootSpan() {
return nullptr; return nullptr;
} }
void
AddEvent(std::string event_label) {
if (enable_trace && local_span != nullptr) {
local_span->AddEvent(event_label);
}
}
void void
logTraceContext(const std::string& extended_info, logTraceContext(const std::string& extended_info,
const std::shared_ptr<trace::Span> span) { const std::shared_ptr<trace::Span> span) {
@ -119,7 +128,7 @@ logTraceContext(const std::string& extended_info,
span->GetContext().trace_id().ToLowerBase16( span->GetContext().trace_id().ToLowerBase16(
nostd::span<char, 2 * opentelemetry::trace::TraceId::kSize>{ nostd::span<char, 2 * opentelemetry::trace::TraceId::kSize>{
&traceID[0], trace_id_size}); &traceID[0], trace_id_size});
LOG_SEGCORE_INFO_ << extended_info << ", traceID:" << traceID; LOG_SEGCORE_DEBUG_ << extended_info << ", traceID:" << traceID;
} }
} }

View File

@ -55,4 +55,7 @@ CloseRootSpan();
std::shared_ptr<trace::Span> std::shared_ptr<trace::Span>
GetRootSpan(); GetRootSpan();
void
AddEvent(std::string event_label);
} // namespace milvus::tracer } // namespace milvus::tracer

View File

@ -44,6 +44,7 @@
#include "storage/ThreadPools.h" #include "storage/ThreadPools.h"
#include "storage/Util.h" #include "storage/Util.h"
#include "utils/File.h" #include "utils/File.h"
#include "common/Tracer.h"
namespace milvus::index { namespace milvus::index {
@ -304,17 +305,23 @@ VectorMemIndex::Query(const DatasetPtr dataset,
search_conf[RANGE_FILTER], search_conf[RANGE_FILTER],
GetMetricType()); GetMetricType());
} }
milvus::tracer::AddEvent("start_knowhere_index_range_search");
auto res = index_.RangeSearch(*dataset, search_conf, bitset); auto res = index_.RangeSearch(*dataset, search_conf, bitset);
milvus::tracer::AddEvent("finish_knowhere_index_range_search");
if (!res.has_value()) { if (!res.has_value()) {
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, PanicCodeInfo(ErrorCodeEnum::UnexpectedError,
fmt::format("failed to range search: {}: {}", fmt::format("failed to range search: {}: {}",
KnowhereStatusString(res.error()), KnowhereStatusString(res.error()),
res.what())); res.what()));
} }
return ReGenRangeSearchResult( auto result = ReGenRangeSearchResult(
res.value(), topk, num_queries, GetMetricType()); res.value(), topk, num_queries, GetMetricType());
milvus::tracer::AddEvent("finish_ReGenRangeSearchResult");
return result;
} else { } else {
milvus::tracer::AddEvent("start_knowhere_index_search");
auto res = index_.Search(*dataset, search_conf, bitset); auto res = index_.Search(*dataset, search_conf, bitset);
milvus::tracer::AddEvent("finish_knowhere_index_search");
if (!res.has_value()) { if (!res.has_value()) {
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, PanicCodeInfo(ErrorCodeEnum::UnexpectedError,
fmt::format("failed to search: {}: {}", fmt::format("failed to search: {}: {}",

View File

@ -23,6 +23,7 @@
#include "knowhere/factory.h" #include "knowhere/factory.h"
#include "knowhere/comp/time_recorder.h" #include "knowhere/comp/time_recorder.h"
#define RAW_DATA "RAW_DATA" #define RAW_DATA "RAW_DATA"
#include "common/Tracer.h"
namespace milvus::index { namespace milvus::index {
@ -87,7 +88,6 @@ VectorMemNMIndex::Query(const DatasetPtr dataset,
// load -> query, raw data has been loaded // load -> query, raw data has been loaded
// build -> query, this case just for test, should load raw data before query // build -> query, this case just for test, should load raw data before query
std::call_once(raw_data_loaded_, load_raw_data_closure); std::call_once(raw_data_loaded_, load_raw_data_closure);
return VectorMemIndex::Query(dataset, search_info, bitset); return VectorMemIndex::Query(dataset, search_info, bitset);
} }
@ -127,6 +127,7 @@ VectorMemNMIndex::LoadRawData() {
PanicCodeInfo( PanicCodeInfo(
ErrorCodeEnum::UnexpectedError, ErrorCodeEnum::UnexpectedError,
"failed to Deserialize index, " + KnowhereStatusString(stat)); "failed to Deserialize index, " + KnowhereStatusString(stat));
milvus::tracer::AddEvent("VectorMemNMIndex_Loaded_RawData");
} }
} // namespace milvus::index } // namespace milvus::index

View File

@ -15,6 +15,7 @@
#include "common/Consts.h" #include "common/Consts.h"
#include "common/RangeSearchHelper.h" #include "common/RangeSearchHelper.h"
#include "common/Utils.h" #include "common/Utils.h"
#include "common/Tracer.h"
#include "SearchBruteForce.h" #include "SearchBruteForce.h"
#include "SubSearchResult.h" #include "SubSearchResult.h"
#include "knowhere/comp/brute_force.h" #include "knowhere/comp/brute_force.h"
@ -71,7 +72,7 @@ BruteForceSearch(const dataset::SearchDataset& dataset,
} }
auto res = knowhere::BruteForce::RangeSearch( auto res = knowhere::BruteForce::RangeSearch(
base_dataset, query_dataset, config, bitset); base_dataset, query_dataset, config, bitset);
milvus::tracer::AddEvent("knowhere_finish_BruteForce_RangeSearch");
if (!res.has_value()) { if (!res.has_value()) {
PanicCodeInfo(ErrorCodeEnum::UnexpectedError, PanicCodeInfo(ErrorCodeEnum::UnexpectedError,
fmt::format("failed to range search: {}: {}", fmt::format("failed to range search: {}: {}",
@ -80,6 +81,7 @@ BruteForceSearch(const dataset::SearchDataset& dataset,
} }
auto result = ReGenRangeSearchResult( auto result = ReGenRangeSearchResult(
res.value(), topk, nq, dataset.metric_type); res.value(), topk, nq, dataset.metric_type);
milvus::tracer::AddEvent("ReGenRangeSearchResult");
std::copy_n( std::copy_n(
GetDatasetIDs(result), nq * topk, sub_result.get_seg_offsets()); GetDatasetIDs(result), nq * topk, sub_result.get_seg_offsets());
std::copy_n(GetDatasetDistance(result), std::copy_n(GetDatasetDistance(result),
@ -93,7 +95,8 @@ BruteForceSearch(const dataset::SearchDataset& dataset,
sub_result.mutable_distances().data(), sub_result.mutable_distances().data(),
config, config,
bitset); bitset);
milvus::tracer::AddEvent(
"knowhere_finish_BruteForce_SearchWithBuf");
if (stat != knowhere::Status::success) { if (stat != knowhere::Status::success) {
throw std::invalid_argument("invalid metric type, " + throw std::invalid_argument("invalid metric type, " +
KnowhereStatusString(stat)); KnowhereStatusString(stat));

View File

@ -12,6 +12,7 @@
#include <cstddef> #include <cstddef>
#include "common/BitsetView.h" #include "common/BitsetView.h"
#include "common/QueryInfo.h" #include "common/QueryInfo.h"
#include "common/Tracer.h"
#include "SearchOnGrowing.h" #include "SearchOnGrowing.h"
#include "query/SearchBruteForce.h" #include "query/SearchBruteForce.h"
#include "query/SearchOnIndex.h" #include "query/SearchOnIndex.h"
@ -123,7 +124,6 @@ SearchOnGrowing(const segcore::SegmentGrowingImpl& segment,
size_per_chunk, size_per_chunk,
info.search_params_, info.search_params_,
sub_view); sub_view);
// convert chunk uid to segment uid // convert chunk uid to segment uid
for (auto& x : sub_qr.mutable_seg_offsets()) { for (auto& x : sub_qr.mutable_seg_offsets()) {
if (x != -1) { if (x != -1) {

View File

@ -15,6 +15,7 @@
#include "Utils.h" #include "Utils.h"
#include "common/SystemProperty.h" #include "common/SystemProperty.h"
#include "common/Tracer.h"
#include "common/Types.h" #include "common/Types.h"
#include "query/generated/ExecPlanNodeVisitor.h" #include "query/generated/ExecPlanNodeVisitor.h"
@ -67,6 +68,7 @@ SegmentInternalInterface::Search(
const query::Plan* plan, const query::Plan* plan,
const query::PlaceholderGroup* placeholder_group) const { const query::PlaceholderGroup* placeholder_group) const {
std::shared_lock lck(mutex_); std::shared_lock lck(mutex_);
milvus::tracer::AddEvent("obtained_segment_lock_mutex");
check_search(plan); check_search(plan);
query::ExecPlanNodeVisitor visitor(*this, 1L << 63, placeholder_group); query::ExecPlanNodeVisitor visitor(*this, 1L << 63, placeholder_group);
auto results = std::make_unique<SearchResult>(); auto results = std::make_unique<SearchResult>();

View File

@ -37,6 +37,7 @@
#include "storage/Util.h" #include "storage/Util.h"
#include "storage/ThreadPools.h" #include "storage/ThreadPools.h"
#include "utils/File.h" #include "utils/File.h"
#include "common/Tracer.h"
namespace milvus::segcore { namespace milvus::segcore {
@ -572,6 +573,7 @@ SegmentSealedImpl::vector_search(SearchInfo& search_info,
query_count, query_count,
bitset, bitset,
output); output);
milvus::tracer::AddEvent("finish_searching_vector_index");
} else { } else {
AssertInfo( AssertInfo(
get_bit(field_data_ready_bitset_, field_id), get_bit(field_data_ready_bitset_, field_id),
@ -587,6 +589,7 @@ SegmentSealedImpl::vector_search(SearchInfo& search_info,
row_count, row_count,
bitset, bitset,
output); output);
milvus::tracer::AddEvent("finish_searching_vector_data");
} }
} }

View File

@ -79,10 +79,6 @@ Search(CSegmentInterface c_segment,
auto ctx = milvus::tracer::TraceContext{ auto ctx = milvus::tracer::TraceContext{
c_trace.traceID, c_trace.spanID, c_trace.flag}; c_trace.traceID, c_trace.spanID, c_trace.flag};
auto span = milvus::tracer::StartSpan("SegCoreSearch", &ctx); auto span = milvus::tracer::StartSpan("SegCoreSearch", &ctx);
milvus::tracer::logTraceContext(
"SegCore_SegmentSearch_SegmentID:" +
std::to_string(segment->get_segment_id()),
span);
milvus::tracer::SetRootSpan(span); milvus::tracer::SetRootSpan(span);
auto search_result = segment->Search(plan, phg_ptr); auto search_result = segment->Search(plan, phg_ptr);
if (!milvus::PositivelyRelated( if (!milvus::PositivelyRelated(