Module Expr Str Import alias Import alias ImportFrom alias ImportFrom alias Import alias Import alias Import alias Import alias Import alias Import alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias ImportFrom alias Assign NameStore Call NameLoad Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Num Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Num Assign NameStore Call NameLoad Assign NameStore Num FunctionDef arguments args NameParam defaults body Expr Str If Call NameLoad NameLoad NameLoad body If BoolOpOr Call NameLoad NameLoad NameLoad Call NameLoad NameLoad Str body Return NameLoad Return NameLoad decorator_list ClassDef bases body FunctionDef arguments args NameParam defaults vararg kwarg body Pass decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Num Dict body Pass decorator_list FunctionDef arguments args NameParam defaults vararg kwarg body Pass decorator_list decorator_list Assign NameStore Call NameLoad ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Assign NameStore SubscriptLoad NameLoad Index Num FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults Num Num Num body Expr Str FunctionDef arguments args defaults vararg kwarg body If CompareEq Call AttributeLoad AttributeLoad NameLoad attr attr Num body Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad AttributeLoad NameLoad attr attr With Call AttributeLoad AttributeLoad NameLoad attr attr keyword BinOpDiv NameLoad NameLoad keyword BinOpDiv NameLoad NameLoad keyword AttributeLoad NameLoad attr keyword BinOpDiv NameLoad NameLoad NameStore body Return Call NameLoad NameLoad NameLoad NameLoad decorator_list Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults Num Num NameLoad Num Num NameLoad NameLoad NameLoad Num NameLoad NameLoad Num NameLoad NameLoad NameLoad Num body Expr Str ClassDef bases NameLoad NameLoad body FunctionDef arguments args NameParam defaults body Return Call AttributeLoad NameLoad attr decorator_list decorator_list FunctionDef arguments args NameParam defaults body Expr Str Expr Call AttributeLoad NameLoad attr decorator_list For TupleStore NameStore NameStore Call NameLoad NameLoad keyword NameLoad body If CompareEq SubscriptLoad SubscriptLoad NameLoad Index Num Index Num Str body Continue Assign NameStore Call NameLoad NameLoad NameLoad NameLoad If BoolOpOr CompareIs NameLoad NameLoad UnaryOpNot Call NameLoad NameLoad body Continue Expr Call NameLoad NameLoad NameLoad Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Assign NameStore BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list Assign SubscriptStore NameLoad Index Str NameLoad Assign SubscriptStore NameLoad Index Str NameLoad Return Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad NameLoad NameLoad NameLoad decorator_list decorator_list ClassDef bases NameLoad body Expr Str Assign NameStore NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore BinOpMod Str NameLoad If CompareGt Call NameLoad NameLoad NameLoad body Assign NameStore BinOpAdd SubscriptLoad NameLoad Slice NameLoad Str Return NameLoad decorator_list FunctionDef arguments args defaults vararg kwarg body Expr Str TryExcept body Assign NameStore Call AttributeLoad Str attr ListComp Call NameLoad NameLoad comprehension NameStore NameLoad If NameLoad body Assign NameStore Call AttributeLoad Str attr ListComp BinOpMod Str TupleLoad NameLoad Call NameLoad NameLoad comprehension TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Assign NameStore BinOpMod Str TupleLoad NameLoad NameLoad If Call NameLoad NameLoad NameLoad body Return Call AttributeLoad NameLoad attr Str Str Return NameLoad handlers ExceptHandler body Return Str decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return BoolOpAnd UnaryOpNot Call NameLoad NameLoad NameLoad UnaryOpNot Call NameLoad NameLoad NameLoad UnaryOpNot Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call NameLoad NameLoad AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str FunctionDef arguments args NameParam defaults vararg kwarg body Assign NameStore Call AttributeLoad NameLoad attr Str AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Str AttributeLoad NameLoad attr If CompareIs NameLoad NameLoad body Assign NameStore NameLoad Assign NameStore AttributeLoad NameLoad attr While NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr TryExcept body TryExcept body Expr Call AttributeLoad NameLoad attr NameLoad NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr body Raise Call NameLoad Assign NameStore Call NameLoad AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore BinOpSub Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore BinOpMult Call AttributeLoad NameLoad attr Num Expr Call AttributeLoad AttributeLoad NameLoad attr attr Call AttributeLoad Str attr NameLoad NameLoad NameLoad keyword Num Expr Call AttributeLoad NameLoad attr Return NameLoad handlers ExceptHandler type NameLoad name NameStore body Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore BinOpSub Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore BinOpMult Call AttributeLoad NameLoad attr Num Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad Raise ExceptHandler type NameLoad name NameStore body Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr AugAssignSub NameStore Num Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore BinOpSub Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore BinOpMult Call AttributeLoad NameLoad attr Num If Call NameLoad NameLoad body Assign NameStore AttributeLoad NameLoad attr If UnaryOpNot NameLoad body Assign NameStore NameLoad If UnaryOpNot Call AttributeLoad NameLoad attr NameLoad body If CompareLt Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad Raise NameLoad NameLoad NameLoad orelse If Call NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str keyword Num keyword Dict Str AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr keyword NameLoad orelse Expr Call AttributeLoad NameLoad attr Str NameLoad NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str keyword Num keyword Dict Str AttributeLoad NameLoad attr If BoolOpOr AttributeLoad NameLoad attr CompareEq NameLoad Num body Expr Call AttributeLoad NameLoad attr keyword NameLoad orelse Expr Call AttributeLoad NameLoad attr keyword NameLoad If UnaryOpNot NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str keyword Num keyword Dict Str AttributeLoad NameLoad attr Raise Call Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Assign NameStore SubscriptLoad NameLoad Index Num FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults Num NameLoad NameLoad NameLoad NameLoad Num NameLoad NameLoad NameLoad NameLoad Num body Expr Str Assign AttributeStore NameLoad attr Call NameLoad NameLoad keyword Num keyword Num Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Str Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list Assign SubscriptStore NameLoad Index Str NameLoad Assign NameStore Str If AttributeLoad NameLoad attr body Assign NameStore AttributeLoad NameLoad attr If CompareGt Call AttributeLoad NameLoad attr Str Num body Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr Str Index Num For TupleStore NameStore NameStore Call NameLoad NameLoad keyword NameLoad body If CompareEq SubscriptLoad SubscriptLoad NameLoad Index Num Index Num Str body Continue Assign SubscriptStore NameLoad Index NameLoad Call NameLoad NameLoad NameLoad NameLoad Return Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad NameLoad decorator_list decorator_list ClassDef bases NameLoad body Expr Str Assign NameStore NameLoad FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Return If AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr orelse Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call SubscriptLoad AttributeLoad AttributeLoad NameLoad attr attr Index Num AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num If NameLoad body Assign TupleStore NameStore NameStore Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr attr Str Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If UnaryOpNot AttributeLoad NameLoad attr body Return NameLoad Return CompareGt BinOpSub Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str AugAssignAdd AttributeStore NameLoad attr Num If BoolOpOr Call AttributeLoad NameLoad attr CompareEq AttributeLoad NameLoad attr NameLoad body Expr Call AttributeLoad NameLoad attr keyword NameLoad decorator_list decorator_list
N/A N/A Utility class to wrap thrift client to ensure connection and do retries.

Sample usage:

1. First define a client class by inheriting from your thrift-service-client
AND ThriftClientMixin (make sure your thrift-service-client class is the first
base class.) You normally should also make your class a singleton to avoid
creating too many connections to your thrift servers.

      import TestService
      from kingpin.thrift_utils.base_thrift_exceptions import ThriftConnectionError
      from kingpin.thrift_utils.thrift_client_mixin import PooledThriftClientMixin

      class TestServiceConnectionException(ThriftConnectionError):
        pass

      @singleton
      class TestServiceClient(TestService.Client,
                                  ThriftClientMixin):
          def get_connection_exception_class(self):
            return TestServiceConnectionException

2. Create a object of TestServiceClient by passing a HostsProvider
object (see common/utils/hosts.py). Then you are ready to call any
thrift RPC method.

      client = TestServiceClient(
          host_provider=HostProvider(['Test1:8000', 'Test2:8001', ...])

      homefeed = client.getHomefeed(user_id, 0, 50)

      # Or you can pass a per request timeout, e.g.
      homefeed = client.getHomefeed(user_id, 0, 50, rpc_timeout_ms=1000)


NOTE: that TestServiceClient defined above is *not* greenlet-safe. If you
want a GREENLET-SAFE client, inherit from PooledThriftClientMixin instead of
ThriftClientMixin and pass pool_size when creating the client. For example:

1.
      import TestService
      from kingpin.thrift_utils.base_thrift_exceptions import ThriftConnectionError
      from kingpin.thrift_utils.thrift_client_mixin import PooledThriftClientMixin

      class TestServiceConnectionException(ThriftConnectionError):
        pass

      @singleton
      class PooledTestServiceClient(TestService.Client,
                                        PooledThriftClientMixin):
          def get_connection_exception_class(self):
            return TestServiceConnectionException


2.
    client = PooledTestServiceClient(
        host_provider=HostProvider(['Test1:8000', 'Test2:8001', ...])
        pool_size=5)

    client.ping()


Under the hood, PooledTestServiceClient maintains a pool with pool_size
number of TestServiceClient-like objects and make sure every RPC is made
exclusively using one of the clients in the pool.

 N/A datetime N/A functools inspect getmembers inspect ismethod N/A logging N/A os N/A random N/A socket N/A sys N/A time thrift.protocol.TBinaryProtocol TBinaryProtocolAcceleratedFactory thrift.Thrift TApplicationException thrift.Thrift TException thrift.transport.TSocket TTransportException thrift.transport.TSSLSocket TSSLSocket thrift.transport.TTransport TBufferedTransport kazoo_utils.hosts RandomHostSelector base_thrift_exceptions ThriftConnectionTimeoutError connection_pool ConnectionPool retry_policy RetryPolicy TNoDelaySocket TNoDelaySocket N/A DEFAULT_RETRY_POLICY N/A RetryPolicy N/A MILLIS_PER_SEC 1000.0 N/A log N/A N/A logging getLogger __name__ N/A NUM_REQUESTS_FOR_CONNECTION_TEARDOWN N/A N/A N/A os environ get THRIFT_NUM_REQUESTS_FOR_CONNECTION_TEARDOWN 50 N/A SECS_FOR_CONNECTION_TEARDOWN N/A N/A N/A os environ get THRIFT_SECS_FOR_CONNECTION_TEARDOWN 10 N/A DEFAULT_THRIFT_PROTOCOL_FACTORY N/A TBinaryProtocolAcceleratedFactory N/A MAX_NUM_CHARS_LOGGED_PER_PARAM 1000 default_thrift_client_replace_if N/A N/A exception N/A N/A N/A Default policy on whether to replace the underlying thrift client.

    The default policy tests whether the given exception is a user defined
    thrift exception. If the given exception is a user defined thrift exception,
    it indicates the underlying connection to the thrift server is sound and can
    continue to be used.

    Args:
        exception: Exception thrown from method invocation of the thrift client.

    Return:
        True, if the underlying thrift client needs to be replaced; otherwise,
        False will be returned.

     N/A N/A isinstance exception TException N/A N/A N/A N/A isinstance exception TApplicationException N/A hasattr exception thrift_spec N/A N/A False N/A True N/A DummyStatsdClient N/A N/A __init__ N/A N/A self N/A args kwargs N/A N/A N/A increment N/A N/A self stats sample_rate tags N/A 1 N/A N/A N/A N/A timing N/A N/A self N/A args kwargs N/A N/A N/A N/A N/A dummy_statsd N/A DummyStatsdClient PooledThriftClientMixinMetaclass N/A type N/A N/A Metaclass for creating subclass of PooledThriftClientMixin. __new__ N/A N/A mcs classname bases classdict N/A N/A N/A _thrift_client_cls N/A bases N/A 0 _ensure_use_pooled_client N/A N/A self method timeout expiration e2e_timeout N/A 5000 5000 5000 N/A N/A Ensure a call is made exclusively on a client in the connection
            pool.

            Args:
                method: a method from a thrift-client class.
                timeout: the maximum time (ms) to wait for a connection.
                expiration: the maximum time (ms) the method may execute using
                    a connection before an exception may be raised.
                e2e_timeout: the end-to-end timeout (ms), including both the
                    time spent on acquire the connection and rpc, and all the
                    retries if there is any.

            Returns:
                a wrapped version of method that grabs a client from the pool
                and uses the client to perform the method.

             wrap_with_pool N/A N/A N/A args kwargs N/A N/A N/A N/A N/A N/A self client_pool qsize 0 N/A N/A N/A N/A log info N/A Contention on thrift-pool %s. Empty pool. N/A N/A self client_pool pool_name N/A N/A N/A N/A self client_pool get_connection timeout N/A timeout MILLIS_PER_SEC expiration N/A expiration MILLIS_PER_SEC replace_if N/A self conn_replace_policy e2e_timeout N/A e2e_timeout MILLIS_PER_SEC client N/A N/A N/A method client args kwargs N/A N/A N/A functools wraps method N/A wrap_with_pool N/A __init__ N/A N/A self host_provider pool_size timeout retry_policy connection_wait_timeout connection_expiration statsd_client socket_connection_timeout always_retry_on_new_host retry_count conn_replace_policy protocol_factory e2e_timeout is_ssl validate ca_certs failed_retry_policy_log_sample_rate N/A 5 5000 None 5000 5000 dummy_statsd None False 3 default_thrift_client_replace_if DEFAULT_THRIFT_PROTOCOL_FACTORY 5000 False True None 1.0 N/A N/A Constructor for PooledThriftClientMixin's subclass.

            The five timeout parameters interact in the following way:

                1. Wait 'connection_wait_timeout' to acquire a connection from
                   the pool. If timeout, give up and raise an exception (most
                   likely gevent.queue.Empty).

                2. Once a connection is acquired, the number of milliseconds
                   specified by 'connection_expiration' is available for the
                   connection, including all retries.  If more time elapses,
                   a services.utils.connection_pool.ExpiredConnection exception
                   is raised.

                3. If the underlying connection needs to be established for
                   first time, we will only wait up to
                   ``socket_connection_timeout``, if connection timeout
                   happens, we will get socket error, and the retry
                   mechanism will start to kick in. By default, it is None,
                   which will fallback to timeout specified.

                4. If the RPC fails or takes more than 'timeout' milliseconds
                   and the 'connection_expiration' limit has not been eached,
                   the RPC will be retried up to three times.

                5. ``e2e_timeout`` is the end-to-end timeout setting that take
                    both ``connection_wait_timeout`` and
                    ``connection_expiration``. If you only want to specify one
                    timeout on your client, specify this one.

            In general, the ExpiredConnection exception should not be caught in
            the context of retry logic. The exception is meant to be used as
            the last resort to prevent connection leaks caused by clients
            holding the connection forever.

            If the desired behavior is to guarantee time for all retries, the
            recommended client strategy is to set 'connection_expiration' to at
            least 'timeout' multiplied by the number of retries allowed (3).

            Args:
                host_provider: a HostProvider object to that provide a list of
                available "host:port".
                pool_size: max number of clients in the pool.
                socket_connection_timeout: the socket timeout (ms) for
                    establishing the underlying socket connection for the
                    first time.
                timeout: the socket timeout (ms) passed ot the connection pool.
                retry_policy: an instance of RetryPolicy. It should have a
                    function 'should_retry' that takes an exception as argument
                    and return a boolean value indicating whether the RPC
                    should be retried. See RetryPolicy in retry_policy.py for
                    the default retry policy.
                connection_wait_timeout: the maximum time (ms) to wait for a
                    connection to become available in the connection pool.
                connection_expiration: the maximum time (ms) a connection is
                    allowed to be out of the connection pool.
                statsd_client: a statsd client to report stats.
                socket_connection_timeout: timeout when connecting to a thrift
                    server.
                always_retry_on_new_host: whether to always retry on a new host.
                    By default, only the last retry is on a new host.
                retry_count: total number of attempts before fail a request.
                conn_replace_policy: a function that takes one argument which
                    is an exception and return a boolean indicating whether
                    to discard the connection for the exception. By default,
                    a connection is discarded for all exceptions other than user
                    defined thrift exceptions.
                protocol_factory: thrift protocol factory.
                e2e_timeout: end-to-end timeout in milliseconds. It includes
                    time taken for establishing connection, retries if
                    necessary, etc. If you only specify one timeout on your
                    client, this is the one you should specify.
                is_ssl: use SSL connection or not, default is False.
                validate: Set to False to disable SSL certificate validation.
                ca_certs: Filename to the Certificate Authority pem file.
                failed_retry_policy_log_sample_rate: sometimes the "failed retry policy
                    becomes too overwhelming so you can set a logging
                    sample rate which ranges from [0, 1.0].

             _ThriftClientMixinClass N/A _thrift_client_cls ThriftClientMixin N/A get_connection_exception_class N/A N/A mixin_self N/A N/A N/A N/A N/A self get_connection_exception_class N/A N/A _close_conn N/A N/A client N/A N/A N/A Close the socket maintained by the client. N/A N/A N/A client teardown_connection N/A N/A N/A method_name method N/A getmembers _ThriftClientMixinClass predicate ismethod N/A N/A N/A N/A N/A method_name N/A 0 N/A 0 _ N/A N/A N/A client_attr N/A getattr _thrift_client_cls method_name None N/A N/A N/A client_attr None N/A N/A ismethod client_attr N/A N/A N/A N/A setattr self method_name N/A N/A self _ensure_use_pooled_client method timeout connection_wait_timeout expiration connection_expiration e2e_timeout e2e_timeout N/A pool_name N/A %s.%s N/A N/A _thrift_client_cls __module__ N/A _thrift_client_cls __name__ N/A N/A self client_pool N/A ConnectionPool pool_name pool_name pool_size pool_size close_conn_f _close_conn conn_cls _ThriftClientMixinClass host_provider host_provider timeout timeout statsd_client statsd_client retry_policy retry_policy socket_connection_timeout socket_connection_timeout always_retry_on_new_host always_retry_on_new_host retry_count retry_count protocol_factory protocol_factory is_ssl is_ssl validate validate ca_certs ca_certs failed_retry_policy_log_sample_rate failed_retry_policy_log_sample_rate N/A N/A self conn_replace_policy conn_replace_policy N/A N/A N/A classdict N/A _ensure_use_pooled_client _ensure_use_pooled_client N/A N/A classdict N/A __init__ __init__ N/A N/A N/A N/A super PooledThriftClientMixinMetaclass mcs __new__ mcs classname bases classdict N/A N/A PooledThriftClientMixin N/A object N/A N/A Greenlet-safe version of ThriftClientMixin.

    It wraps around ThriftClientMixin by pooling multiple ThriftClientMixin
    objects and delegates operations on them exclusively. Sample usage:

    class PooledTestServiceClient(TestService.Client,
                                      PooledThriftClientMixin):
        def get_connection_exception_class(self):
            return SomeExceptionClass

     N/A __metaclass__ PooledThriftClientMixinMetaclass N/A _param_to_str N/A N/A param N/A N/A N/A  convert param to a string of limited number of characters.  N/A param_str N/A %s param N/A N/A N/A len param_str MAX_NUM_CHARS_LOGGED_PER_PARAM N/A N/A param_str N/A N/A param_str N/A MAX_NUM_CHARS_LOGGED_PER_PARAM ... N/A param_str N/A args_to_str N/A N/A N/A args kwargs N/A N/A Return a string for the given args/kwargs. N/A N/A N/A handler_args N/A N/A , join N/A N/A _param_to_str x N/A x args N/A kwargs N/A N/A kw_args N/A N/A , join N/A N/A %s=%s N/A k N/A _param_to_str v N/A N/A k v N/A N/A kwargs iteritems N/A handler_args N/A %s,%s N/A handler_args kw_args N/A N/A isinstance handler_args unicode N/A N/A N/A N/A handler_args encode utf-8 ignore N/A handler_args N/A N/A N/A N/A ERROR N/A _is_application_exception N/A N/A e N/A N/A N/A  check whether an exception is application specific exception.  N/A N/A N/A N/A isinstance e TTransportException N/A N/A isinstance e ThriftConnectionTimeoutError N/A N/A isinstance e IOError N/A _is_rpc_timeout N/A N/A e N/A N/A N/A  check whether an exception individual rpc timeout.  N/A N/A isinstance e N/A socket timeout N/A ensure_connection N/A N/A service_name method_name method N/A N/A N/A Ensure that client is connected before executing method.

    .. note:: Class to which this decorator is applied **must** have
       ``get_connection_exception_class()`` method that would return the
       class of the exception to be thrown when retryable connection
       exception is repacked.

    This decorator can only be applied to class methods,
    not a non-class function.

    Args:
        method_name: A string, the name of the method to be ensured.
        method: A string, the actual method to be ensured.

    Returns:
        Whatever the executed method returns.

     method_wrapper N/A N/A self N/A args kwargs N/A N/A req_timeout_ms N/A N/A kwargs pop rpc_timeout_ms N/A self timeout N/A conn_timeout_ms N/A N/A kwargs pop rpc_timeout_ms N/A self socket_connection_timeout N/A N/A conn_timeout_ms None N/A N/A conn_timeout_ms req_timeout_ms N/A retries_left N/A self retry_count N/A retries_left N/A N/A start_time N/A N/A N/A datetime datetime now N/A N/A N/A N/A N/A N/A N/A self connect conn_timeout_ms req_timeout_ms N/A N/A N/A N/A socket timeout N/A N/A N/A ThriftConnectionTimeoutError N/A result N/A method N/A self _client args kwargs N/A time_taken N/A N/A N/A N/A datetime datetime now start_time N/A time_taken_ms N/A N/A N/A time_taken total_seconds 1000 N/A N/A N/A N/A self statsd_client timing N/A N/A client.requests.{0}.{1} format service_name method_name time_taken_ms sample_rate 0.001 N/A N/A N/A self refresh_connection_if_needed N/A result N/A N/A N/A TApplicationException N/A e N/A N/A handler_args N/A args_to_str args kwargs N/A time_taken N/A N/A N/A N/A datetime datetime now start_time N/A time_taken_ms N/A N/A N/A time_taken total_seconds 1000 N/A N/A N/A log info N/A Thrift call failed TApplicationException : %s(%s) : %s:%d : time_taken_ms : %s : %s N/A method_name handler_args N/A self host N/A self port time_taken_ms e N/A N/A N/A Exception N/A e N/A N/A N/A t v tb N/A N/A sys exc_info N/A retries_left 1 N/A handler_args N/A args_to_str args kwargs N/A time_taken N/A N/A N/A N/A datetime datetime now start_time N/A time_taken_ms N/A N/A N/A time_taken total_seconds 1000 N/A N/A _is_application_exception e N/A N/A retry_policy_to_apply N/A self retry_policy N/A N/A retry_policy_to_apply N/A N/A retry_policy_to_apply DEFAULT_RETRY_POLICY N/A N/A N/A N/A retry_policy_to_apply should_retry e N/A N/A N/A N/A N/A random random N/A self failed_retry_policy_log_sample_rate N/A N/A N/A N/A log info N/A Thrift call failed retry policy : %s(%s) :%s:%d : time_taken_ms : %s : %s N/A method_name handler_args N/A self host N/A self port time_taken_ms e N/A t v tb N/A N/A N/A _is_rpc_timeout e N/A N/A N/A N/A log info N/A Thrift call failed rpc timeout : %s(%s) :%s:%d : time_taken_ms : %s : %s N/A method_name handler_args N/A self host N/A self port time_taken_ms e N/A N/A N/A N/A self statsd_client increment errors.thriftclient.RpcTimeoutError sample_rate 0.01 tags N/A client N/A self host N/A N/A N/A self teardown_connection select_new_host True N/A N/A N/A N/A log info Thrift client connection fail : %s(%s) : %s:%d : retries_left=%d : time_taken_ms : %s  %r method_name handler_args N/A self host N/A self port retries_left time_taken_ms e N/A N/A N/A N/A self statsd_client increment errors.thriftclient.ConnectionError sample_rate 0.01 tags N/A client N/A self host N/A N/A N/A self always_retry_on_new_host N/A retries_left 1 N/A N/A N/A N/A self teardown_connection select_new_host True N/A N/A N/A N/A self teardown_connection select_new_host False N/A N/A retries_left N/A N/A N/A N/A log info N/A Thrift call failed all retries : %s(%s) : %s:%d : time_taken_ms: %s %s N/A method_name handler_args N/A self host N/A self port time_taken_ms e N/A N/A N/A N/A self statsd_client increment errors.thriftclient.AllConnectionError sample_rate 0.01 tags N/A client N/A self host N/A N/A N/A N/A self get_connection_exception_class e None tb N/A N/A N/A functools wraps method N/A method_wrapper N/A ThriftClientConnectionEnsured N/A type N/A N/A Metaclass to wrap all methods with ensure_connection(). __new__ N/A N/A cls classname bases classdict N/A N/A N/A _client_cls N/A bases N/A 0 __init__ N/A N/A self host_provider timeout retry_policy statsd_client socket_connection_timeout always_retry_on_new_host retry_count protocol_factory is_ssl validate ca_certs failed_retry_policy_log_sample_rate N/A 5000 None dummy_statsd None False 3 DEFAULT_THRIFT_PROTOCOL_FACTORY False True None 1.0 N/A N/A Replacement of subclass constructor.

            Args:
                host_provider: A ``HostProvider`` to provide the list of
                    live hosts for the client to talk to.
                timeout: Timeout in milliseconds for connections.
                retry_policy: On what exception the request should be retried.
                socket_connection_timeout: timeout for establishing the
                    underlying socket connection for the first time. By
                    default, it is None, which will fallback to timeout
                    specified.
                always_retry_on_new_host: If set, always retry on a new host.
                retry_count: total number of tries of rpc.
                protocol_factory: the factory of the underlying protocol to
                                  be used for rpc.
                is_ssl: use SSL connection or not, default is False.
                validate: Set to False to disable SSL certificate validation.
                ca_certs: Filename to the Certificate Authority pem file.
                failed_retry_policy_log_sample_rate: sometimes the "failed retry policy
                becomes too overwhelming so you can set a logging
                 sample rate which ranges from [0, 1.0].
             N/A N/A self _host_selector N/A RandomHostSelector host_provider expire_time 0 retry_time 0 N/A host_port_pair N/A N/A N/A self _host_selector get_host N/A N/A host port N/A N/A host_port_pair split : N/A N/A self host host N/A N/A self port N/A int port N/A N/A self timeout timeout N/A N/A self is_ssl is_ssl N/A N/A self validate validate N/A N/A self ca_certs ca_certs N/A N/A self retry_policy retry_policy N/A N/A self retry_count retry_count N/A N/A self socket_connection_timeout socket_connection_timeout N/A N/A self always_retry_on_new_host always_retry_on_new_host N/A N/A self connected False N/A N/A self connected_at 0 N/A N/A self requests_served 0 N/A N/A self statsd_client statsd_client N/A N/A self protocol_factory protocol_factory N/A N/A self failed_retry_policy_log_sample_rate failed_retry_policy_log_sample_rate N/A N/A N/A classdict N/A __init__ __init__ N/A service_name Base N/A N/A _client_cls __module__ N/A N/A service_name N/A _client_cls __module__ N/A N/A N/A N/A service_name split . 0 N/A N/A service_name N/A N/A N/A service_name split . N/A -1 N/A N/A method_name method N/A getmembers _client_cls predicate ismethod N/A N/A N/A N/A N/A method_name N/A 0 N/A 0 _ N/A N/A N/A N/A classdict N/A method_name N/A ensure_connection service_name method_name method N/A N/A N/A type __new__ cls classname bases classdict N/A N/A ThriftClientMixin N/A object N/A N/A Mixin for all Thrift clients.

    Provides the following features:

      - Simplified instantiation using host and port
      - Opaque singleton instantiation
      - Lazy connection
      - Ensures client is connected on each call

     N/A __metaclass__ ThriftClientConnectionEnsured connect N/A N/A self conn_timeout_ms req_timeout_ms N/A N/A N/A Connect to the endpoint specified in self.host and self.port.

        .. note:: It makes connection only if it's not already connected.

         N/A N/A self connected N/A N/A N/A N/A N/A self _socket setTimeout req_timeout_ms N/A N/A N/A self is_ssl N/A N/A N/A self _socket N/A TSSLSocket N/A self host N/A self port N/A self validate N/A self ca_certs N/A N/A N/A self _socket N/A TNoDelaySocket N/A self host N/A self port N/A N/A N/A N/A self _socket setTimeout conn_timeout_ms N/A N/A self _transport N/A TBufferedTransport N/A self _socket N/A N/A N/A N/A self _transport open N/A N/A self _protocol N/A N/A N/A self protocol_factory getProtocol N/A self _transport N/A N/A self _client N/A N/A N/A N/A self __class__ __bases__ N/A 0 N/A self _protocol N/A N/A self connected True N/A N/A self connected_at N/A N/A time time N/A N/A N/A N/A self _socket setTimeout req_timeout_ms N/A teardown_connection N/A N/A self select_new_host N/A False N/A N/A Tear down the connection.

        Args:
            select_new_host: Boolean, whether to reset self.host and
            self.port to a random one from host_provider specified in
            the constructor.

         N/A N/A self connected N/A N/A N/A N/A N/A self _transport close N/A N/A self connected False N/A N/A self connected_at 0 N/A N/A self _transport None N/A N/A self _socket None N/A N/A self requests_served 0 N/A select_new_host N/A N/A N/A new_host new_port N/A N/A N/A N/A N/A self _host_selector get_host split : N/A N/A self host new_host N/A N/A self port N/A int new_port N/A _is_connection_old N/A N/A self N/A N/A N/A Check whether the current connection age is beyond configured time.
         N/A N/A N/A self connected N/A N/A False N/A N/A N/A N/A N/A time time N/A self connected_at SECS_FOR_CONNECTION_TEARDOWN N/A refresh_connection_if_needed N/A N/A self num_requests N/A NUM_REQUESTS_FOR_CONNECTION_TEARDOWN N/A N/A Track whether we need connect to a new endpoint.

        :param num_requests: number of requests needed for connection to be
            torn down and a new endpoint chosen.  New endpoint is lazily
            established in ``ensure_connection()`` call.
         N/A N/A self requests_served 1 N/A N/A N/A N/A self _is_connection_old N/A N/A self requests_served NUM_REQUESTS_FOR_CONNECTION_TEARDOWN N/A N/A N/A N/A self teardown_connection select_new_host True N/A N/A