Git Product home page Git Product logo

pysoa's Introduction

PySOA (Deprecated)

https://readthedocs.org/projects/pysoa/badge/ https://pepy.tech/badge/pysoa

PySOA is deprecated, and is not a recommended solution. Please use another RPC protocol.

Basic Tenets

  • Services and actions both have simple names, and are called from the client by name. You can call actions individually, or bundle multiple action calls into a "job" to be run serially (either aborting or continuing on error).
  • Requests and responses are simply Python dictionaries, and PySOA uses our open source validation framework Conformity in order to verify their schema on the way in and out.
  • Message bodies are encoded using MessagePack by default (however, you can define your own serializer), with a few non-standard types encoded using MessagePack extensions, such as dates, times, date-times, and amounts of currency (using our open source currint library).
  • Requests have a context, which is sourced from the original client context (web request, API request, etc.) and automatically chained down into subsequent client calls made inside the service. This is used for contextual request information like correlation IDs, authentication tokens, locales, etc.
  • We include "SOA Switches" as a first-party implementation of feature flags/toggles. Part of the context, they are bundled along with every request and automatically chained, and are packed as integers to ensure they have minimal overhead.

This intro summarizes some of the key concepts of using PySOA. For more thorough documentation, see the PySOA Documentation.

License

PySOA is licensed under the Apache License, version 2.0.

Installation

PySOA is available in PyPi and can be installing directly via Pip or listed in setup.py, requirements.txt, or Pipfile:

pip install 'pysoa~=1.2'
install_requires=[
    ...
    'pysoa~=1.2',
    ...
]
pysoa~=1.2
pysoa = {version="~=1.2"}

Documentation

The complete PySOA documentation is available on Read the Docs!

pysoa's People

Contributors

adamsussman avatar akirmse-eb avatar andrewgodwin avatar bar avatar danpinkard-eb avatar eb-emilio avatar eb-enzo avatar eb-nahuel avatar ebwill avatar eyalr avatar farrokhi avatar jshuping avatar leonardoa-eb avatar mauricioh-eb avatar michaelmanganiello-eb avatar miguelsanchez-eb avatar miloops avatar nickwilliams-eventbrite avatar renzo-eb avatar rmathews-eb avatar sethbrite avatar shen-lung avatar vartec avatar vellis-eb avatar yanguo-eb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pysoa's Issues

`stub_action` doesn't play nice with `side_effect`s that raise errors

OS: macOS mojave 10.14.6 (18G2022)
Python: Python 3.7.6 (CPython)

stub_action seems to "cache" exceptions given through side_effect, effectively ignoring whatever values come next and re-raising the exception it encountered indefinitely.

STR:

  1. pip3 install pytest==5.3.5 pysoa==1.1.0
  2. python3
  3. Paste this code:
import pytest
from pysoa.client.client import Client
from pysoa.common.transport.errors import MessageReceiveTimeout
from pysoa.test.stub_service import stub_action


def test_it():
    client = Client(config={})
    with stub_action('foo', 'bar', side_effect=[MessageReceiveTimeout('foo'), {}]):
        with pytest.raises(MessageReceiveTimeout):
            client.call_action('foo', 'bar')
        client.call_action('foo', 'bar')


test_it()

"IndexError: list index out of range" in Client. _expand_objects

Unknown cause at this point.

Traceback (most recent call last):
...
  File "pysoa/client/client.py", line 450, in call_actions
    **kwargs
  File "pysoa/client/client.py", line 245, in result
    self._response = self._get_response(timeout)
  File "pysoa/client/client.py", line 653, in get_response
    self._perform_expansion(response.actions, expansions, **kwargs)
  File "pysoa/client/client.py", line 889, in _perform_expansion
    self._expand_objects(objects_to_expand, **kwargs)
  File "pysoa/client/client.py", line 964, in _expand_objects
    action_response = response.actions[0]
IndexError: list index out of range

Remove all Python 2.7-3.6 support

This is the tracking issue for removing all support for Python 2.7 and 3.5-3.6. Once closed, PySOA will support only Python 3.7 and above and will use Python Typing syntax instead of Python Typing comments, removing try/except around the existing AsyncIO support, eliminate the use of the six library, and remove backports (enum, typing, etc.) from the list of dependencies. Some or all Attrs classes may possibly switched to dataclasses, as well.

Put in place content length checks to make problems more visible

Issues with chunked message reassembly in the Redis transport, such as #240, would be easier to diagnose if we included chunk-length and content-length headers and performed sanity checks on received chunks and re-assembled messages with those headers. However, such a change cannot be included in the fix for #240, because it will require a new minor version and a new Redis protocol version (4).

`UnicodeDecodeError` causing `InvalidMessageError` trying to deserialize a message when chunked

When chunking is enabled, some large, chunked messages are causing a UnicodeDecodeError which causes an InvalidMessageError when the re-assembled chucks are deserialized by Message Pack.

Root cause analysis: We are stripping whitespace from serialized messages when extracting header information. When messages are chunked and the chunk boundary lands on a whitespace character, this causes the re-assembled message to fail to deserialize.

Change ServerMiddleware.job to use JobRequest instead of dict

The callable accepted and returned by ServerMiddleware.action accepts an EnrichedActionRequest and returns an ActionResponse. The callable accepted and returned by ServerMiddleware.job returns a JobResponse, but inconsistently accepts a dictionary. It should accept a JobRequest for consistency.

Distinguish server/code errors from caller errors

Some errors are the result of caller misaction and require caller action to resolve. Other errors are the result of server mis-coding, mis-configuration, or broken dependencies (databases, etc.) and require operational or engineering action to resolve. The nature of these errors are very different and organizations frequently track them differently. For example, organizations that employ "error budgets" for autonomous teams deploying microservices don't typically count user-input validation errors against the error budget, but do count uncaught exceptions and inaccessible resources against the error budget.

This proposal involves add an is_caller_error attribute to Error objects to be able to distinguish the difference between these two sources of errors. JobErrors would have an is_caller_error argument that defaults to False and ActionErrors would have one that defaults to True. Services, middleware, and some PySOA code will override these defaults when necessary to indicate the precise nature of errors.

TestPlans: emptydict and emptylist are ignored when global inputs are defined

  • Your operating system name and version.

ProductName: Mac OS X
ProductVersion: 10.15.5
BuildVersion: 19F101

  • Your Python interpreter type and version.

Python 3.7.7

  • Any details about your local setup that might be helpful in troubleshooting.
    None
  • Detailed steps to reproduce the bug.
    Create a test plan using a global input using a nested list/dict structure, like:
echo.0: global input:                  global_echo_list.0.foo: bar

test name: case_001
test description: testing
# one
echo.0: expect: no errors
# two
echo.1: input emptydict:               local_echo_list.0:
echo.1: input:                         local_echo_list.1.bar: foo
echo.1: input emptydict:               local_echo_list.2:
echo.1: expect: no errors

And this test case:

from __future__ import absolute_import, unicode_literals
import os

from pprint import pprint as pp
from conformity import fields

from pysoa.server.action.base import Action
from pysoa.server.server import Server
from pysoa.test.plan import ServicePlanTestCase

class EchoAction(Action):
    request_schema = fields.SchemalessDictionary()
    response_schema = fields.SchemalessDictionary()
    def run(self, request):
        pp(request.body)
        return request.body

class StubServer(Server):
    service_name = 'stub'
    action_class_map = {'echo': EchoAction}

class TestPySOAPlans(ServicePlanTestCase):
    server_class = StubServer
    server_settings = {}
    fixture_path = os.path.dirname(__file__) + '/plans'

Run that test and verify that local_echo_list only has 1 item in it.

  • Expected Behavior:
    Run that test and receive a local_echo_list with 3 items in it.

Client and server cannot communicate if one is Python 2 and the other is Python 3

If the SOA client is on Python 2 while the server is on Python 3, or vice versa, they are not able to communicate due to missing key errors, because the top-level request message keys on the Python 2 side are serialized as non-unicode, while the top-level response message keys on the Python 3 side are expected to be unicode and are actually bytes.

Disabling raise_job_errors with a single action call results in IndexError

When using raise_job_errors=False, I instead received IndexError: list index out of range. It appears that the client is trying to reference actions[0] in call_action_future, but since there is only one call that had a JobError, there is no action to reference.

Traceback (most recent call last):
  File "/usr/local/www/REDACTED/lib/python2.7/site-packages/service/job.py", line 867, in run
    action.run(self, controller, idx)
  -- STACK TRACE REDACTED
  File "/usr/local/www/REDACTED/lib/python2.7/site-packages/REDACTED/utils.py", line 121, in get_hierarchy_from_coordinates
    raise_job_errors=False,
  File "/usr/local/www/REDACTED/lib/python2.7/site-packages/pysoa/client/client.py", line 390, in call_action
    return self.call_action_future(service_name, action, body, **kwargs).result()
  File "/usr/local/www/REDACTED/lib/python2.7/site-packages/pysoa/client/client.py", line 245, in result
    self._response = self._get_response(timeout)
  File "/usr/local/www/REDACTED/lib/python2.7/site-packages/pysoa/client/client.py", line 594, in <lambda>
    return self.FutureResponse(lambda _timeout: future.result(_timeout).actions[0])
IndexError: list index out of range

Move some server metrics gauges from internal code to PySOA

Some server gauges exist only in our internal code due to our disparate metrics setup. Now that PySOA uses PyMetrics, move those to PySOA so that they are properly (and more accurately) integrated into the startup and request workflows.

Double-import trap in standalone services breaks on Python 3.7 when used with -m

PySOA has a double-import trap to stop standalone services from starting like this:

python /path/to/service_module/standalone.py

This is because starting like that can cause double-imports that break all kinds of things (even overriding system modules).

However, this double-import trap has broken in Python 3.7, due to this change:

When using the -m switch, the initial working directory is now added to sys.path, rather than an empty string (which dynamically denoted the current working directory at the time of each import). Any programs that are checking for the empty string, or otherwise relying on the previous behaviour, will need to be updated accordingly (e.g. by also checking for os.getcwd() or os.path.dirname(__main__.__file__), depending on why the code was checking for the empty string in the first place).

This needs to be fixed.

Add support for response chunking in Redis Gateway transport

Sometimes, services legitimately need to return very large responses. The current paradigm of establishing a hard limit on response size discourages that. The reason for this is that multi-megabyte responses can significantly reduce the throughput of Redis. Since it is single-threaded, multiple services and clients can block for an unreasonably long time waiting for Redis to handle the I/O of a single response. We need to make it easier to send very large responses without choking Redis.

Response chunking is the solution. With response chunking, a 10MB response divided into 40 chunks of 250kb each would take longer for that server to send and its client to receive, but it would not impact Redis more than other responses, because the work would be spread out and other requests and responses could be handled while that response is being sent and received.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.