def _create_lambda_profiler(profiling_group_name, region_name, environment_override, context, env=os.environ):
    """
    Calls build_profiler module to create the profiler object. If we fail to create it we return a no-op profiler
    so that we don't even go through this method again.
    """
    from codeguru_profiler_agent.profiler_builder import build_profiler
    from codeguru_profiler_agent.agent_metadata.agent_metadata import AgentMetadata
    from codeguru_profiler_agent.agent_metadata.aws_lambda import AWSLambda
    override = {'agent_metadata': AgentMetadata(AWSLambda.look_up_metadata(context))}
    override.update(environment_override)
    profiler = build_profiler(pg_name=profiling_group_name, region_name=region_name, override=override, env=env)
    if profiler is None:
        return _EmptyProfiler()
    return profiler
コード例 #2
0
 def test_it_returns_none(self):
     subject = AWSLambda.look_up_metadata(context=None, env={})
     assert subject is None
コード例 #3
0
 def test_memory_limit_is_set_to_none(self):
     subject = AWSLambda.look_up_metadata(
         self.context, self.env)
     assert subject.memory_limit_mb is None
コード例 #4
0
 def test_it_finds_the_execution_env(self):
     subject = AWSLambda.look_up_metadata(
         self.context, self.env)
     assert subject.execution_env == "AWS_Lambda_python3.6"
コード例 #5
0
 def test_it_still_returns_the_arn(self):
     subject = AWSLambda.look_up_metadata(self.context, {})
     assert subject.function_arn == "the_lambda_function_arn"
コード例 #6
0
 def test_when_env_is_not_available_other_values_are_set_to_none(
         self):
     subject = AWSLambda.look_up_metadata(self.context, {})
     assert subject.execution_env is None
     assert subject.memory_limit_mb is None
コード例 #7
0
 def test_when_env_is_not_available_it_still_returns_at_least_the_arn(
         self):
     subject = AWSLambda.look_up_metadata(self.context, {})
     assert subject.function_arn == "the_lambda_function_arn"
コード例 #8
0
 def test_it_finds_memory_limit(self):
     subject = AWSLambda.look_up_metadata(
         self.context, self.env)
     assert subject.memory_limit_mb == 2048
コード例 #9
0
 def test_it_finds_the_arn(self):
     subject = AWSLambda.look_up_metadata(
         self.context, self.env)
     assert subject.function_arn == "the_lambda_function_arn"