enhance: Support otlp with insecure (#29115)

issue: https://github.com/milvus-io/milvus/issues/28914

Signed-off-by: Enwei Jiao <enwei.jiao@zilliz.com>
This commit is contained in:
Enwei Jiao 2023-12-12 11:14:37 +08:00 committed by GitHub
parent 0a87724f18
commit 0e65e90338
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 7 deletions

View File

@ -703,12 +703,15 @@ quotaAndLimits:
trace: trace:
# trace exporter type, default is stdout, # trace exporter type, default is stdout,
# optional values: ['stdout', 'jaeger'] # optional values: ['stdout', 'jaeger', 'otlp']
exporter: stdout exporter: stdout
# fraction of traceID based sampler, # fraction of traceID based sampler,
# optional values: [0, 1] # optional values: [0, 1]
# Fractions >= 1 will always sample. Fractions < 0 are treated as zero. # Fractions >= 1 will always sample. Fractions < 0 are treated as zero.
sampleFraction: 0 sampleFraction: 0
otlp:
endpoint: # "127.0.0.1:4318"
secure: true
jaeger: jaeger:
url: # "http://127.0.0.1:14268/api/traces" url: # "http://127.0.0.1:14268/api/traces"
# when exporter is jaeger should set the jaeger's URL # when exporter is jaeger should set the jaeger's URL

View File

@ -54,6 +54,7 @@ initTelementry(TraceConfig* config) {
} else if (config->exporter == "otlp") { } else if (config->exporter == "otlp") {
auto opts = otlp::OtlpGrpcExporterOptions{}; auto opts = otlp::OtlpGrpcExporterOptions{};
opts.endpoint = config->otlpEndpoint; opts.endpoint = config->otlpEndpoint;
opts.use_ssl_credentials = config->oltpSecure;
exporter = otlp::OtlpGrpcExporterFactory::Create(opts); exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
LOG_SEGCORE_INFO_ << "init otlp exporter, endpoint:" << opts.endpoint; LOG_SEGCORE_INFO_ << "init otlp exporter, endpoint:" << opts.endpoint;
} else { } else {

View File

@ -24,6 +24,7 @@ struct TraceConfig {
int sampleFraction; int sampleFraction;
std::string jaegerURL; std::string jaegerURL;
std::string otlpEndpoint; std::string otlpEndpoint;
bool oltpSecure;
int nodeID; int nodeID;
}; };

View File

@ -76,6 +76,7 @@ InitTrace(CTraceConfig* config) {
config->sampleFraction, config->sampleFraction,
config->jaegerURL, config->jaegerURL,
config->otlpEndpoint, config->otlpEndpoint,
config->oltpSecure,
config->nodeID}; config->nodeID};
std::call_once( std::call_once(
traceFlag, traceFlag,

View File

@ -95,6 +95,7 @@ typedef struct CTraceConfig {
int sampleFraction; int sampleFraction;
const char* jaegerURL; const char* jaegerURL;
const char* otlpEndpoint; const char* otlpEndpoint;
bool oltpSecure;
int nodeID; int nodeID;
} CTraceConfig; } CTraceConfig;

View File

@ -45,7 +45,14 @@ func Init() {
exp, err = jaeger.New(jaeger.WithCollectorEndpoint( exp, err = jaeger.New(jaeger.WithCollectorEndpoint(
jaeger.WithEndpoint(params.TraceCfg.JaegerURL.GetValue()))) jaeger.WithEndpoint(params.TraceCfg.JaegerURL.GetValue())))
case "otlp": 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": case "stdout":
exp, err = stdout.New() exp, err = stdout.New()
default: default:

View File

@ -671,6 +671,7 @@ type traceConfig struct {
SampleFraction ParamItem `refreshable:"false"` SampleFraction ParamItem `refreshable:"false"`
JaegerURL ParamItem `refreshable:"false"` JaegerURL ParamItem `refreshable:"false"`
OtlpEndpoint ParamItem `refreshable:"false"` OtlpEndpoint ParamItem `refreshable:"false"`
OtlpSecure ParamItem `refreshable:"false"`
} }
func (t *traceConfig) init(base *BaseTable) { func (t *traceConfig) init(base *BaseTable) {
@ -705,8 +706,16 @@ Fractions >= 1 will always sample. Fractions < 0 are treated as zero.`,
t.OtlpEndpoint = ParamItem{ t.OtlpEndpoint = ParamItem{
Key: "trace.otlp.endpoint", Key: "trace.otlp.endpoint",
Version: "2.3.0", Version: "2.3.0",
Doc: "example: \"127.0.0.1:4318\"",
} }
t.OtlpEndpoint.Init(base.mgr) 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 { type logConfig struct {