Skip to content

Commit

Permalink
Skip coverage check for trace code
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Yudong <yudong.cai@zilliz.com>
  • Loading branch information
cydrain committed Sep 20, 2024
1 parent b35d053 commit 028db90
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/common/comp/brute_force.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ BruteForce::Search(const DataSetPtr base_dataset, const DataSetPtr query_dataset
}

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(cfg.trace_id.value());
Expand All @@ -96,6 +97,7 @@ BruteForce::Search(const DataSetPtr base_dataset, const DataSetPtr query_dataset
span->SetAttribute(meta::DIM, dim);
span->SetAttribute(meta::NQ, nq);
}
// LCOV_EXCL_STOP
#endif

std::string metric_str = cfg.metric_type.value();
Expand Down Expand Up @@ -180,9 +182,11 @@ BruteForce::Search(const DataSetPtr base_dataset, const DataSetPtr query_dataset
auto res = GenResultDataSet(nq, cfg.k.value(), std::move(labels), std::move(distances));

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
if (cfg.trace_id.has_value()) {
span->End();
}
// LCOV_EXCL_STOP
#endif

return res;
Expand All @@ -206,6 +210,7 @@ BruteForce::SearchWithBuf(const DataSetPtr base_dataset, const DataSetPtr query_
RETURN_IF_ERROR(Config::Load(cfg, config, knowhere::SEARCH));

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(cfg.trace_id.value());
Expand All @@ -219,6 +224,7 @@ BruteForce::SearchWithBuf(const DataSetPtr base_dataset, const DataSetPtr query_
span->SetAttribute(meta::DIM, dim);
span->SetAttribute(meta::NQ, nq);
}
// LCOV_EXCL_STOP
#endif

std::string metric_str = cfg.metric_type.value();
Expand Down Expand Up @@ -299,9 +305,11 @@ BruteForce::SearchWithBuf(const DataSetPtr base_dataset, const DataSetPtr query_
RETURN_IF_ERROR(WaitAllSuccess(futs));

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
if (cfg.trace_id.has_value()) {
span->End();
}
// LCOV_EXCL_STOP
#endif

return Status::success;
Expand Down Expand Up @@ -335,6 +343,7 @@ BruteForce::RangeSearch(const DataSetPtr base_dataset, const DataSetPtr query_da
}

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(cfg.trace_id.value());
Expand All @@ -351,6 +360,7 @@ BruteForce::RangeSearch(const DataSetPtr base_dataset, const DataSetPtr query_da
span->SetAttribute(meta::DIM, dim);
span->SetAttribute(meta::NQ, nq);
}
// LCOV_EXCL_STOP
#endif

std::string metric_str = cfg.metric_type.value();
Expand Down Expand Up @@ -478,9 +488,11 @@ BruteForce::RangeSearch(const DataSetPtr base_dataset, const DataSetPtr query_da
auto res = GenResultDataSet(nq, std::move(range_search_result));

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
if (cfg.trace_id.has_value()) {
span->End();
}
// LCOV_EXCL_STOP
#endif

return res;
Expand All @@ -505,6 +517,7 @@ BruteForce::SearchSparseWithBuf(const DataSetPtr base_dataset, const DataSetPtr
}

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(cfg.trace_id.value());
Expand All @@ -518,6 +531,7 @@ BruteForce::SearchSparseWithBuf(const DataSetPtr base_dataset, const DataSetPtr
span->SetAttribute(meta::DIM, dim);
span->SetAttribute(meta::NQ, nq);
}
// LCOV_EXCL_STOP
#endif

std::string metric_str = cfg.metric_type.value();
Expand Down Expand Up @@ -573,9 +587,11 @@ BruteForce::SearchSparseWithBuf(const DataSetPtr base_dataset, const DataSetPtr
WaitAllSuccess(futs);

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
if (cfg.trace_id.has_value()) {
span->End();
}
// LCOV_EXCL_STOP
#endif

return Status::success;
Expand Down Expand Up @@ -626,6 +642,7 @@ BruteForce::AnnIterator(const DataSetPtr base_dataset, const DataSetPtr query_da
}

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(cfg.trace_id.value());
Expand All @@ -638,6 +655,7 @@ BruteForce::AnnIterator(const DataSetPtr base_dataset, const DataSetPtr query_da
span->SetAttribute(meta::DIM, dim);
span->SetAttribute(meta::NQ, nq);
}
// LCOV_EXCL_STOP
#endif
faiss::MetricType faiss_metric_type = result.value();
bool is_cosine = IsMetricType(metric_str, metric::COSINE);
Expand Down Expand Up @@ -691,9 +709,11 @@ BruteForce::AnnIterator(const DataSetPtr base_dataset, const DataSetPtr query_da
}

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
if (cfg.trace_id.has_value()) {
span->End();
}
// LCOV_EXCL_STOP
#endif
return vec;
}
Expand Down Expand Up @@ -722,6 +742,7 @@ BruteForce::AnnIterator<knowhere::sparse::SparseRow<float>>(const DataSetPtr bas
std::string metric_str = cfg.metric_type.value();

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(cfg.trace_id.value());
Expand All @@ -734,6 +755,7 @@ BruteForce::AnnIterator<knowhere::sparse::SparseRow<float>>(const DataSetPtr bas
span->SetAttribute(meta::DIM, dim);
span->SetAttribute(meta::NQ, nq);
}
// LCOV_EXCL_STOP
#endif

const bool is_bm25 = IsMetricType(metric_str, metric::BM25);
Expand Down Expand Up @@ -776,9 +798,11 @@ BruteForce::AnnIterator<knowhere::sparse::SparseRow<float>>(const DataSetPtr bas
WaitAllSuccess(futs);

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
if (cfg.trace_id.has_value()) {
span->End();
}
// LCOV_EXCL_STOP
#endif

return vec;
Expand Down
8 changes: 8 additions & 0 deletions src/index/index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Index<T>::Search(const DataSetPtr dataset, const Json& json, const BitsetView& b

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
const BaseConfig& b_cfg = static_cast<const BaseConfig&>(*cfg);
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (b_cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(b_cfg.trace_id.value());
Expand All @@ -105,6 +106,7 @@ Index<T>::Search(const DataSetPtr dataset, const Json& json, const BitsetView& b
span->SetAttribute(meta::DIM, Dim());
span->SetAttribute(meta::NQ, dataset->GetRows());
}
// LCOV_EXCL_STOP

TimeRecorder rc("Search");
bool has_trace_id = b_cfg.trace_id.has_value();
Expand All @@ -115,9 +117,11 @@ Index<T>::Search(const DataSetPtr dataset, const Json& json, const BitsetView& b
knowhere_search_latency.Observe(time);
knowhere_search_topk.Observe(k);

// LCOV_EXCL_START
if (has_trace_id) {
span->End();
}
// LCOV_EXCL_STOP
#else
auto res = this->node->Search(dataset, std::move(cfg), bitset);
#endif
Expand Down Expand Up @@ -183,6 +187,7 @@ Index<T>::RangeSearch(const DataSetPtr dataset, const Json& json, const BitsetVi

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
const BaseConfig& b_cfg = static_cast<const BaseConfig&>(*cfg);
// LCOV_EXCL_START
std::shared_ptr<tracer::trace::Span> span = nullptr;
if (b_cfg.trace_id.has_value()) {
auto trace_id_str = tracer::GetIDFromHexStr(b_cfg.trace_id.value());
Expand All @@ -199,6 +204,7 @@ Index<T>::RangeSearch(const DataSetPtr dataset, const Json& json, const BitsetVi
span->SetAttribute(meta::DIM, Dim());
span->SetAttribute(meta::NQ, dataset->GetRows());
}
// LCOV_EXCL_STOP

TimeRecorder rc("Range Search");
bool has_trace_id = b_cfg.trace_id.has_value();
Expand All @@ -207,9 +213,11 @@ Index<T>::RangeSearch(const DataSetPtr dataset, const Json& json, const BitsetVi
time *= 0.001; // convert to ms
knowhere_range_search_latency.Observe(time);

// LCOV_EXCL_START
if (has_trace_id) {
span->End();
}
// LCOV_EXCL_STOP
#else
auto res = this->node->RangeSearch(dataset, std::move(cfg), bitset);
#endif
Expand Down

0 comments on commit 028db90

Please sign in to comment.