diff --git a/internal/core/src/common/Tracer.cpp b/internal/core/src/common/Tracer.cpp index 70544c6999..31b75cbc9c 100644 --- a/internal/core/src/common/Tracer.cpp +++ b/internal/core/src/common/Tracer.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include "opentelemetry/exporters/jaeger/jaeger_exporter_factory.h" @@ -164,23 +163,43 @@ EmptySpanID(const TraceContext* ctx) { return isEmptyID(ctx->spanID, trace::SpanId::kSize); } -std::vector -GetTraceIDAsVector(const TraceContext* ctx) { +std::string +BytesToHexStr(const uint8_t* data, const size_t len) { + std::stringstream ss; + for (size_t i = 0; i < len; i++) { + ss << std::hex << std::setw(2) << std::setfill('0') + << static_cast(data[i]); + } + return ss.str(); +} + +std::string +GetIDFromHexStr(const std::string& hexStr) { + std::stringstream ss; + for (size_t i = 0; i < hexStr.length(); i += 2) { + std::string byteStr = hexStr.substr(i, 2); + char byte = static_cast(std::stoi(byteStr, nullptr, 16)); + ss << byte; + } + return ss.str(); +} + +std::string +GetTraceIDAsHexStr(const TraceContext* ctx) { if (ctx != nullptr && !EmptyTraceID(ctx)) { - return std::vector( - ctx->traceID, ctx->traceID + opentelemetry::trace::TraceId::kSize); + return BytesToHexStr(ctx->traceID, + opentelemetry::trace::TraceId::kSize); } else { - return {}; + return std::string(); } } -std::vector -GetSpanIDAsVector(const TraceContext* ctx) { +std::string +GetSpanIDAsHexStr(const TraceContext* ctx) { if (ctx != nullptr && !EmptySpanID(ctx)) { - return std::vector( - ctx->spanID, ctx->spanID + opentelemetry::trace::SpanId::kSize); + return BytesToHexStr(ctx->spanID, opentelemetry::trace::SpanId::kSize); } else { - return {}; + return std::string(); } } diff --git a/internal/core/src/common/Tracer.h b/internal/core/src/common/Tracer.h index 26aec63f32..1d40c0a1ca 100644 --- a/internal/core/src/common/Tracer.h +++ b/internal/core/src/common/Tracer.h @@ -62,11 +62,17 @@ EmptyTraceID(const TraceContext* ctx); bool EmptySpanID(const TraceContext* ctx); -std::vector -GetTraceIDAsVector(const TraceContext* ctx); +std::string +BytesToHexStr(const uint8_t* data, const size_t len); -std::vector -GetSpanIDAsVector(const TraceContext* ctx); +std::string +GetIDFromHexStr(const std::string& hexStr); + +std::string +GetTraceIDAsHexStr(const TraceContext* ctx); + +std::string +GetSpanIDAsHexStr(const TraceContext* ctx); struct AutoSpan { explicit AutoSpan(const std::string& name, diff --git a/internal/core/src/index/VectorIndex.h b/internal/core/src/index/VectorIndex.h index 4c824d4887..540b93d4a7 100644 --- a/internal/core/src/index/VectorIndex.h +++ b/internal/core/src/index/VectorIndex.h @@ -126,9 +126,9 @@ class VectorIndex : public IndexBase { if (search_info.trace_ctx_.traceID != nullptr && search_info.trace_ctx_.spanID != nullptr) { search_cfg[knowhere::meta::TRACE_ID] = - tracer::GetTraceIDAsVector(&search_info.trace_ctx_); + tracer::GetTraceIDAsHexStr(&search_info.trace_ctx_); search_cfg[knowhere::meta::SPAN_ID] = - tracer::GetSpanIDAsVector(&search_info.trace_ctx_); + tracer::GetSpanIDAsHexStr(&search_info.trace_ctx_); search_cfg[knowhere::meta::TRACE_FLAGS] = search_info.trace_ctx_.traceFlags; } diff --git a/internal/core/src/query/SearchBruteForce.cpp b/internal/core/src/query/SearchBruteForce.cpp index 8497ff138b..b5f112c5b9 100644 --- a/internal/core/src/query/SearchBruteForce.cpp +++ b/internal/core/src/query/SearchBruteForce.cpp @@ -52,9 +52,9 @@ PrepareBFSearchParams(const SearchInfo& search_info) { if (search_info.trace_ctx_.traceID != nullptr && search_info.trace_ctx_.spanID != nullptr) { search_cfg[knowhere::meta::TRACE_ID] = - tracer::GetTraceIDAsVector(&search_info.trace_ctx_); + tracer::GetTraceIDAsHexStr(&search_info.trace_ctx_); search_cfg[knowhere::meta::SPAN_ID] = - tracer::GetSpanIDAsVector(&search_info.trace_ctx_); + tracer::GetSpanIDAsHexStr(&search_info.trace_ctx_); search_cfg[knowhere::meta::TRACE_FLAGS] = search_info.trace_ctx_.traceFlags; } diff --git a/internal/core/thirdparty/knowhere/CMakeLists.txt b/internal/core/thirdparty/knowhere/CMakeLists.txt index 5c3407d520..76c3fa39e3 100644 --- a/internal/core/thirdparty/knowhere/CMakeLists.txt +++ b/internal/core/thirdparty/knowhere/CMakeLists.txt @@ -13,7 +13,7 @@ # Update KNOWHERE_VERSION for the first occurrence set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES "") -set( KNOWHERE_VERSION 685bbf31 ) +set( KNOWHERE_VERSION c91e59b2 ) set( GIT_REPOSITORY "https://github.com/zilliztech/knowhere.git") message(STATUS "Knowhere repo: ${GIT_REPOSITORY}") message(STATUS "Knowhere version: ${KNOWHERE_VERSION}") diff --git a/internal/core/unittest/test_tracer.cpp b/internal/core/unittest/test_tracer.cpp index 4e2cfdc337..901a1c2316 100644 --- a/internal/core/unittest/test_tracer.cpp +++ b/internal/core/unittest/test_tracer.cpp @@ -16,7 +16,6 @@ #include "common/Tracer.h" #include "common/EasyAssert.h" -#include "common/Tracer.h" #include "knowhere/comp/index_param.h" #include "knowhere/config.h" @@ -47,74 +46,72 @@ TEST(Tracer, Span) { config->nodeID = 1; initTelemetry(*config); - const auto trace_id_vec = std::vector({0x01, - 0x23, - 0x45, - 0x67, - 0x89, - 0xab, - 0xcd, - 0xef, - 0xfe, - 0xdc, - 0xba, - 0x98, - 0x76, - 0x54, - 0x32, - 0x10}); - const auto span_id_vec = - std::vector({0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}); - auto ctx = std::make_shared(); - ctx->traceID = trace_id_vec.data(); - ctx->spanID = span_id_vec.data(); + ctx->traceID = new uint8_t[16]{0x01, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, + 0xfe, + 0xdc, + 0xba, + 0x98, + 0x76, + 0x54, + 0x32, + 0x10}; + ctx->spanID = + new uint8_t[8]{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}; ctx->traceFlags = 1; auto span = StartSpan("test", ctx.get()); ASSERT_TRUE(span->GetContext().trace_id() == trace::TraceId({ctx->traceID, 16})); + + delete[] ctx->traceID; + delete[] ctx->spanID; } -TEST(Tracer, Config) { - const auto trace_id_vec = std::vector({0x01, - 0x23, - 0x45, - 0x67, - 0x89, - 0xab, - 0xcd, - 0xef, - 0xfe, - 0xdc, - 0xba, - 0x98, - 0x76, - 0x54, - 0x32, - 0x10}); - const auto span_id_vec = - std::vector({0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}); - +TEST(Tracer, Hex) { auto ctx = std::make_shared(); - ctx->traceID = trace_id_vec.data(); - ctx->spanID = span_id_vec.data(); + ctx->traceID = new uint8_t[16]{0x01, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, + 0xfe, + 0xdc, + 0xba, + 0x98, + 0x76, + 0x54, + 0x32, + 0x10}; + ctx->spanID = + new uint8_t[8]{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}; ctx->traceFlags = 1; knowhere::Json search_cfg = {}; // save trace context into search conf search_cfg[knowhere::meta::TRACE_ID] = - tracer::GetTraceIDAsVector(ctx.get()); - search_cfg[knowhere::meta::SPAN_ID] = tracer::GetSpanIDAsVector(ctx.get()); + tracer::GetTraceIDAsHexStr(ctx.get()); + search_cfg[knowhere::meta::SPAN_ID] = tracer::GetSpanIDAsHexStr(ctx.get()); search_cfg[knowhere::meta::TRACE_FLAGS] = ctx->traceFlags; std::cout << "search config: " << search_cfg.dump() << std::endl; - auto trace_id_cfg = - search_cfg[knowhere::meta::TRACE_ID].get>(); - auto span_id_cfg = - search_cfg[knowhere::meta::SPAN_ID].get>(); + auto trace_id_str = GetIDFromHexStr(search_cfg[knowhere::meta::TRACE_ID]); + auto span_id_str = GetIDFromHexStr(search_cfg[knowhere::meta::SPAN_ID]); - ASSERT_TRUE(memcmp(ctx->traceID, trace_id_cfg.data(), 16) == 0); - ASSERT_TRUE(memcmp(ctx->spanID, span_id_cfg.data(), 8) == 0); + ASSERT_TRUE(strncmp((char*)ctx->traceID, trace_id_str.c_str(), 16) == 0); + ASSERT_TRUE(strncmp((char*)ctx->spanID, span_id_str.c_str(), 8) == 0); + + delete[] ctx->traceID; + delete[] ctx->spanID; }