@@ -309,6 +309,62 @@ def test_ignores_non_elastic_filename(self, get_logger_mock, handle_logging_mock
309309 agent .send .assert_called_once_with (payload = mock .ANY )
310310 client ._build_full_state_message .assert_not_called ()
311311
312+ @mock .patch ("elasticotel.distro.config._get_config" )
313+ @mock .patch ("elasticotel.distro.config.logger" )
314+ def test_fails_if_cannot_decode_elastic_config_json (self , logger_mock , get_config_mock ):
315+ get_config_mock .return_value = Config ()
316+ agent = mock .Mock ()
317+ client = mock .Mock ()
318+ config = opamp_pb2 .AgentConfigMap ()
319+ config .config_map ["elastic" ].body = b"{"
320+ config .config_map ["elastic" ].content_type = "application/json"
321+ remote_config = opamp_pb2 .AgentRemoteConfig (config = config , config_hash = b"1234" )
322+ message = opamp_pb2 .ServerToAgent (remote_config = remote_config )
323+ opamp_handler (agent , client , message )
324+
325+ error_message = "Failed to decode elastic with content type application/json: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"
326+ logger_mock .error .assert_called_once_with (error_message )
327+
328+ client ._update_remote_config_status .assert_called_once_with (
329+ remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_FAILED , error_message = error_message
330+ )
331+ client ._update_effective_config .assert_called_once_with (
332+ {"elastic" : {"logging_level" : "info" , "sampling_rate" : "1.0" }}
333+ )
334+ client ._build_remote_config_status_response_message .assert_called_once_with (
335+ client ._update_remote_config_status ()
336+ )
337+ agent .send .assert_called_once_with (payload = mock .ANY )
338+ client ._build_full_state_message .assert_not_called ()
339+
340+ @mock .patch ("elasticotel.distro.config._get_config" )
341+ @mock .patch ("elasticotel.distro.config.logger" )
342+ def test_fails_if_elastic_config_is_not_json (self , logger_mock , get_config_mock ):
343+ get_config_mock .return_value = Config ()
344+ agent = mock .Mock ()
345+ client = mock .Mock ()
346+ config = opamp_pb2 .AgentConfigMap ()
347+ config .config_map ["elastic" ].body = b"not-json"
348+ config .config_map ["elastic" ].content_type = "not/json"
349+ remote_config = opamp_pb2 .AgentRemoteConfig (config = config , config_hash = b"1234" )
350+ message = opamp_pb2 .ServerToAgent (remote_config = remote_config )
351+ opamp_handler (agent , client , message )
352+
353+ error_message = "Cannot parse elastic with content type not/json"
354+ logger_mock .error .assert_called_once_with (error_message )
355+
356+ client ._update_remote_config_status .assert_called_once_with (
357+ remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_FAILED , error_message = error_message
358+ )
359+ client ._update_effective_config .assert_called_once_with (
360+ {"elastic" : {"logging_level" : "info" , "sampling_rate" : "1.0" }}
361+ )
362+ client ._build_remote_config_status_response_message .assert_called_once_with (
363+ client ._update_remote_config_status ()
364+ )
365+ agent .send .assert_called_once_with (payload = mock .ANY )
366+ client ._build_full_state_message .assert_not_called ()
367+
312368 @mock .patch ("elasticotel.distro.config._get_config" )
313369 @mock .patch .object (logging , "getLogger" )
314370 def test_sets_matching_logging_level (self , get_logger_mock , get_config_mock ):
0 commit comments