Skip to content

Commit

Permalink
delete useless deps for milvus lite on knowhere
Browse files Browse the repository at this point in the history
Signed-off-by: yusheng.ma <[email protected]>
  • Loading branch information
Presburger committed Nov 20, 2024
1 parent 985c8e6 commit df71faf
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 14 deletions.
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ knowhere_option(WITH_LIGHT "Build with light weight version" OFF)
# cardinal is an enterprise vector search engine and can only be enabled for
# cloud environment
knowhere_option(WITH_CARDINAL "Build with cardinal" OFF)
knowhere_option(CARDINAL_VERSION_FORCE_CHECKOUT "Force checkout cardinal version" OFF)
knowhere_option(CARDINAL_VERSION_FORCE_CHECKOUT
"Force checkout cardinal version" OFF)
# this is needed for clang on ubuntu:20.04, otherwise the linked fails with
# 'undefined reference' error. fmt v9 was used by the time the error was
# encountered. clang on ubuntu:22.04 seems to be unaffected. gcc seems to be
Expand Down Expand Up @@ -97,10 +98,10 @@ find_package(nlohmann_json REQUIRED)
find_package(glog REQUIRED)
find_package(prometheus-cpp REQUIRED)
if(NOT WITH_RAFT)
find_package(fmt REQUIRED)
find_package(fmt REQUIRED)
endif()
if(NOT WITH_LIGHT)
find_package(opentelemetry-cpp REQUIRED)
find_package(opentelemetry-cpp REQUIRED)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_OSX_DEPLOYMENT_TARGET
Expand Down Expand Up @@ -131,8 +132,18 @@ if(NOT WITH_LIGHT)
endif()

if(WITH_LIGHT)
knowhere_file_glob(GLOB_RECURSE KNOWHERE_SRCS src/common/*.cc
src/index/hnsw/hnsw.cc src/io/*.cc src/index/index_factory.cc)
knowhere_file_glob(
GLOB_RECURSE
KNOWHERE_SRCS
src/common/*.cc
src/index/ivf/ivf.cc
src/index/index_node_data_mock_wrapper.cc
src/index/index_static.cc
src/index/index.cc
src/index/interrupt.cc
src/index/sparse/*.cc
src/io/*.cc
src/index/index_factory.cc)
knowhere_file_glob(GLOB_RECURSE KNOWHERE_TRACER_SRCS src/common/tracer.cc
src/common/prometheus_client.cc)
list(REMOVE_ITEM KNOWHERE_SRCS ${KNOWHERE_TRACER_SRCS})
Expand Down
6 changes: 5 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class KnowhereConan(ConanFile):
"with_benchmark": [True, False],
"with_coverage": [True, False],
"with_faiss_tests": [True, False],
"with_light": [True, False],
}
default_options = {
"shared": True,
Expand All @@ -50,6 +51,7 @@ class KnowhereConan(ConanFile):
"boost:without_test": True,
"fmt:header_only": True,
"with_faiss_tests": False,
"with_light": False,
}

exports_sources = (
Expand Down Expand Up @@ -95,7 +97,8 @@ def requirements(self):
self.requires("fmt/9.1.0")
self.requires("folly/2023.10.30.08@milvus/dev")
self.requires("libcurl/8.2.1")
self.requires("opentelemetry-cpp/1.8.1.1@milvus/dev")
if not self.options.with_light:
self.requires("opentelemetry-cpp/1.8.1.1@milvus/dev")
if self.settings.os != "Macos":
self.requires("libunwind/1.7.2")
if self.options.with_ut:
Expand Down Expand Up @@ -164,6 +167,7 @@ def generate(self):
tc.variables["WITH_BENCHMARK"] = self.options.with_benchmark
tc.variables["WITH_COVERAGE"] = self.options.with_coverage
tc.variables["WITH_FAISS_TESTS"] = self.options.with_faiss_tests
tc.variables["WITH_LIGHT"] = self.options.with_light
tc.generate()

deps = CMakeDeps(self)
Expand Down
30 changes: 30 additions & 0 deletions include/knowhere/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,42 @@

#pragma once

#include <any>
#include <memory>
#include <string>

#include "knowhere/config.h"
#ifndef KNOWHERE_WITH_LIGHT
#include "opentelemetry/trace/provider.h"
#endif

#define TRACE_SERVICE_KNOWHERE "knowhere"

namespace knowhere::tracer {

#ifdef KNOWHERE_WITH_LIGHT

namespace trace {
class Span {
public:
void
End() {
}
void
SetAttribute(const char* a, std::any b) {
}
};
class Tracer {
public:
static int
WithActiveSpan(std::shared_ptr<Span>& span) noexcept {
return 0;
}
};

}; // namespace trace
#endif

struct TraceConfig {
std::string exporter;
float sampleFraction;
Expand All @@ -35,7 +62,10 @@ struct TraceContext {
const uint8_t* spanID = nullptr;
uint8_t traceFlags = 0;
};

#ifndef KNOWHERE_WITH_LIGHT
namespace trace = opentelemetry::trace;
#endif

void
initTelemetry(const TraceConfig& cfg);
Expand Down
4 changes: 2 additions & 2 deletions src/common/comp/brute_force.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ BruteForce::SearchSparseWithBuf(const DataSetPtr base_dataset, const DataSetPtr
float* distances, const Json& config, const BitsetView& bitset) {
auto base = static_cast<const sparse::SparseRow<float>*>(base_dataset->GetTensor());
auto rows = base_dataset->GetRows();
auto dim = base_dataset->GetDim();
auto xb_id_offset = base_dataset->GetTensorBeginId();

auto xq = static_cast<const sparse::SparseRow<float>*>(query_dataset->GetTensor());
Expand All @@ -555,6 +554,7 @@ BruteForce::SearchSparseWithBuf(const DataSetPtr base_dataset, const DataSetPtr

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
auto dim = base_dataset->GetDim();
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 Down Expand Up @@ -776,7 +776,6 @@ BruteForce::AnnIterator<knowhere::sparse::SparseRow<float>>(const DataSetPtr bas
const BitsetView& bitset) {
auto base = static_cast<const sparse::SparseRow<float>*>(base_dataset->GetTensor());
auto rows = base_dataset->GetRows();
auto dim = base_dataset->GetDim();
auto xb_id_offset = base_dataset->GetTensorBeginId();

auto xq = static_cast<const sparse::SparseRow<float>*>(query_dataset->GetTensor());
Expand All @@ -795,6 +794,7 @@ BruteForce::AnnIterator<knowhere::sparse::SparseRow<float>>(const DataSetPtr bas

#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
// LCOV_EXCL_START
auto dim = base_dataset->GetDim();
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 Down
78 changes: 72 additions & 6 deletions src/common/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>
#include <utility>

#include "knowhere/log.h"

#ifndef KNOHWERE_WITH_LIGHT
#include "opentelemetry/exporters/jaeger/jaeger_exporter_factory.h"
#include "opentelemetry/exporters/ostream/span_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h"
Expand All @@ -29,9 +32,12 @@
#include "opentelemetry/sdk/version/version.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/trace/span_metadata.h"
#endif

namespace knowhere::tracer {

#ifndef KNOWHERE_WITH_LIGHT

namespace trace = opentelemetry::trace;
namespace nostd = opentelemetry::nostd;

Expand All @@ -56,12 +62,12 @@ initTelemetry(const TraceConfig& cfg) {
opts.endpoint = cfg.jaegerURL;
exporter = jaeger::JaegerExporterFactory::Create(opts);
LOG_KNOWHERE_INFO_ << "init jaeger exporter, endpoint: " << opts.endpoint;
// } else if (cfg.exporter == "otlp") {
// auto opts = otlp::OtlpGrpcExporterOptions{};
// opts.endpoint = cfg.otlpEndpoint;
// opts.use_ssl_credentials = cfg.oltpSecure;
// exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
// LOG_KNOWHERE_INFO_ << "init otlp exporter, endpoint: " << opts.endpoint;
} else if (cfg.exporter == "otlp") {
auto opts = otlp::OtlpGrpcExporterOptions{};
opts.endpoint = cfg.otlpEndpoint;
opts.use_ssl_credentials = cfg.oltpSecure;
exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
LOG_KNOWHERE_INFO_ << "init otlp exporter, endpoint: " << opts.endpoint;
} else {
LOG_KNOWHERE_INFO_ << "Empty Trace";
enable_trace = false;
Expand Down Expand Up @@ -143,6 +149,65 @@ EmptySpanID(const TraceContext* ctx) {
return isEmptyID(ctx->spanID, trace::SpanId::kSize);
}

tracer::TraceContext
GetTraceCtxFromCfg(const BaseConfig* cfg) {
auto trace_id = cfg->trace_id.value();
auto span_id = cfg->span_id.value();
auto trace_flags = cfg->trace_flags.value();
return tracer::TraceContext{trace_id.data(), span_id.data(), (uint8_t)trace_flags};
}
#endif

#ifdef KNOWHERE_WITH_LIGHT
void
initTelemetry(const TraceConfig& cfg) {
}

std::shared_ptr<trace::Tracer>
GetTracer() {
return std::make_shared<trace::Tracer>();
}

std::shared_ptr<trace::Span>
StartSpan(const std::string& name, TraceContext* parentCtx) {
return std::make_shared<trace::Span>();
}

thread_local std::shared_ptr<trace::Span> local_span;
void
SetRootSpan(std::shared_ptr<trace::Span> span) {
}

void
CloseRootSpan() {
}

void
AddEvent(const std::string& event_label) {
}

bool
isEmptyID(const uint8_t* id, int length) {
if (id != nullptr) {
for (int i = 0; i < length; i++) {
if (id[i] != 0) {
return false;
}
}
}
return true;
}

bool
EmptyTraceID(const TraceContext* ctx) {
return true;
}

bool
EmptySpanID(const TraceContext* ctx) {
return true;
}

std::string
BytesToHexStr(const uint8_t* data, size_t len) {
std::stringstream ss;
Expand All @@ -163,4 +228,5 @@ GetIDFromHexStr(const std::string& hexStr) {
return ss.str();
}

#endif
} // namespace knowhere::tracer

0 comments on commit df71faf

Please sign in to comment.