Skip to content

Conversation

patrickelectric
Copy link
Member

@patrickelectric patrickelectric commented May 28, 2025

Signed-off-by: Patrick José Pereira patrickelectric@gmail.com

Summary by Sourcery

Add an MCAP recorder for Zenoh that dynamically generates JSON schemas and channels per topic, records incoming messages to an MCAP file, and exposes a CLI for subscription and logging configuration.

New Features:

  • Add mcap-logger service to subscribe to Zenoh topics and record JSON messages into an MCAP file with dynamic schema and channel registration
  • Provide a command-line interface to configure the subscription key expression and logging level

Enhancements:

  • Integrate structured logging with configurable levels and comprehensive error handling for robust message processing

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Copy link

sourcery-ai bot commented May 28, 2025

Reviewer's Guide

Introduces a new MCAP logger service that subscribes to Zenoh topics, generates JSON schemas on-the-fly (including special handling for Foxglove logs), registers schemas and channels, and writes incoming messages into an MCAP file; also updates the project’s dependency lock file.

Sequence Diagram: MCAP Logger Message Handling

sequenceDiagram
    participant Z as Zenoh
    participant MLS as McapLoggerService
    participant MW as McapWriter

    MLS ->> Z: Subscribe to key_expr
    %% Message processing loop begins after subscription
    Z ->> MLS: zenoh.Sample (message)
    MLS ->> MLS: Parse JSON payload from sample
    MLS ->> MLS: Validate parsed data
    alt Data is valid and parsed
        alt Topic's schema not yet in schema_map
            alt Topic name ends with "/log" (Foxglove Log)
                MLS ->> MW: register_schema(name="foxglove.Log", encoding="jsonschema", data=JSON_Log_Schema)
                MW -->> MLS: schema_id
                MLS ->> MW: register_channel(schema_id, topic, message_encoding="json")
                MW -->> MLS: channel_id
                MLS ->> MLS: Store schema_id in schema_map
                MLS ->> MLS: Store channel_id in channel_map
            else Regular Topic
                MLS ->> MLS: create_schema(data) (using genson)
                MW -->> MLS: schema_data (JSON bytes)
                MLS ->> MW: register_schema(name=json_topic_name, encoding="jsonschema", data=schema_data)
                MW -->> MLS: schema_id
                MLS ->> MLS: Store schema_id in schema_map
            end
        end

        alt Topic's channel not yet in channel_map AND not a Foxglove Log topic (whose channel was just registered)
            MLS ->> MLS: Get schema_id from schema_map (for regular topic)
            MLS ->> MW: register_channel(schema_id, topic, message_encoding="json")
            MW -->> MLS: channel_id
            MLS ->> MLS: Store channel_id in channel_map
        end

        MLS ->> MLS: Get channel_id from channel_map (guaranteed to be present now)
        MLS ->> MLS: Get current timestamp (ts_ns)
        MLS ->> MW: add_message(channel_id, log_time=ts_ns, publish_time=ts_ns, data=json.dumps(data).encode())
    else Data is invalid or parsing failed
        MLS ->> MLS: Log error/warning and skip message
    end
Loading

File-Level Changes

Change Details Files
Implement MCAP logger service
  • Configure Python logging and argument parsing
  • Add helpers for JSON schema creation and data validation
  • Open Zenoh session, declare subscriber with message listener
  • In listener: parse messages, register schemas and channels, write MCAP messages
core/services/mcap-logger/main.py
Update project lockfile
  • Regenerate core/uv.lock to include new mcap-logger dependencies
core/uv.lock

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant