Add validation for tracing

* add  validation of tracing in validating process

Signed-off-by: Qian Deng <dengq@vmware.com>
This commit is contained in:
Qian Deng 2021-09-27 07:38:29 +00:00
parent fc1db450b2
commit 3c23926bdc
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():