Skip to content

Commit

Permalink
Add tls check option configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Nov 5, 2024
1 parent c0f229c commit 820dcc7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
10 changes: 6 additions & 4 deletions .docker/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318

exporters:
logging:
debug:
prometheus:
endpoint: "0.0.0.0:8889"
const_labels:
otel: otel
otlp:
otlp/jaeger:
endpoint: "jaeger:4317"
tls:
insecure: true
Expand All @@ -25,8 +27,8 @@ service:
exporters: [prometheus]
traces:
receivers: [otlp]
exporters: [otlp]
exporters: [otlp/jaeger]
logs:
receivers: [otlp]
processors: [batch]
exporters: [logging]
exporters: [debug]
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.13
4.0.14
2 changes: 1 addition & 1 deletion ansible-imalive/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
imalive_api_version: 4.0.11
imalive_api_version: 4.0.14
imalive_port: 8099
imalive_wait_time: 300
imalive_force_recreate: true
Expand Down
4 changes: 4 additions & 0 deletions ansible-imalive/templates/.env.imalive.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ IMALIVE_NODE_NAME={{ node_name }}
OTEL_COLLECTOR_ENDPOINT={{ imalive_otel_collector_endpoint }}
{% endif %}

{% if imalive_otel_collector_tls_check is defined and imalive_otel_collector_tls_check %}
OTEL_COLLECTOR_TLS_CHECK={{ imalive_otel_collector_tls_check }}
{% endif %}

{% if imalive_otel_collector_username is defined and imalive_otel_collector_username %}
OTEL_COLLECTOR_USERNAME={{ imalive_otel_collector_username }}
{% endif %}
Expand Down
5 changes: 5 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ spec:
value: {{ $.Values.otlp_endpoint | quote }}
{{ end }}

{{ if $.Values.otlp_tls_check }}
- name: OTEL_COLLECTOR_TLS_CHECK
value: {{ $.Values.otlp_tls_check | quote }}
{{ end }}

{{ if $.Values.otlp_username }}
- name: OTEL_COLLECTOR_USERNAME
value: {{ $.Values.otlp_username | quote }}
Expand Down
9 changes: 5 additions & 4 deletions src/utils/otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter

from utils.common import is_enabled, is_not_empty
from utils.common import is_enabled, is_false, is_not_empty

_otel_tracer = trace.get_tracer(__name__)
_otel_collector_endpoint = os.getenv('OTEL_COLLECTOR_ENDPOINT')
_otel_service_name = "imalive-{}".format(os.getenv('IMALIVE_NODE_NAME', "anode"))
_otel_service_version = os.getenv('VERSION', '0.1')
_otel_collector_tls_disable_check = is_false(os.getenv('OTEL_COLLECTOR_TLS_CHECK', 'false'))

_otel_collector_username = os.getenv('OTEL_COLLECTOR_USERNAME')
_otel_collector_password = os.getenv('OTEL_COLLECTOR_PASSWORD')
Expand Down Expand Up @@ -56,16 +57,16 @@ def init_otel_tracer():
trace.set_tracer_provider(TracerProvider(resource=_otel_resource))

if is_enabled(_otel_collector_endpoint):
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint=_otel_collector_endpoint, credentials=credentials, insecure=True)))
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint=_otel_collector_endpoint, credentials=credentials, insecure=_otel_collector_tls_disable_check)))

def init_otel_metrics():
if is_enabled(_otel_collector_endpoint):
otlp_exporter = OTLPMetricExporter(endpoint=_otel_collector_endpoint, credentials=credentials, insecure=True)
otlp_exporter = OTLPMetricExporter(endpoint=_otel_collector_endpoint, credentials=credentials, insecure=_otel_collector_tls_disable_check)
set_meter_provider(MeterProvider(resource=_otel_resource, metric_readers=[PeriodicExportingMetricReader(otlp_exporter, export_interval_millis=5000)]))

def init_otel_logger():
if is_enabled(_otel_collector_endpoint):
otlp_exporter = OTLPLogExporter(endpoint=_otel_collector_endpoint, credentials=credentials, insecure=True)
otlp_exporter = OTLPLogExporter(endpoint=_otel_collector_endpoint, credentials=credentials, insecure=_otel_collector_tls_disable_check)
_logger_provider.add_log_record_processor(BatchLogRecordProcessor(otlp_exporter))
handler = LoggingHandler(level=logging.NOTSET, logger_provider=_logger_provider)
logging.getLogger().addHandler(handler)
Expand Down

0 comments on commit 820dcc7

Please sign in to comment.