Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python bindings #426

Merged
merged 16 commits into from
Oct 24, 2024
Merged

Python bindings #426

merged 16 commits into from
Oct 24, 2024

Commits on Oct 21, 2024

  1. events: do not derive Default on event sections

    It is not required by the core or by any other piece of infrastructure.
    Only some events need to derive from Default because of the way they are
    constructed.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    a9aa217 View commit details
    Browse the repository at this point in the history
  2. events: ovs: Use Option instead of unit enum value.

    OVS module currently makes no assumptions on the order of the event
    chunks and tries to build the event even if out-of-order pieces are
    received. This makes little sense in practice as these chuncks are sent
    in the same hook.
    
    Removing that unneeded requirement and assuming the base action event
    (OVS_DP_ACTION) will be received before specific action argument events
    (e.g: OVS_DP_ACTION_OUTPUT) makes decoding simpler.
    
    This also it avoids requiring a Default version of the event which is
    currently implemented using an "undefined" value for enums. This
    mechanism is not supported by pyo3.
    
    Also, create a dummy object to avoid having mixed complex unit variants
    in enums.
    
    [1] Upstream discussions:
    PyO3/pyo3#3582 (comment)
    PyO3/pyo3#3749
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    ba01022 View commit details
    Browse the repository at this point in the history
  3. events: move TestEvent to event crate.

    It is useful to be able to define a dummy event to test their creation
    (factories) and manipulation.
    
    However, in preparation to add python support, we must ensure pyo3
    dependencies only come from retis-events. Therefore, all events must be
    defined there, including TestEvent.
    
    Create a feature to enable this dummy event that is enabled only when
    "cargo test" is run on the main crate.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    ce8cef4 View commit details
    Browse the repository at this point in the history
  4. events: move EventSeries to events crate.

    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    cb81d64 View commit details
    Browse the repository at this point in the history
  5. events: make events implement Send

    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    42086d2 View commit details
    Browse the repository at this point in the history
  6. helpers: bimap: explicitly name the lifetime

    It would anyway be resolved to 'a and nightly toolchain prefers it to be
    explicit.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    417373c View commit details
    Browse the repository at this point in the history
  7. events: simplify EventFactory API.

    It currently uses a struct EventResult that was originally thought to be
    used when creating events from ebpf as it has a timeout. The file
    factory is not using this so we can express the result as
    Result<Option<Event>>.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    0174e46 View commit details
    Browse the repository at this point in the history
  8. python: add python event representation.

    Use pyo3 to represent events and event sections.
    
    Notably, this requires some simple enums to implement PartialEq.
    Also, SectionId::from_str() has to be recovered.
    
    EventTypes are given a __repr__() helper that uses the debug formatter.
    It seems a good first start.
    
    EventSections are given a __repr__() helper that prints a dictionary
    based on the json object as well as a show() helper that formats the
    event.
    
    Co-authored-by: Adrian Moreno <[email protected]>
    Signed-off-by: Antoine Tenart <[email protected]>
    Signed-off-by: Adrian Moreno <[email protected]>
    atenart and amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    9e0038e View commit details
    Browse the repository at this point in the history
  9. events: add interactive python shell

    Add an python shell as post-process command.
    
    Signed-off-by: Antoine Tenart <[email protected]>
    Co-authored-by: Antoine Tenart <[email protected]>
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz and atenart committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    c851aef View commit details
    Browse the repository at this point in the history
  10. events: add section iterator.

    Add a helper to iterate through the available sections of an event.
    Expose such helper to the python representation.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    3395af4 View commit details
    Browse the repository at this point in the history
  11. events: support Series in FileEventFactory

    Currently, EventSeries are created, printed and even encoded into json
    but we do not support reading it back from json.
    
    This patch adds support for EventSeries in FileEventFactory.
    The type of file that is being processed is autodetected upon creation
    and a differnt interface (next_series()) is used to retrieve EventSeries
    so that typing is clear.
    
    By also adding TrackingInfo to the types that unmarshal, we can now do:
    
    ```
    retis collect [...]
    retis sort -o sorted.json
    retis print sorted.json
    ```
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    e478159 View commit details
    Browse the repository at this point in the history

Commits on Oct 24, 2024

  1. retis-events: introduce python library.

    The features used for pyo3 are different (and not-compatible)
    for the embedded interpreter and python bindings, so move the
    interpreter into an independent file that is easy to conditionally
    compile off.
    
    Use maturin to build with stable abi3.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 24, 2024
    Configuration menu
    Copy the full SHA
    33985cf View commit details
    Browse the repository at this point in the history
  2. ci: add a cirrus task to build python bindings

    Store the result as artifact to ease testing.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 24, 2024
    Configuration menu
    Copy the full SHA
    484f634 View commit details
    Browse the repository at this point in the history
  3. docs: Document python bindings

    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 24, 2024
    Configuration menu
    Copy the full SHA
    ef9946f View commit details
    Browse the repository at this point in the history
  4. events: add python library tests

    Use tox to handle virtual env and pytest to as test runner.
    Add a task in cirrus CI to run them.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 24, 2024
    Configuration menu
    Copy the full SHA
    574ac76 View commit details
    Browse the repository at this point in the history
  5. Cargo.toml: make python optional but default.

    Python support provided by pyo3 requires linking against python >= 3.6.
    Building retis on distros with older python versions would fail. In
    order to work around this issues, make python an optional dependency but
    enable it by default.
    
    On non-supported distros, CARGO_CMD_OPTS="--no-default-features" can be
    used to build without python support.
    
    Signed-off-by: Adrian Moreno <[email protected]>
    amorenoz committed Oct 24, 2024
    Configuration menu
    Copy the full SHA
    b4f20e0 View commit details
    Browse the repository at this point in the history