Merge pull request #15674 from ninjadq/add_validation_for_tracing

Add validation for tracing
This commit is contained in:
Qian Deng 2021-09-29 18:13:46 +08:00 committed by GitHub
commit 18c236d3cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -161,8 +161,10 @@ class JaegerExporter:
self.agent_port = config.get('agent_port')
def validate(self):
if not self.endpoint and self.agent_host is None:
raise Exception('Jaeger Colector Endpoint or Agent host not set')
if not self.endpoint and not self.agent_host:
raise Exception('Jaeger Colector Endpoint or Agent host not set, must set one')
if self.endpoint and self.agent_host:
raise Exception('Jaeger Colector Endpoint and Agent host both set, only can set one')
class OtelExporter:
def __init__(self, config: dict):
@ -192,9 +194,13 @@ class Trace:
self.attributes = config.get('attributes') or {}
def validate(self):
if not self.jaeger.enabled and not self.enabled:
if not self.enabled:
return
if not self.jaeger.enabled and not self.otel.enabled:
raise Exception('Trace enabled but no trace exporter set')
if self.jaeger.enabled:
JaegerExporter(self.jaeger).validate()
if self.otel.enabled:
OtelExporter(self.otel).validate()
elif self.jaeger.enabled and self.otel.enabled:
raise Exception('Only can have one trace exporter at a time')
elif self.jaeger.enabled:
self.jaeger.validate()
elif self.otel.enabled:
self.otel.validate()

View File

@ -76,6 +76,8 @@ def validate(conf: dict, **kwargs):
# TODO:
# If user enable trust cert dir, need check if the files in this dir is readable.
if conf.get('trace'):
conf['trace'].validate()
def parse_versions():
if not versions_file_path.is_file():