Ejemplo n.º 1
0
    def test_merge_settings(self):
        """
        """
        server_conf = {
            "applicationId": "1233",
            "enabled": True,
            "appSessionKey": "rwreqrq",
            "dataSentInterval": 60,
            "apdex_t": 25,
            "config": {
                "nbs.agent_enabled": True,
                "nbs.auto_action_naming": True,
                "nbs.capture_params": True,
                "nbs.error_collector.enabled": True,
                "nbs.error_collector.record_db_errors": True,
                "nbs.action_tracer.enabled": True,
                "nbs.action_tracer.action_threshold": 0,
                "nbs.action_tracer.record_sql": "obfuscated",
                "nbs.action_tracer.slow_sql": True,
                "nbs.action_tracer.slow_sql_threshold": 500,
                "nbs.ignored_params": "",
                "nbs.error_collector.ignored_status_codes": "",
                "nbs.urls_captured": "/cargo/detail/6/\\n/cargo/detail/7/",
            }
        }
        snapshot = merge_settings(server_conf)

        self.assertTrue(hasattr(snapshot, "applicationId"),
                        "merge attribute failed.")
        self.assertEqual(snapshot.applicationId, "1233",
                         "merge attribute failed.")

        self.assertTrue(hasattr(snapshot, "enabled"),
                        "merge attribute failed.")
        self.assertEqual(snapshot.enabled, True, "merge attribute failed.")

        self.assertTrue(hasattr(snapshot, "appSessionKey"),
                        "merge attribute failed.")
        self.assertEqual(snapshot.appSessionKey, "rwreqrq",
                         "merge attribute failed.")

        self.assertTrue(hasattr(snapshot, "apdex_t"),
                        "merge attribute failed.")
        self.assertEqual(snapshot.apdex_t, 25, "merge attribute failed.")

        self.assertTrue(hasattr(snapshot, "error_collector"),
                        "merge attribute failed.")
        self.assertEqual(snapshot.error_collector.enabled, True,
                         "merge attribute failed.")

        self.assertTrue(hasattr(snapshot, "capture_params"),
                        "merge attribute failed.")
        self.assertEqual(snapshot.capture_params, True,
                         "merge attribute failed.")
Ejemplo n.º 2
0
def create_connection(license_key, app_name, linked_applications, machine_env,
                      settings):
    """
    :return:
    """
    start_time = time.time()

    if not license_key:
        license_key = settings.license_key

    if not license_key:
        console.error(
            "license key should be provided in tingyun.ini config file, agent may can not started."
        )

    try:
        console.info(
            "init app with license: %s, app: %s, link app: %s, env: %s, settings: %s, upload settings: %s",
            license_key, app_name, linked_applications, machine_env, settings,
            get_upload_settings())

        # when private the agent. we should get redirect with port set in settings
        url = connect_url("getRedirectHost", with_port=True)
        param = {"licenseKey": license_key, "version": settings.data_version}
        redirect_host = transmitter(None, url, "getRedirectHost", {}, param)
        local_conf = {
            "host": socket.gethostname(),
            "appName": [app_name] + linked_applications,
            "language": "Python",
            "agentVersion": settings.agent_version,
            "config": get_upload_settings(),
            "env": machine_env
        }

        # At second step. we need not the port with url. because the returned redirect url take it or has default 80.
        url = connect_url("initAgentApp", redirect_host, with_port=False)
        server_conf = transmitter(None, url, "initAgentApp", local_conf,
                                  {"licenseKey": license_key})
        app_config = merge_settings(server_conf)
    except Exception as err:
        console.error("errors when connect to server %s", err)
        raise RetryDataForRequest(
            "Errors occurred, when create session with server. %s" % err)
    else:
        console.info(
            "Successful register application to agent server with name: %s, use time: %ss",
            app_name,
            time.time() - start_time)

        url = connect_url("upload", redirect_host)
        return Engine(url, app_config, license_key, redirect_host)
Ejemplo n.º 3
0
    def test_quantile_4_specail_str(self):

        print "begin specail str"
        quantile_ = [[], '\\']

        self.server_side_config['config']['nbs.quantile'] = quantile_
        result = merge_settings(self.server_side_config)
        try:
            quantile_raw = result['quantile']
        except Exception as err:
            print "special str`s server_config: %s " % result
            quantile_raw = "fail"

        self.assertEqual(quantile_raw, [])
Ejemplo n.º 4
0
    def test_quantile_3_float(self):

        print "begin float"
        quantile_ = [12.4, 98.9]

        self.server_side_config['config']['nbs.quantile'] = quantile_
        result = merge_settings(self.server_side_config)
        try:
            quantile_raw = result['quantile']
        except Exception as err:
            print "float`s server_config: %s " % result
            quantile_raw = "fail"

        self.assertEqual(quantile_raw, [])
Ejemplo n.º 5
0
    def test_quantile_2_str(self):

        print "begin str"
        quantile_ = ['abc', 'DE', 'FFFF']

        self.server_side_config['config']['nbs.quantile'] = quantile_
        result = merge_settings(self.server_side_config)
        try:
            quantile_raw = result['quantile']
        except Exception as err:
            print "str`s server_config: %s " % result
            quantile_raw = "fail"

        self.assertEqual(quantile_raw, [])
Ejemplo n.º 6
0
    def test_quantile_1_blank(self):

        print "begin blank"
        quantile_ = []

        self.server_side_config['config']['nbs.quantile'] = quantile_
        result = merge_settings(server_side_config=self.server_side_config)
        try:
            quantile_raw = result['quantile']
        except Exception as err:
            print "blank`s server_config: %s " % result
            quantile_raw = "fail"

        self.assertEqual(quantile_raw, [])
Ejemplo n.º 7
0
    def test_quantile_7_out_range(self):

        print "begin out range"
        quantile_ = [100, 100000000]

        self.server_side_config['config']['nbs.quantile'] = quantile_
        result = merge_settings(self.server_side_config)
        try:
            quantile_raw = result['quantile']
        except Exception as err:
            print "out range`s server_config: %s " % result
            quantile_raw = "fail"

        self.assertEqual(quantile_raw, [])
Ejemplo n.º 8
0
    def test_quantile_6_negative(self):

        print "begin negative"
        quantile_ = [-1]

        self.server_side_config['config']['nbs.quantile'] = quantile_
        result = merge_settings(self.server_side_config)
        try:
            quantile_raw = result['quantile']
        except Exception as err:
            print "negative`s server_config: %s " % result
            quantile_raw = "fail"

        self.assertEqual(quantile_raw, [])