SunilKumarPradhan opened a new pull request, #4490:
URL: https://github.com/apache/iggy/pull/4490

   Closes #4420. Part of #3893 (row 9).
   
   ## What
   
   Add `IggyClient.get_cluster_metadata()` to the Python SDK. It returns 
`ClusterMetadata`.
   `ClusterMetadata` holds the cluster name and a list of `ClusterNode` objects.
   Each node has `name`, `ip`, `endpoints`, `role` and `status`.
   
   New types: `ClusterMetadata`, `ClusterNode`, `TransportEndpoints`, 
`ClusterNodeRole`, `ClusterNodeStatus`.
   The names match the Java, Go and C# SDKs.
   
   ```python
   metadata = await client.get_cluster_metadata()
   metadata.name                  # 'single-node'
   node = metadata.nodes[0]
   node.role, node.status         # ClusterNodeRole.Leader, 
ClusterNodeStatus.Healthy
   node.endpoints                 # TransportEndpoints(tcp=8090, quic=8080, 
http=3000, websocket=8092)
   ```
   
   ## How
   
   - `src/cluster.rs` wraps the Rust types and follows `src/stats.rs`.
   - `src/client.rs` adds the method next to `get_stats`.
   - `apache_iggy.pyi` is regenerated with `cargo run --bin stub_gen` and the 
ruff hooks.
   - `tests/test_cluster.py` follows `tests/test_stats.py`.
   
   ## Notes for the reviewer
   
   - The server needs a logged-in user for this call, but no global permission
     (`core/server/src/dispatch/authz.rs`). `get_stats` is different.
     The docstring and one test state this.
   - `ClusterNode.ip` can hold a host name when the server sets an advertised 
address.
     The name `ip` matches the Rust type.
   - A server that runs without clustering reports one node, `Leader` and 
`Healthy`.
     The test asserts exactly that.
   
   ## Testing
   
   Run in a Linux container on top of `master` at 5ded8ff62, against an 
`iggy-server` built from the same source.
   The method was called over TCP only.
   
   - `pytest tests/test_cluster.py`: 4 passed
   - `pytest tests/` without `test_tls.py`: 826 passed
   - `cargo fmt --check`, `cargo clippy --all-targets --all-features -- -D 
warnings`, `cargo test`: pass
   - `ruff check`, `ruff format --check`, `pyrefly check`, `typos`: pass
     (the changed Python files were checked again with the current `uv.lock` 
versions, ruff 0.16.9 and pyrefly 1.3.2)
   - `apache_iggy.pyi` equals the `stub_gen` output
   
   Not run locally: `test_tls.py`, which needs the `iggy-server:local` image.
   One full run had a timeout in 
`test_producer.py::...::test_background_write_reconnects_after_server_restart`
   (`Restartable Iggy server did not publish its TCP address`, a 15 second wait 
on a debug build).
   The test passed alone and in a second full run.
   
   ## Questions
   
   i. Do you want one call per transport in `test_http_config.py`, 
`test_quic_config.py` and `test_websocket_config.py`?
   The Rust SDK wires `get_cluster_metadata` for TCP, QUIC, HTTP and WebSocket, 
and the Python client uses the same wrapper.
   The tests here use TCP only.
   
   ii. Is there a supported way to start a cluster-enabled server for pytest?
   The Python suite runs against one server without clustering.
   If not, I will leave multi-node cases to `core/integration/tests/cluster`.
   
   iii. Do you want `test_get_cluster_metadata_needs_no_permission` kept?
   It pins that any logged-in user can call this.
   If the server later adds a permission check, the test must change.
   
   iv. Do you want the name `ip` kept in Python? (optional)
   It matches Rust, Java, Go and C#, but it can hold a host name.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to