def StartTabaAgentServer(server_endpoints, flush_period_seconds, port, queues_per_url, double_agent_conf=None): """Initialize the Taba Agent, and setup the HTTP request handlers for the Client and monitoring interface. Args: server_endpoints - List of Taba Server end-point dictionaries, containing 'host' and 'port' fields for each end-point. flush_period_seconds - The period, in seconds, at which the Taba Agent should flush its buffer. port - Port the Taba Agent to listen to for receiving Events. queues_per_url - Number of parallel queues to use per URL end-point. double_agent_conf - If not None, represents an alternative Taba Agent configuration which will be spawned and forwarded a copy of all incoming requests. """ # Compile the Cython components. from taba.util.misc_util import BootstrapCython BootstrapCython(port) # Grab the bottle Application object for possibly wrapping in middleware. app = bottle.app() # If running in 'Double Agent' mode, inject the forwarding middleware and # spin up the sub-process. subproc = None if double_agent_conf: from taba.util.middleware import DoubleAgent app = DoubleAgent(app, double_agent_conf["AGENT_PORT"]) from multiprocessing import Process subproc = Process( target=StartTabaAgentServer, args=( double_agent_conf["SERVER_ENDPOINTS"], double_agent_conf["AGENT_FLUSH_SECONDS"], double_agent_conf["AGENT_PORT"], double_agent_conf.get("AGENT_QUEUES_PER_SERVER", 1), None, ), ) subproc.start() logging.basicConfig(level=logging.WARNING) # Initialize the Taba Agent _GLOBAL_TABA_AGENT.Initialize(server_endpoints, flush_period_seconds, queues_per_url=queues_per_url) try: bottle.run(app=app, host="0.0.0.0", port=port, server="gevent") finally: if subproc: subproc.terminate() subproc.join()
def setUp(self): """Override.""" super(AgentHandlersTestCase, self).setUp() self.app = webtest.TestApp(bottle.app())
def _StartTabaServer( port, db_settings, roles, agent_url=None, priority=False, debug=False, name_blacklist=None, client_blacklist=None, additional_handlers=None): """Initialize the Taba Server worker process. Args: port - Port to listen on for requests. db_settings - Dict of DB settings. roles - Comma delimited list of ServerRoles. agent_url - Agent URL to use for posting internally generated Events. priority - If True, bump up this process' priority. debug - Whether to launch in debug mode. name_blacklist - List of regular expressions that will be used to ignore any matching Names. If None, no filtering will be applied. client_blacklist - List of regular expressions that will be used to ignore any matching Client Names. If None, no filtering will be applied. """ # Monkey patch gevent before doing anything. from gevent import monkey monkey.patch_all() # If this process is flagged as priority, adjust the nice value. if priority: os.nice(-2) # Attempt to turn heapy remote monitoring on. try: # noinspection PyUnresolvedReferences import guppy.heapy.RM except ImportError: pass # Attach a stack-trace dump to the SIGQUIT (kill -3) signal. signal.signal(signal.SIGQUIT, _PrintTrace) # Compile the Cython components. from taba.util.misc_util import BootstrapCython BootstrapCython(port) import logging logging.basicConfig(level=logging.WARNING) server_name = 'taba_server.%s.%d' % (socket.gethostname(), port) # Initialize the server. from taba.server.model import model_provider model_provider.Initialize( server_name, db_settings, roles, debug, name_blacklist, client_blacklist, additional_handlers) # Setup the local Taba Client. if agent_url: from taba import client from taba.client.gevent_engine import GeventEngine client_name = 'taba_server.%s' % socket.gethostname() client.Initialize(client_name, agent_url, flush_period=10, engine_class=GeventEngine) # Start the server. from taba.third_party import bottle from taba.server import request_handlers app = bottle.app() bottle.run(app=app, host='0.0.0.0', port=port, server='gevent')