def test_it_increments_error_count_when_postAgentProfileErrors(self):
            subject = ErrorsMetadata()
            subject.record_sdk_error("postAgentProfileErrors")

            assert subject.errors_count == 1
            assert subject.sdk_client_errors == 1
            assert subject.configure_agent_errors == 0
            assert subject.configure_agent_rnfe_auto_create_enabled_errors == 0
            assert subject.create_profiling_group_errors == 0
            assert subject.post_agent_profile_errors == 1
            assert subject.post_agent_profile_rnfe_auto_create_enabled_errors == 0
        def test_it_returns_json_with_error_counts(self):
            subject = ErrorsMetadata()
            subject.record_sdk_error("configureAgentErrors")

            assert subject.serialize_to_json() == {
                "errorsCount": 1,
                "sdkClientErrors": 1,
                "configureAgentErrors": 1,
                "configureAgentRnfeAutoCreateEnabledErrors": 0,
                "createProfilingGroupErrors": 0,
                "postAgentProfileErrors": 0,
                "postAgentProfileRnfeAutoCreateEnabledErrors": 0
            }
    def test_it_returns_json_with_error_counts(self):
        errors_metadata = ErrorsMetadata()
        errors_metadata.record_sdk_error("createProfilingGroupErrors")
        subject = AgentDebugInfo(errors_metadata)

        serialized_json = subject.serialize_to_json()
        assert serialized_json["errorsCount"] == {
            "configureAgentErrors": 0,
            "configureAgentRnfeAutoCreateEnabledErrors": 0,
            "createProfilingGroupErrors": 1,
            "errorsCount": 1,
            "postAgentProfileErrors": 0,
            "postAgentProfileRnfeAutoCreateEnabledErrors": 0,
            "sdkClientErrors": 1
        }
Exemplo n.º 4
0
    def before(self):
        self.test_start_time = 1603884061556
        self.mock_clock = Mock()
        self.mock_clock.return_value = self.test_start_time / 1000
        self.subject = Profile(profiling_group_name="foo",
                               sampling_interval_seconds=1.0,
                               host_weight=2,
                               start=self.test_start_time,
                               agent_debug_info=AgentDebugInfo(
                                   ErrorsMetadata()),
                               clock=self.mock_clock)

        def turn_clock(seconds):
            self.mock_clock.return_value += seconds

        self.turn_clock = turn_clock
Exemplo n.º 5
0
    def _setup_final_environment(self, environment, environment_override):
        environment.update(environment_override)

        # set additional parameters if needed (costly default init or depend on other parameters)
        if environment.get('initial_sampling_interval') is None:
            environment['initial_sampling_interval'] = datetime.timedelta(
                seconds=SystemRandom().uniform(
                    0,
                    AgentConfiguration.get().sampling_interval.total_seconds()
                ))
        environment['excluded_threads'] = \
            frozenset({environment['profiler_thread_name']}.union(environment['excluded_threads']))
        # TODO delay metadata lookup until we need it
        environment['agent_metadata'] = environment.get(
            'agent_metadata') or AgentMetadata()
        environment['errors_metadata'] = environment.get(
            'errors_metadata') or ErrorsMetadata()
        environment['collector'] = environment.get(
            'collector') or self._select_collector(environment)
        environment["profiler_disabler"] = environment.get(
            'profiler_disabler') or ProfilerDisabler(environment)
        return UnmodifiableDict(environment)
Exemplo n.º 6
0
    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)
        errors_metadata = ErrorsMetadata()

        self.profile = Profile(MY_PROFILING_GROUP_NAME_FOR_INTEG_TESTS, 1.0,
                               1.0, five_minutes_ago_millis,
                               AgentDebugInfo(errors_metadata))
        # 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()),
            "errors_metadata": errors_metadata
        }
        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 test_it_resets_error_count(self):
            subject = ErrorsMetadata()
            subject.record_sdk_error("createProfilingGroupErrors")

            assert subject.errors_count == 1
            assert subject.sdk_client_errors == 1
            assert subject.configure_agent_errors == 0
            assert subject.configure_agent_rnfe_auto_create_enabled_errors == 0
            assert subject.create_profiling_group_errors == 1
            assert subject.post_agent_profile_errors == 0
            assert subject.post_agent_profile_rnfe_auto_create_enabled_errors == 0

            subject.reset()

            assert subject.errors_count == 0
            assert subject.sdk_client_errors == 0
            assert subject.configure_agent_errors == 0
            assert subject.configure_agent_rnfe_auto_create_enabled_errors == 0
            assert subject.create_profiling_group_errors == 0
            assert subject.post_agent_profile_errors == 0
            assert subject.post_agent_profile_rnfe_auto_create_enabled_errors == 0
                     Frame("different_top")],
                    [Frame("bottom"), Frame("middle")]],
            attempted_sample_threads_count=10,
            seen_threads_count=15))
    profile.end = end_time
    profile.set_overhead_ms(timedelta(milliseconds=256))
    if platform.system() == "Windows":
        # In Windows, as time.process stays constant if no cpu time was used (https://bugs.python.org/issue37859), we
        # would need to manually override the cpu_time_seconds to ensure the test runs as expected
        profile.cpu_time_seconds = 0.123
    return profile


agent_metadata = AgentMetadata(fleet_info=AWSEC2Instance(
    host_name="testHostName", host_type="testHostType"))
errors_metadata = ErrorsMetadata()

environment = {
    "timer": Timer(),
    "agent_metadata": agent_metadata,
    "errors_metadata": errors_metadata
}


class TestSdkProfileEncoder:
    def before(self):
        self.profile = example_profile()
        self.output_stream = io.BytesIO()
        self.subject = \
            ProfileEncoder(gzip=False, environment=environment)
        self.decoded_json_result = self.decoded_json_result.__get__(self)