2121
2222from elasticotel .distro import ElasticOpenTelemetryConfigurator , ElasticOpenTelemetryDistro , logger as distro_logger
2323from elasticotel .distro .config import opamp_handler , logger as config_logger , Config
24- from elasticotel .distro .environment_variables import ELASTIC_OTEL_OPAMP_ENDPOINT , ELASTIC_OTEL_SYSTEM_METRICS_ENABLED
24+ from elasticotel .distro .environment_variables import (
25+ ELASTIC_OTEL_OPAMP_ENDPOINT ,
26+ ELASTIC_OTEL_OPAMP_CERTIFICATE ,
27+ ELASTIC_OTEL_OPAMP_CLIENT_CERTIFICATE ,
28+ ELASTIC_OTEL_OPAMP_CLIENT_KEY ,
29+ ELASTIC_OTEL_SYSTEM_METRICS_ENABLED ,
30+ )
2531from elasticotel .sdk .sampler import DefaultSampler
2632from opentelemetry .environment_variables import (
2733 OTEL_LOGS_EXPORTER ,
@@ -162,6 +168,9 @@ def test_configurator_sets_up_opamp_with_http_endpoint(self, client_mock, agent_
162168 endpoint = "http://localhost:4320/v1/opamp" ,
163169 agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
164170 headers = None ,
171+ tls_certificate = True ,
172+ tls_client_certificate = None ,
173+ tls_client_key = None ,
165174 )
166175 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
167176 agent_mock .start .assert_called_once_with ()
@@ -186,6 +195,9 @@ def test_configurator_sets_up_opamp_with_https_endpoint(self, client_mock, agent
186195 endpoint = "https://localhost:4320/v1/opamp" ,
187196 agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
188197 headers = None ,
198+ tls_certificate = True ,
199+ tls_client_certificate = None ,
200+ tls_client_key = None ,
189201 )
190202 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
191203 agent_mock .start .assert_called_once_with ()
@@ -211,6 +223,9 @@ def test_configurator_sets_up_opamp_with_headers_from_environment_variable(self,
211223 endpoint = "http://localhost:4320/v1/opamp" ,
212224 agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
213225 headers = {"authorization" : "ApiKey foobar===" },
226+ tls_certificate = True ,
227+ tls_client_certificate = None ,
228+ tls_client_key = None ,
214229 )
215230 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
216231 agent_mock .start .assert_called_once_with ()
@@ -235,6 +250,9 @@ def test_configurator_adds_path_to_opamp_endpoint_if_missing(self, client_mock,
235250 endpoint = "https://localhost:4320/v1/opamp" ,
236251 agent_identifying_attributes = {"service.name" : "service" , "deployment.environment.name" : "dev" },
237252 headers = None ,
253+ tls_certificate = True ,
254+ tls_client_certificate = None ,
255+ tls_client_key = None ,
238256 )
239257 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
240258 agent_mock .start .assert_called_once_with ()
@@ -259,6 +277,39 @@ def test_configurator_sets_up_opamp_without_deployment_environment_name(self, cl
259277 endpoint = "https://localhost:4320/v1/opamp" ,
260278 agent_identifying_attributes = {"service.name" : "service" },
261279 headers = None ,
280+ tls_certificate = True ,
281+ tls_client_certificate = None ,
282+ tls_client_key = None ,
283+ )
284+ agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
285+ agent_mock .start .assert_called_once_with ()
286+
287+ @mock .patch .dict (
288+ "os.environ" ,
289+ {
290+ ELASTIC_OTEL_OPAMP_ENDPOINT : "https://localhost:4320/v1/opamp" ,
291+ ELASTIC_OTEL_OPAMP_CERTIFICATE : "server.pem" ,
292+ ELASTIC_OTEL_OPAMP_CLIENT_CERTIFICATE : "client.pem" ,
293+ ELASTIC_OTEL_OPAMP_CLIENT_KEY : "client.key" ,
294+ "OTEL_RESOURCE_ATTRIBUTES" : "service.name=service" ,
295+ },
296+ clear = True ,
297+ )
298+ @mock .patch ("elasticotel.distro.OpAMPAgent" )
299+ @mock .patch ("elasticotel.distro.OpAMPClient" )
300+ def test_configurator_sets_up_opamp_with_mTLS_variables (self , client_mock , agent_mock ):
301+ client_mock .return_value = client_mock
302+ agent_mock .return_value = agent_mock
303+
304+ ElasticOpenTelemetryConfigurator ()._configure ()
305+
306+ client_mock .assert_called_once_with (
307+ endpoint = "https://localhost:4320/v1/opamp" ,
308+ agent_identifying_attributes = {"service.name" : "service" },
309+ headers = None ,
310+ tls_certificate = "server.pem" ,
311+ tls_client_certificate = "client.pem" ,
312+ tls_client_key = "client.key" ,
262313 )
263314 agent_mock .assert_called_once_with (interval = 30 , message_handler = opamp_handler , client = client_mock )
264315 agent_mock .start .assert_called_once_with ()
0 commit comments