# Copyright Hybrid Logic Ltd. See LICENSE file for details. """ This module defines the Eliot log events emitted by the API implementation. """ __all__ = [ "REQUEST_PATH", "REQUEST", ] from eliot import Field, ActionType LOG_SYSTEM = u"api" REQUEST_PATH = Field.forTypes( u"request_path", [unicode], u"The absolute path of the resource to which the request was issued.") REQUEST = ActionType(LOG_SYSTEM, [REQUEST_PATH], [], u"A request was received on the public HTTP interface.")
from eliot import Field, ActionType __all__ = [ "JSON_REQUEST", "REQUEST", ] LOG_SYSTEM = u"api" METHOD = Field(u"method", lambda method: method, u"The HTTP method of the request.") REQUEST_PATH = Field( u"request_path", lambda path: path, u"The absolute path of the resource to which the request was issued.") JSON = Field.forTypes( u"json", [unicode, bytes, dict, list, None, bool, float], u"The JSON request body.") RESPONSE_CODE = Field.forTypes( u"code", [int], u"The response code for the request.") # It would be nice if RESPONSE_CODE was in REQUEST instead of # JSON_REQUEST; see FLOC-1586. REQUEST = ActionType( LOG_SYSTEM + u":request", [REQUEST_PATH, METHOD], [], u"A request was received on the public HTTP interface.") # NB we deliberately do not log the entire JSON response body because the
:param arguments: A ``list`` of ``bytes``, command-line arguments to ``zfs``. :return: A :class:`Deferred` firing with the bytes of the result (on exit code 0), or errbacking with :class:`CommandFailed` or :class:`BadArguments` depending on the exit code (1 or 2). """ endpoint = ProcessEndpoint(reactor, b"zfs", [b"zfs"] + arguments, os.environ) d = connectProtocol(endpoint, _AccumulatingProtocol()) d.addCallback(lambda protocol: protocol._result) return d _ZFS_COMMAND = Field.forTypes( "zfs_command", [bytes], u"The command which was run.") _OUTPUT = Field.forTypes( "output", [bytes], u"The output generated by the command.") _STATUS = Field.forTypes( "status", [int], u"The exit status of the command") ZFS_ERROR = MessageType( "filesystem:zfs:error", [_ZFS_COMMAND, _OUTPUT, _STATUS], u"The zfs command signaled an error.") def _sync_command_error_squashed(arguments, logger): """ Synchronously run a command-line tool with the given arguments.
NOT_FOUND, PRECONDITION_FAILED, ) from twisted.internet.utils import getProcessOutput from twisted.internet.task import deferLater from treq import json_content, content from ..ca import treq_with_authentication from ..control import Leases as LeasesModel, LeaseError, DockerImage from ..common import retry_failure from .. import __version__ _LOG_HTTP_REQUEST = ActionType("flocker:apiclient:http_request", [ Field.forTypes("url", [bytes, unicode], "Request URL."), Field.forTypes("method", [bytes, unicode], "Request method."), Field("request_body", lambda o: o, "Request JSON body.") ], [ Field.forTypes("response_code", [int], "Response code."), Field("response_body", lambda o: o, "JSON response body.") ], "A HTTP request.") _LOG_CONDITIONAL_CREATE = ActionType(u"flocker:apiclient:conditional_create", [], [], u"Conditionally create a dataset.") NoneType = type(None) class ServerResponseMissingElementError(Exception):
from zope.interface import Attribute, Interface, implementer, provider from zope.interface.exceptions import DoesNotImplement from eliot import Field, ActionType, Logger from twisted.python.util import FancyStrMixin, FancyEqMixin from twisted.python.components import proxyForInterface from twisted.internet.defer import succeed def _system(suffix): return u":".join((u"fsm", suffix)) FSM_IDENTIFIER = Field.forTypes( u"fsm_identifier", [unicode], u"An unique identifier for the FSM to which the event pertains.") FSM_STATE = Field.forTypes( u"fsm_state", [unicode], u"The state of the FSM prior to the transition.") FSM_RICH_INPUT = Field.forTypes( u"fsm_rich_input", [unicode], u"The string representation of the rich input delivered to the FSM.") FSM_INPUT = Field.forTypes( u"fsm_input", [unicode], u"The string representation of the input symbol delivered to the FSM.") FSM_NEXT_STATE = Field.forTypes( u"fsm_next_state", [unicode], u"The string representation of the state of the FSM after the transition.") FSM_OUTPUT = Field.forTypes( u"fsm_output", [list], # of unicode u"A list of the string representations of the outputs produced by the "
from twisted.internet.defer import succeed, fail from twisted.python.filepath import FilePath from twisted.web.http import CREATED, OK, CONFLICT, NOT_FOUND from twisted.internet.utils import getProcessOutput from treq import json_content, content from ..ca import treq_with_authentication from ..control import Leases as LeasesModel, LeaseError from ..common import retry_failure from .. import __version__ _LOG_HTTP_REQUEST = ActionType( "flocker:apiclient:http_request", [Field.forTypes("url", [bytes, unicode], "Request URL."), Field.forTypes("method", [bytes, unicode], "Request method."), Field("request_body", lambda o: o, "Request JSON body.")], [Field.forTypes("response_code", [int], "Response code."), Field("response_body", lambda o: o, "JSON response body.")], "A HTTP request.") NoneType = type(None) class Dataset(PClass): """ A dataset in the configuration. :attr UUID primary: The node where the dataset should manifest.
# Copyright ClusterHQ Inc. See LICENSE file for details. """ This module defines the Eliot log events emitted by the API implementation. """ from eliot import Field, ActionType __all__ = [ "REQUEST", ] LOG_SYSTEM = u"api" METHOD = Field(u"method", lambda method: method, u"The HTTP method of the request.") REQUEST_PATH = Field( u"request_path", lambda path: path, u"The absolute path of the resource to which the request was issued.") JSON = Field.forTypes(u"json", [unicode, bytes, dict, list, None, bool, float], u"The JSON request body.") RESPONSE_CODE = Field.forTypes(u"code", [int], u"The response code for the request.") # It would be nice if RESPONSE_CODE was in REQUEST; see FLOC-1586. REQUEST = ActionType(LOG_SYSTEM + u":request", [REQUEST_PATH, METHOD], [], u"A request was received on the public HTTP interface.")
The goal here is to mostly focus on performance of serialization, in a vaguely realistic manner. That is, mesages are logged in context of a message with a small number of fields. """ from __future__ import unicode_literals import time from eliot import Logger, MessageType, Field, ActionType def _ascii(s): return s.decode("ascii") F1 = Field.forTypes("integer", [int], "") F2 = Field("string", _ascii, "") F3 = Field("string2", _ascii, "") F4 = Field.forTypes("list", [list], "list of integers") M = MessageType("system:message", [F1, F2, F3, F4], "description") A = ActionType("action", [], [], [], "desc") log = Logger() N = 100000 def run(): start = time.time() with A(log): for i in xrange(N):
raise ValidationError( value, u"Field %s requires type to be IPv4Address (not %s)" % (u"target_ip", type(value))) def serialize_ipv4_address(address): return unicode(address) TARGET_IP = Field( key=u"target_ip", serializer=serialize_ipv4_address, extraValidator=validate_ipv4_address, description=u"The IP address which is the target of a proxy.") TARGET_PORT = Field.forTypes( u"target_port", [int], u"The port number which is the target of a proxy.") ARGV = Field.forTypes(u"argv", [list], u"The argument list of a child process being executed.") IPTABLES = ActionType( _system(u"iptables"), [ARGV], [], u"An iptables command which Flocker is executing against the system.") CREATE_PROXY_TO = ActionType(_system(u"create_proxy_to"), [TARGET_IP, TARGET_PORT], [], U"Flocker is creating a new proxy.") DELETE_PROXY = ActionType(_system(u"delete_proxy"), [TARGET_IP, TARGET_PORT], [], u"Flocker is deleting an existing proxy.")
__all__ = [ "JSON_REQUEST", "REQUEST", ] from eliot import Field, ActionType LOG_SYSTEM = u"api" METHOD = Field(u"method", lambda method: method, u"The HTTP method of the request.") REQUEST_PATH = Field( u"request_path", lambda path: path, u"The absolute path of the resource to which the request was issued.") JSON = Field.forTypes( u"json", [unicode, bytes, dict, list, None, bool, float], u"JSON, either request or response depending on context.") RESPONSE_CODE = Field.forTypes( u"code", [int], u"The response code for the request.") # It would be nice if RESPONSE_CODE was in REQUEST instead of # JSON_REQUEST; see FLOC-1586. REQUEST = ActionType( LOG_SYSTEM + u":request", [REQUEST_PATH, METHOD], [], u"A request was received on the public HTTP interface.") JSON_REQUEST = ActionType( LOG_SYSTEM + u":json_request",
from zope.interface import Attribute, Interface, implementer, provider from zope.interface.exceptions import DoesNotImplement from eliot import Field, ActionType, Logger from twisted.python.util import FancyStrMixin, FancyEqMixin from twisted.python.components import proxyForInterface from twisted.internet.defer import succeed def _system(suffix): return u":".join((u"fsm", suffix)) FSM_IDENTIFIER = Field.forTypes( u"fsm_identifier", [unicode], u"An unique identifier for the FSM to which the event pertains.") FSM_STATE = Field.forTypes(u"fsm_state", [unicode], u"The state of the FSM prior to the transition.") FSM_RICH_INPUT = Field.forTypes( u"fsm_rich_input", [unicode], u"The string representation of the rich input delivered to the FSM.") FSM_INPUT = Field.forTypes( u"fsm_input", [unicode], u"The string representation of the input symbol delivered to the FSM.") FSM_NEXT_STATE = Field.forTypes( u"fsm_next_state", [unicode], u"The string representation of the state of the FSM after the transition.") FSM_OUTPUT = Field.forTypes( u"fsm_output", [list], # of unicode
# Copyright Hybrid Logic Ltd. See LICENSE file for details. """ This module defines the Eliot log events emitted by the API implementation. """ __all__ = [ "REQUEST_PATH", "REQUEST", ] from eliot import Field, ActionType LOG_SYSTEM = u"api" REQUEST_PATH = Field.forTypes( u"request_path", [unicode], u"The absolute path of the resource to which the request was issued.") REQUEST = ActionType( LOG_SYSTEM, [REQUEST_PATH], [], u"A request was received on the public HTTP interface.")
from eliot import Field, ActionType __all__ = [ "JSON_REQUEST", "REQUEST", ] LOG_SYSTEM = u"api" METHOD = Field(u"method", lambda method: method, u"The HTTP method of the request.") REQUEST_PATH = Field( u"request_path", lambda path: path, u"The absolute path of the resource to which the request was issued.") JSON = Field.forTypes( u"json", [unicode, bytes, dict, list, None, bool, float], u"JSON, either request or response depending on context.") RESPONSE_CODE = Field.forTypes( u"code", [int], u"The response code for the request.") # It would be nice if RESPONSE_CODE was in REQUEST instead of # JSON_REQUEST; see FLOC-1586. REQUEST = ActionType( LOG_SYSTEM + u":request", [REQUEST_PATH, METHOD], [], u"A request was received on the public HTTP interface.") JSON_REQUEST = ActionType( LOG_SYSTEM + u":json_request",
u"target_ip", type(value))) def serialize_ipv4_address(address): return unicode(address) TARGET_IP = Field( key=u"target_ip", serializer=serialize_ipv4_address, extraValidator=validate_ipv4_address, description=u"The IP address which is the target of a proxy.") TARGET_PORT = Field.forTypes( u"target_port", [int], u"The port number which is the target of a proxy.") ARGV = Field.forTypes( u"argv", [list], u"The argument list of a child process being executed.") IPTABLES = ActionType( _system(u"iptables"), [ARGV], [], u"An iptables command which Flocker is executing against the system.")
realistic manner. That is, mesages are logged in context of a message with a small number of fields. """ from __future__ import unicode_literals import time from eliot import Logger, MessageType, Field, ActionType def _ascii(s): return s.decode("ascii") F1 = Field.forTypes("integer", [int], "") F2 = Field("string", _ascii, "") F3 = Field("string2", _ascii, "") F4 = Field.forTypes("list", [list], "list of integers") M = MessageType("system:message", [F1, F2, F3, F4], "description") A = ActionType("action", [], [], [], "desc") log = Logger() N = 100000 def run(): start = time.time() with A(log):