def before(self): codeguru_client_builder = CodeGuruClientBuilder( environment={"aws_session": boto3.session.Session()}) self.client_stubber = Stubber(codeguru_client_builder.codeguru_client) self.clear_lambda_specific_environment_variables_for_test_run() profile_encoder = MagicMock(name="profile_encoder", spec=ProfileEncoder) profile_encoder.encode.side_effect = lambda **args: args[ "output_stream"].write(b"test-profile-encoder-output") self.environment = { "profiling_group_name": profiling_group_name, "profile_encoder": profile_encoder, "codeguru_profiler_builder": codeguru_client_builder, "agent_metadata": AgentMetadata(fleet_info=DefaultFleetInfo()), "reporting_interval": timedelta(minutes=13), "sampling_interval": timedelta(seconds=13), "minimum_time_reporting": timedelta(minutes=13), "max_stack_depth": 1300 } default_config = AgentConfiguration( should_profile=True, sampling_interval=self.environment["sampling_interval"], reporting_interval=self.environment["reporting_interval"], minimum_time_reporting=self.environment["minimum_time_reporting"]) self.environment["agent_config_merger"] = AgentConfigurationMerger( default_config) self.subject = SdkReporter(environment=self.environment) self.subject.setup()
def before(self): self.subject = CodeGuruClientBuilder( environment={ 'aws_session': boto3.session.Session( region_name='eu-west-2'), 'region_name': 'eu-west-2' })
def before(self): self.mock_session = MagicMock(name="profiler", spec=boto3.session.Session) self.subject = CodeGuruClientBuilder( environment={'aws_session': self.mock_session}) # it is necessary to call codeguru_client; otherwise no session will be created. self.subject.codeguru_client
def before(self): now_millis = int(time.time()) * 1000 five_minutes_ago_millis = now_millis - (5 * 60 * 1000) sample = Sample( stacks=[[Frame(MY_PROFILING_GROUP_NAME_FOR_INTEG_TESTS)]], attempted_sample_threads_count=1, seen_threads_count=1) self.profile = Profile(MY_PROFILING_GROUP_NAME_FOR_INTEG_TESTS, 1.0, 1.0, five_minutes_ago_millis) # FIXME: Remove adding the end time manually below after feature fully support self.profile.end = now_millis self.profile.add(sample) self.environment = { "should_profile": True, "profiling_group_name": MY_PROFILING_GROUP_NAME_FOR_INTEG_TESTS, "aws_session": boto3.session.Session(), "reporting_interval": timedelta(minutes=13), "sampling_interval": timedelta(seconds=1), "minimum_time_reporting": timedelta(minutes=6), "max_stack_depth": 2345, "cpu_limit_percentage": 29, "agent_metadata": AgentMetadata(fleet_info=DefaultFleetInfo()) } self.environment["codeguru_profiler_builder"] = CodeGuruClientBuilder( self.environment) self.agent_config = AgentConfiguration( should_profile=True, sampling_interval=self.environment["sampling_interval"], reporting_interval=self.environment["reporting_interval"], minimum_time_reporting=self.environment["minimum_time_reporting"], max_stack_depth=self.environment["max_stack_depth"], cpu_limit_percentage=self.environment["cpu_limit_percentage"])
def around(self): previous_region_value = os.environ.get('AWS_DEFAULT_REGION') os.environ['AWS_DEFAULT_REGION'] = 'ap-southeast-2' self.subject = CodeGuruClientBuilder( environment={'aws_session': boto3.session.Session()}) yield if previous_region_value is not None: os.environ['AWS_DEFAULT_REGION'] = previous_region_value else: del os.environ['AWS_DEFAULT_REGION']
def _select_collector(environment): reporting_mode = environment.get('reporting_mode') if reporting_mode == "codeguru_service": environment["codeguru_profiler_builder"] = CodeGuruClientBuilder(environment) return LocalAggregator( reporter=SdkReporter(environment=environment), environment=environment) elif reporting_mode == "file": return LocalAggregator( reporter=FileReporter(environment=environment), environment=environment) else: raise ValueError("Invalid reporting mode for CodeGuru Profiler detected: {}".format(reporting_mode))
def before(self): self.subject = CodeGuruClientBuilder(environment={ 'aws_session': boto3.session.Session(region_name='ap-southeast-2') })
def before(self): default_session = boto3.session.Session() self.subject = CodeGuruClientBuilder( environment={'aws_session': default_session})
def before(self): self.subject = CodeGuruClientBuilder( environment={ 'aws_session': boto3.session.Session(), 'endpoint_url': 'https://some-endpoint.amazonaws.com' })