Skip to content

feat(python): expose get_stats on IggyClient - #4018

Open
7487 wants to merge 1 commit into
apache:masterfrom
7487:python-sdk-get-stats
Open

feat(python): expose get_stats on IggyClient#4018
7487 wants to merge 1 commit into
apache:masterfrom
7487:python-sdk-get-stats

Conversation

@7487

@7487 7487 commented Sep 1, 2026

Copy link
Copy Markdown

Which issue does this PR address?

Closes #4016

Rationale

get_stats is the server's headline diagnostic call and is exposed by every other SDK; the Python SDK could not reach it.

What changed?

The Python SDK had no binding for get_stats, so server counts, host/version details and cache metrics were unreachable from Python.

A new foreign/python/src/stats.rs wraps Stats, CacheMetrics and CacheMetricsKey following the user.rs pattern. CacheMetricsKey is frozen with __eq__/__hash__, so Stats.cache_metrics converts to dict[CacheMetricsKey, CacheMetrics]. IggyClient.get_stats returns an awaitable resolving to Stats; byte sizes are exposed as integer bytes and times as microseconds, matching the existing getters. Stubs were regenerated with cargo run --bin stub_gen (purely additive diff after ruff).

tests/test_stats.py creates a stream/topic, sends messages, and asserts the stream/topic/partition/message counts moved, the version string is non-empty, and the cache-metrics dict round-trips through key lookup.

Local Execution

  • Passed
  • Pre-commit hooks ran

Ran against a locally built iggy-server from this branch: pytest tests/ gives 323 passed (only test_tls errors locally for lack of a Docker daemon, unrelated). cargo fmt, cargo clippy --all-features --all-targets, ruff check/format and pyrefly are clean.

AI Usage

  1. Claude Code (Fable 5).
  2. Entire implementation and tests, following the pattern proposed in the issue.
  3. Built the extension and ran the new and full Python test suites against a locally built server; regenerated and diffed the stubs; ran clippy/fmt/ruff/pyrefly.
  4. Yes.

The Python SDK had no way to reach the server's headline diagnostic
call, exposed by every other SDK.

Wrap Stats, CacheMetrics and CacheMetricsKey in a new stats module
following the user.rs pattern. CacheMetricsKey is frozen, hashable and
comparable so cache_metrics maps to dict[CacheMetricsKey, CacheMetrics].
Byte sizes are exposed as integer bytes, times as microseconds,
matching the existing getters.

Closes apache#4016
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Thanks for the PR. It is labeled S-waiting-on-review and queued for review.

Slash commands (own line, regular comment) move it around the queue:

  • /ready - back to S-waiting-on-review after addressing feedback
  • /author - flip to S-waiting-on-author while you finish changes
  • /request-review @user-or-team - request a reviewer

See CONTRIBUTING.md for details.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.75000% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.97%. Comparing base (328b289) to head (fe8d21d).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
foreign/python/src/stats.rs 37.39% 72 Missing ⚠️

❌ Your patch check has failed because the patch coverage (43.75%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #4018      +/-   ##
============================================
- Coverage     85.00%   84.97%   -0.03%     
  Complexity     1402     1402              
============================================
  Files          1225     1226       +1     
  Lines        180283   180411     +128     
  Branches     146587   146587              
============================================
+ Hits         153248   153304      +56     
- Misses        22993    23065      +72     
  Partials       4042     4042              
Components Coverage Δ
Rust Core 85.90% <ø> (ø)
Java SDK 67.29% <ø> (ø)
C# SDK 75.37% <ø> (ø)
Python SDK 87.63% <43.75%> (-2.44%) ⬇️
PHP SDK 85.65% <ø> (ø)
Node SDK 96.24% <ø> (ø)
Go SDK 69.31% <ø> (ø)
Files with missing lines Coverage Δ
foreign/python/src/client.rs 99.85% <100.00%> (+<0.01%) ⬆️
foreign/python/src/lib.rs 100.00% <100.00%> (ø)
foreign/python/src/stats.rs 37.39% <37.39%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review PR is waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK: expose get_stats

1 participant