in codeguru_profiler_agent/sdk_reporter/sdk_reporter.py [0:0]
def refresh_configuration(self):
"""
Refresh the agent configuration by calling the profiler backend service.
Note:
For an agent running on AWS Lambda, if the environment variables for Profiling using
Lambda layers are set, it tries to create a Profiling Group whenever a ResourceNotFoundException
is encountered.
"""
try:
fleet_instance_id = self.metadata.fleet_info.get_fleet_instance_id()
metadata = self.metadata.fleet_info.get_metadata_for_configure_agent_call()
configuration = self.codeguru_client_builder.codeguru_client.configure_agent(
fleetInstanceId=fleet_instance_id,
metadata=metadata if metadata is not None else {},
profilingGroupName=self.profiling_group_name
).get('configuration')
logger.debug("Got response from backend for configure_agent operation: " + str(configuration))
self.agent_config_merger.merge_with(configure_agent_response=configuration)
except ClientError as error:
# If we get a validation error or the profiling group does not exists, do not profile. We do not stop the
# whole process because the customer may fix this on their side by creating/changing the profiling group.
# We handle service exceptions like this in boto3
# see https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html
if error.response['Error']['Code'] == 'ValidationException':
self.errors_metadata.record_sdk_error("configureAgentErrors")
self.agent_config_merger.disable_profiling()
self._log_request_failed(operation="configure_agent", exception=error)
elif error.response['Error']['Code'] == 'ResourceNotFoundException':
if self.should_auto_create_profiling_group():
self.errors_metadata.record_sdk_error("configureAgentRnfeAutoCreateEnabledErrors")
logger.info(
"Profiling group not found. Will try to create a profiling group "
"with name = {} and compute platform = {} and retry calling configure agent after 5 minutes. "
"Make sure that Lambda's execution role has AmazonCodeGuruProfilerAgentAccess policy added."
.format(self.profiling_group_name, 'AWSLambda'))
self.create_profiling_group()
else:
self.errors_metadata.record_sdk_error("configureAgentErrors")
self.agent_config_merger.disable_profiling()
else:
self.errors_metadata.record_sdk_error("configureAgentErrors")
except Exception as e:
self._log_request_failed(operation="configure_agent", exception=e)