From 14aa20b7f7aea82cb5dedd7029defd2da7eae9ae Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 18 Jan 2024 12:43:05 +0800 Subject: [PATCH] enhance: [cherry-pick] fix otel config param type & leak (#30068) cherry pick from master pr: #29810 #30055 `SampleFraction` shall be float and all `C.CString` shall be freed Signed-off-by: Yudong Cai Signed-off-by: Congqi Xia --- internal/core/src/common/Tracer.h | 2 +- internal/core/src/common/type_c.h | 2 +- internal/util/initcore/init_core.go | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/internal/core/src/common/Tracer.h b/internal/core/src/common/Tracer.h index bcca453f1f..ba29828164 100644 --- a/internal/core/src/common/Tracer.h +++ b/internal/core/src/common/Tracer.h @@ -19,7 +19,7 @@ namespace milvus::tracer { struct TraceConfig { std::string exporter; - int sampleFraction; + float sampleFraction; std::string jaegerURL; std::string otlpEndpoint; bool oltpSecure; diff --git a/internal/core/src/common/type_c.h b/internal/core/src/common/type_c.h index f9eed84fe7..48eb069373 100644 --- a/internal/core/src/common/type_c.h +++ b/internal/core/src/common/type_c.h @@ -92,7 +92,7 @@ typedef struct CStorageConfig { typedef struct CTraceConfig { const char* exporter; - int sampleFraction; + float sampleFraction; const char* jaegerURL; const char* otlpEndpoint; bool oltpSecure; diff --git a/internal/util/initcore/init_core.go b/internal/util/initcore/init_core.go index a9cd20d561..51f47f194c 100644 --- a/internal/util/initcore/init_core.go +++ b/internal/util/initcore/init_core.go @@ -45,12 +45,21 @@ func InitLocalChunkManager(path string) { } func InitTraceConfig(params *paramtable.ComponentParam) { + sampleFraction := C.float(params.TraceCfg.SampleFraction.GetAsFloat()) + nodeID := C.int(paramtable.GetNodeID()) + exporter := C.CString(params.TraceCfg.Exporter.GetValue()) + jaegerURL := C.CString(params.TraceCfg.JaegerURL.GetValue()) + endpoint := C.CString(params.TraceCfg.OtlpEndpoint.GetValue()) + defer C.free(unsafe.Pointer(exporter)) + defer C.free(unsafe.Pointer(jaegerURL)) + defer C.free(unsafe.Pointer(endpoint)) + config := C.CTraceConfig{ - exporter: C.CString(params.TraceCfg.Exporter.GetValue()), - sampleFraction: C.int(params.TraceCfg.SampleFraction.GetAsInt()), - jaegerURL: C.CString(params.TraceCfg.JaegerURL.GetValue()), - otlpEndpoint: C.CString(params.TraceCfg.OtlpEndpoint.GetValue()), - nodeID: C.int(paramtable.GetNodeID()), + exporter: exporter, + sampleFraction: sampleFraction, + jaegerURL: jaegerURL, + otlpEndpoint: endpoint, + nodeID: nodeID, } C.InitTrace(&config) }