Пример #1
0
    def __init__(self, queue_, max_batch=MAX_BATCH, config=None, **kwargs):
        super(StackifyListener, self).__init__(queue_)

        self.max_batch = max_batch
        self.messages = []
        self.transport = configure_transport(config, **kwargs)
        self.timer = RepeatedTimer(API_REQUEST_INTERVAL_IN_SEC,
                                   self.send_group)

        self._started = False
    def test_default_transport(self):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
        }

        transport = configure_transport(**config)

        assert isinstance(transport, DefaultTransport)
    def test_agent_socket_transport(self):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
            'socket_url': 'test_socketurl',
            'transport': 'agent_socket',
        }

        transport = configure_transport(**config)

        assert isinstance(transport, AgentSocketTransport)
    def test_default_create_message(self):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
        }

        transport = configure_transport(**config)
        message = transport.create_message(
            logging.makeLogRecord({'mgs': 'message'}))

        assert isinstance(message, LogMsg)
    def test_agent_http_transport(self):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
            'http_endpoint': 'test.url',
            'transport': 'agent_http',
        }

        transport = configure_transport(**config)

        assert isinstance(transport, AgentHTTPTransport)
    def test_default_send_url(self, mock_send):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
        }

        transport = configure_transport(**config)
        message = transport.create_message(
            logging.makeLogRecord({'mgs': 'message'}))
        group_message = transport.create_group_message([message])
        transport.send(group_message)

        assert mock_send.called
        assert mock_send.call_args_list[0][0][0] == '/Log/Save'
    def test_agent_http_create_message(self):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
            'http_endpoint': 'test.url',
            'transport': 'agent_http',
        }

        transport = configure_transport(**config)
        message = transport.create_message(
            logging.makeLogRecord({
                'mgs': 'message',
                'funcName': 'foo'
            }))

        assert isinstance(message, stackify_agent_pb2.LogGroup.Log)
    def test_agent_socket_create_group_message(self):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
            'socket_url': 'test_socketurl',
            'transport': 'agent_socket',
        }

        transport = configure_transport(**config)
        message = transport.create_message(
            logging.makeLogRecord({
                'mgs': 'message',
                'funcName': 'foo'
            }))
        group_message = transport.create_group_message([message])

        assert isinstance(group_message, stackify_agent_pb2.LogGroup)
    def test_agent_socket_send_url_default(self, mock_send):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
            'transport': 'agent_socket',
        }

        transport = configure_transport(**config)
        message = transport.create_message(
            logging.makeLogRecord({
                'mgs': 'message',
                'funcName': 'foo'
            }))
        group_message = transport.create_group_message([message])
        transport.send(group_message)

        assert mock_send.called
        assert mock_send.call_args_list[0][0][
            0] == 'http+unix://%2Fusr%2Flocal%2Fstackify%2Fstackify.sock/log'
    def test_agent_http_send_url_default(self, mock_send):
        config = {
            'application': 'test_appname',
            'environment': 'test_environment',
            'api_key': 'test_apikey',
            'api_url': 'test_apiurl',
            'transport': 'agent_http',
        }

        transport = configure_transport(**config)
        assert isinstance(transport, AgentHTTPTransport)
        message = transport.create_message(
            logging.makeLogRecord({
                'mgs': 'message',
                'funcName': 'foo'
            }))
        group_message = transport.create_group_message([message])
        transport.send(group_message)

        assert mock_send.called
        assert mock_send.call_args_list[0][0][
            0] == DEFAULT_HTTP_ENDPOINT + AGENT_LOG_URL