Example #1
0
def parse_config(args, default_config_files=None):
    set_defaults()
    log.register_options(CONF)
    policy_opts.set_defaults(CONF)
    osprofiler_opts.set_defaults(CONF)
    db_options.set_defaults(CONF)

    for group, options in opts.list_opts():
        CONF.register_opts(list(options),
                           group=None if group == 'DEFAULT' else group)

    CONF(args[1:],
         project='vitrage',
         validate_default_values=True,
         default_config_files=default_config_files)

    if CONF.profiler.enabled:
        osprofiler_initializer.init_from_conf(conf=CONF,
                                              context=None,
                                              project='vitrage',
                                              service='api',
                                              host=CONF.api.host)

    for datasource in CONF.datasources.types:
        opts.register_opts(datasource, CONF.datasources.path)

    keystone_client.register_keystoneauth_opts()
    log.setup(CONF, 'vitrage')
    CONF.log_opt_values(LOG, log.DEBUG)
    messaging.setup()
Example #2
0
    def test_list_traces(self):
        # initialize profiler notifier (the same way as in services)
        initializer.init_from_conf(
            CONF, {}, self.PROJECT, self.SERVICE, "host")
        profiler.init("SECRET_KEY")

        # grab base_id
        base_id = profiler.get().get_base_id()

        # execute profiled code
        foo = Foo()
        foo.bar(1)

        # instantiate report engine (the same way as in osprofiler CLI)
        engine = base.get_driver(CONF.profiler.connection_string,
                                 project=self.PROJECT,
                                 service=self.SERVICE,
                                 host="host",
                                 conf=CONF)

        # generate the report
        traces = engine.list_traces()
        LOG.debug("Collected traces: %s", traces)

        # ensure trace with base_id is in the list of traces
        self.assertIn(base_id, [t["base_id"] for t in traces])
Example #3
0
    def test_list_traces(self):
        # initialize profiler notifier (the same way as in services)
        initializer.init_from_conf(CONF, {}, self.PROJECT, self.SERVICE,
                                   "host")
        profiler.init("SECRET_KEY")

        # grab base_id
        base_id = profiler.get().get_base_id()

        # execute profiled code
        foo = Foo()
        foo.bar(1)

        # instantiate report engine (the same way as in osprofiler CLI)
        engine = base.get_driver(CONF.profiler.connection_string,
                                 project=self.PROJECT,
                                 service=self.SERVICE,
                                 host="host",
                                 conf=CONF)

        # generate the report
        traces = engine.list_traces()
        LOG.debug("Collected traces: %s", traces)

        # ensure trace with base_id is in the list of traces
        self.assertIn(base_id, [t["base_id"] for t in traces])
Example #4
0
def prepare_service(args=None, conf=None, config_files=None):
    set_defaults()
    if conf is None:
        conf = cfg.ConfigOpts()
    log.register_options(conf)
    policy_opts.set_defaults(conf)
    osprofiler_opts.set_defaults(conf)
    db_options.set_defaults(conf)

    for group, options in opts.list_opts():
        conf.register_opts(list(options),
                           group=None if group == 'DEFAULT' else group)

    conf(args,
         project='vitrage',
         validate_default_values=True,
         default_config_files=config_files)

    if conf.profiler.enabled:
        osprofiler_initializer.init_from_conf(conf=conf,
                                              context=None,
                                              project="vitrage",
                                              service="api",
                                              host=conf.api.host)

    for datasource in conf.datasources.types:
        register_opts(conf, datasource, conf.datasources.path)

    keystone_client.register_keystoneauth_opts(conf)

    log.setup(conf, 'vitrage')
    conf.log_opt_values(LOG, log.DEBUG)
    messaging.setup()

    return conf
Example #5
0
    def test_get_report(self):
        initializer.init_from_conf(CONF, None, self.PROJECT, self.SERVICE,
                                   "host")
        profiler.init("SECRET_KEY", project=self.PROJECT, service=self.SERVICE)

        foo = DriverTestCase.Foo()
        foo.bar(1)

        engine = base.get_driver(CONF.profiler.connection_string,
                                 project=self.PROJECT,
                                 service=self.SERVICE,
                                 host="host",
                                 conf=CONF)
        base_id = profiler.get().get_base_id()
        res = engine.get_report(base_id)

        self.assertEqual("total", res["info"]["name"])
        self.assertEqual(2, res["stats"]["rpc"]["count"])
        self.assertEqual(1, len(res["children"]))

        cbar = res["children"][0]
        self._assert_child_dict(
            cbar, base_id, base_id, "rpc",
            "osprofiler.tests.functional.test_driver.Foo.bar")

        self.assertEqual(1, len(cbar["children"]))
        cbaz = cbar["children"][0]
        self._assert_child_dict(
            cbaz, base_id, cbar["trace_id"], "rpc",
            "osprofiler.tests.functional.test_driver.Foo.baz")
Example #6
0
    def test_initializer(self, web_enable_mock, notifier_create_mock,
                         notifier_set_mock):
        conf = mock.Mock()
        conf.profiler.connection_string = "driver://"
        conf.profiler.hmac_keys = "hmac_keys"
        context = {}
        project = "my-project"
        service = "my-service"
        host = "my-host"

        notifier_mock = mock.Mock()
        notifier_create_mock.return_value = notifier_mock

        initializer.init_from_conf(conf, context, project, service, host)

        notifier_create_mock.assert_called_once_with(
            "driver://", context=context, project=project, service=service,
            host=host, conf=conf)
        notifier_set_mock.assert_called_once_with(notifier_mock)
        web_enable_mock.assert_called_once_with("hmac_keys")
Example #7
0
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glare')
        notification.set_defaults()

        if CONF.profiler.enabled:
            initializer.init_from_conf(
                conf=CONF,
                context={},
                project="glare",
                service="api",
                host=CONF.bind_host
            )

        server = wsgi.Server(initialize_glance_store=True)
        server.start(config.load_paste_app('glare-api'), default_port=9494)
        server.wait()
    except KNOWN_EXCEPTIONS as e:
        fail(e)
Example #8
0
    def test_get_report(self):
        # initialize profiler notifier (the same way as in services)
        initializer.init_from_conf(
            CONF, {}, self.PROJECT, self.SERVICE, "host")
        profiler.init("SECRET_KEY")

        # grab base_id
        base_id = profiler.get().get_base_id()

        # execute profiled code
        foo = Foo()
        foo.bar(1)

        # instantiate report engine (the same way as in osprofiler CLI)
        engine = base.get_driver(CONF.profiler.connection_string,
                                 project=self.PROJECT,
                                 service=self.SERVICE,
                                 host="host",
                                 conf=CONF)

        # generate the report
        report = engine.get_report(base_id)
        LOG.debug("OSProfiler report: %s", report)

        # verify the report
        self.assertEqual("total", report["info"]["name"])
        self.assertEqual(2, report["stats"]["rpc"]["count"])
        self.assertEqual(1, len(report["children"]))

        cbar = report["children"][0]
        self._assert_child_dict(
            cbar, base_id, base_id, "rpc",
            "osprofiler.tests.functional.test_driver.Foo.bar")

        self.assertEqual(1, len(cbar["children"]))
        cbaz = cbar["children"][0]
        self._assert_child_dict(
            cbaz, base_id, cbar["trace_id"], "rpc",
            "osprofiler.tests.functional.test_driver.Foo.baz")
Example #9
0
    def test_get_report(self):
        # initialize profiler notifier (the same way as in services)
        initializer.init_from_conf(CONF, {}, self.PROJECT, self.SERVICE,
                                   "host")
        profiler.init("SECRET_KEY")

        # grab base_id
        base_id = profiler.get().get_base_id()

        # execute profiled code
        foo = Foo()
        foo.bar(1)

        # instantiate report engine (the same way as in osprofiler CLI)
        engine = base.get_driver(CONF.profiler.connection_string,
                                 project=self.PROJECT,
                                 service=self.SERVICE,
                                 host="host",
                                 conf=CONF)

        # generate the report
        report = engine.get_report(base_id)
        LOG.debug("OSProfiler report: %s", report)

        # verify the report
        self.assertEqual("total", report["info"]["name"])
        self.assertEqual(2, report["stats"]["rpc"]["count"])
        self.assertEqual(1, len(report["children"]))

        cbar = report["children"][0]
        self._assert_child_dict(
            cbar, base_id, base_id, "rpc",
            "osprofiler.tests.functional.test_driver.Foo.bar")

        self.assertEqual(1, len(cbar["children"]))
        cbaz = cbar["children"][0]
        self._assert_child_dict(
            cbaz, base_id, cbar["trace_id"], "rpc",
            "osprofiler.tests.functional.test_driver.Foo.baz")
Example #10
0
def setup(name, host='0.0.0.0'):
    """Setup OSprofiler notifier and enable profiling.

    :param name: name of the service that will be profiled
    :param host: hostname or host IP address that the service will be
                 running on. By default host will be set to 0.0.0.0, but
                 specifying host name / address usage is highly recommended.
    :raises TypeError: in case of invalid connection string for
                       a notifier backend, which is set in
                       osprofiler.initializer.init_from_conf.
    """
    if not CONF.profiler.enabled:
        return

    admin_context = context.get_admin_context()
    initializer.init_from_conf(conf=CONF,
                               context=admin_context.to_dict(),
                               project="ironic",
                               service=name,
                               host=host)
    LOG.info("OSProfiler is enabled. Trace is generated using "
             "[profiler]/hmac_keys specified in ironic.conf. "
             "To disable, set [profiler]/enabled=false")