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 <yudong.cai@zilliz.com>
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-01-18 12:43:05 +08:00 committed by GitHub
parent 3ec02826bf
commit 14aa20b7f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

View File

@ -19,7 +19,7 @@ namespace milvus::tracer {
struct TraceConfig {
std::string exporter;
int sampleFraction;
float sampleFraction;
std::string jaegerURL;
std::string otlpEndpoint;
bool oltpSecure;

View File

@ -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;

View File

@ -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)
}