From a875e17b9af1386318cbeff5a8d997bdadb0a012 Mon Sep 17 00:00:00 2001 From: Enwei Jiao Date: Mon, 11 Dec 2023 16:40:40 +0800 Subject: [PATCH] Support otlp with insecure Signed-off-by: Enwei Jiao --- configs/milvus.yaml | 15 +++++++++------ internal/core/src/common/Tracer.cpp | 1 + internal/core/src/common/Tracer.h | 1 + internal/core/src/common/init_c.cpp | 1 + internal/core/src/common/type_c.h | 1 + pkg/tracer/tracer.go | 9 ++++++++- pkg/util/paramtable/component_param.go | 9 +++++++++ 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/configs/milvus.yaml b/configs/milvus.yaml index ded657338986f..0600699172ca9 100644 --- a/configs/milvus.yaml +++ b/configs/milvus.yaml @@ -203,15 +203,15 @@ proxy: accessLog: enable: false # Log filename, set as "" to use stdout. - # filename: "" + # filename: "" # define formatters for access log by XXX:{format: XXX, method:[XXX,XXX]} formatters: # "base" formatter could not set methods # all method will use "base" formatter default - base: + base: # will not print access log if set as "" format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name [status: $method_status] [code: $error_code] [sdk: $sdk_version] [msg: $error_msg] [traceID: $trace_id] [timeCost: $time_cost]" - query: + query: format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name [status: $method_status] [code: $error_code] [sdk: $sdk_version] [msg: $error_msg] [traceID: $trace_id] [timeCost: $time_cost] [database: $database_name] [collection: $collection_name] [partitions: $partition_name] [expr: $method_expr]" # set formatter owners by method name(method was all milvus external interface) # all method will use base formatter default @@ -223,7 +223,7 @@ proxy: # rotatedTime: 0 # max time range of singal log file, mean close when time <= 0; # maxBackups: 8 # num of reserved backups. will rotate and crate a new backup when access log file trigger maxSize or rotatedTime. # cacheSize: 10240 # write cache of accesslog in Byte - + # minioEnable: false # update backups to milvus minio when minioEnable is true. # remotePath: "access_log/" # file path when update backups to minio # remoteMaxTime: 0 # max time range(in Hour) of backups in minio, 0 means close time retention. @@ -292,7 +292,7 @@ queryNode: enableIndex: true nlist: 128 # segment index nlist nprobe: 16 # nprobe to search segment, based on your accuracy requirement, must smaller than nlist - memExpansionRate: 1.15 # the ratio of building interim index memory usage to raw data + memExpansionRate: 1.15 # the ratio of building interim index memory usage to raw data loadMemoryUsageFactor: 1 # The multiply factor of calculating the memory usage while loading segments enableDisk: false # enable querynode load disk index, and search on disk index maxDiskUsagePercentage: 95 @@ -692,12 +692,15 @@ quotaAndLimits: trace: # trace exporter type, default is stdout, - # optional values: ['stdout', 'jaeger'] + # optional values: ['stdout', 'jaeger', 'otlp'] exporter: stdout # fraction of traceID based sampler, # optional values: [0, 1] # Fractions >= 1 will always sample. Fractions < 0 are treated as zero. sampleFraction: 0 + otlp: + endpoint: # "127.0.0.1:4318" + secure: true jaeger: url: # "http://127.0.0.1:14268/api/traces" # when exporter is jaeger should set the jaeger's URL diff --git a/internal/core/src/common/Tracer.cpp b/internal/core/src/common/Tracer.cpp index 21a4c637092f2..a12cb84394248 100644 --- a/internal/core/src/common/Tracer.cpp +++ b/internal/core/src/common/Tracer.cpp @@ -54,6 +54,7 @@ initTelementry(TraceConfig* config) { } else if (config->exporter == "otlp") { auto opts = otlp::OtlpGrpcExporterOptions{}; opts.endpoint = config->otlpEndpoint; + opts.use_ssl_credentials = config->oltpSecure; exporter = otlp::OtlpGrpcExporterFactory::Create(opts); LOG_SEGCORE_INFO_ << "init otlp exporter, endpoint:" << opts.endpoint; } else { diff --git a/internal/core/src/common/Tracer.h b/internal/core/src/common/Tracer.h index 08e900f42817e..bcca453f1fffb 100644 --- a/internal/core/src/common/Tracer.h +++ b/internal/core/src/common/Tracer.h @@ -22,6 +22,7 @@ struct TraceConfig { int sampleFraction; std::string jaegerURL; std::string otlpEndpoint; + bool oltpSecure; int nodeID; }; diff --git a/internal/core/src/common/init_c.cpp b/internal/core/src/common/init_c.cpp index ddef38319ac4d..0f166d9422d44 100644 --- a/internal/core/src/common/init_c.cpp +++ b/internal/core/src/common/init_c.cpp @@ -76,6 +76,7 @@ InitTrace(CTraceConfig* config) { config->sampleFraction, config->jaegerURL, config->otlpEndpoint, + config->oltpSecure, config->nodeID}; std::call_once( traceFlag, diff --git a/internal/core/src/common/type_c.h b/internal/core/src/common/type_c.h index e432e899e6f69..9fcd66e3b9b3e 100644 --- a/internal/core/src/common/type_c.h +++ b/internal/core/src/common/type_c.h @@ -93,6 +93,7 @@ typedef struct CTraceConfig { int sampleFraction; const char* jaegerURL; const char* otlpEndpoint; + bool oltpSecure; int nodeID; } CTraceConfig; diff --git a/pkg/tracer/tracer.go b/pkg/tracer/tracer.go index 78386610430ef..b509a74d5e206 100644 --- a/pkg/tracer/tracer.go +++ b/pkg/tracer/tracer.go @@ -45,7 +45,14 @@ func Init() { exp, err = jaeger.New(jaeger.WithCollectorEndpoint( jaeger.WithEndpoint(params.TraceCfg.JaegerURL.GetValue()))) case "otlp": - exp, err = otlptracegrpc.New(context.Background(), otlptracegrpc.WithEndpoint(params.TraceCfg.OtlpEndpoint.GetValue())) + secure := params.TraceCfg.OtlpSecure.GetAsBool() + opts := []otlptracegrpc.Option{ + otlptracegrpc.WithEndpoint(params.TraceCfg.OtlpEndpoint.GetValue()), + } + if !secure { + opts = append(opts, otlptracegrpc.WithInsecure()) + } + exp, err = otlptracegrpc.New(context.Background(), opts...) case "stdout": exp, err = stdout.New() default: diff --git a/pkg/util/paramtable/component_param.go b/pkg/util/paramtable/component_param.go index 3f23d07fce540..1e3db079c73b1 100644 --- a/pkg/util/paramtable/component_param.go +++ b/pkg/util/paramtable/component_param.go @@ -642,6 +642,7 @@ type traceConfig struct { SampleFraction ParamItem `refreshable:"false"` JaegerURL ParamItem `refreshable:"false"` OtlpEndpoint ParamItem `refreshable:"false"` + OtlpSecure ParamItem `refreshable:"false"` } func (t *traceConfig) init(base *BaseTable) { @@ -676,8 +677,16 @@ Fractions >= 1 will always sample. Fractions < 0 are treated as zero.`, t.OtlpEndpoint = ParamItem{ Key: "trace.otlp.endpoint", Version: "2.3.0", + Doc: "example: \"127.0.0.1:4318\"", } t.OtlpEndpoint.Init(base.mgr) + + t.OtlpSecure = ParamItem{ + Key: "trace.otlp.secure", + Version: "2.4.0", + DefaultValue: "true", + } + t.OtlpSecure.Init(base.mgr) } type logConfig struct {