Skip to content

feat: expose stub_status connection-state atomics via event::connecti…#290

Open
u5surf wants to merge 1 commit into
nginx:mainfrom
u5surf:feat/expose-ngx-stat-stub
Open

feat: expose stub_status connection-state atomics via event::connecti…#290
u5surf wants to merge 1 commit into
nginx:mainfrom
u5surf:feat/expose-ngx-stat-stub

Conversation

@u5surf

@u5surf u5surf commented May 24, 2026

Copy link
Copy Markdown

…on_stats

Proposed changes

Describe the use case and detail of the change. If this PR addresses an issue
on GitHub, make sure to include a link to that issue here in this description
(not in the title of the PR).

We would like to pure rust nginx status module, so we’d like to have a safe accessor for the seven ngx_stat_* globals nginx populates when built with --with-http_stub_status_module.

We can already emits the raw externs once that build flag is set, but we currently have to read them by hand with several unsafe casts; the new event::connection_stats() function returns a ConnectionStats snapshot in one call.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have written my commit messages in the Conventional Commits format.
  • I have read the CONTRIBUTING doc
  • I have added tests (when possible) that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

…on_stats

Add a safe accessor for the seven `ngx_stat_*` globals nginx populates
when built with `--with-http_stub_status_module`.  Bindgen already
emits the raw externs once that build flag is set, but consumers
currently have to read them by hand with several `unsafe` casts; the
new `event::connection_stats()` function returns a `ConnectionStats`
snapshot in one call.

Gated behind `#[cfg(ngx_feature = "stat_stub")]` so nginx builds
without stub_status still link cleanly.

Signed-off-by: Y.Horie <u5.horie@gmail.com>
@u5surf
u5surf force-pushed the feat/expose-ngx-stat-stub branch from 5f74c2c to 39e7100 Compare May 24, 2026 22:56

@avahahn avahahn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but I think just a few alterations are in order.

Comment thread src/event.rs
@@ -0,0 +1,161 @@
//! Helpers around nginx's event-loop globals.

#[cfg(ngx_feature = "stat_stub")]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this needs a feature gate, but ill defer to @bavshin-f5 or @ensh63 if either of them agree with having it.

Comment thread src/event.rs
pub use connection_stats::{ConnectionStats, connection_stats};

#[cfg(ngx_feature = "stat_stub")]
mod connection_stats {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add more features to this src/event.rs file (which we very well may in the future) then having many features as nested mod blocks will mean that the tests will be interleaved through the code as well as many more use statements that could be de-duplicated and in one place. I think that will make it harder to read through and navigate the code. Lets not bother with the mod here even though we have used them elsewhere in this project.

Comment thread src/event.rs
}

#[test]
#[allow(clippy::unnecessary_cast)] // `ngx_atomic_t::MAX as u64` is a no-op on 64-bit targets.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will require hardware that has a non 64 bit addressing bus in order to actually test anything.
Its not impossible to do in github CI but it is a bunch of work and isnt implemented here. Also this doesn't test any logic that NGINX or ngx-rust implements.

Lets just pull that test out for now?

Comment thread src/event.rs
use super::*;

#[test]
fn default_is_all_zero() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since default is derived on this type your test is only testing the logic of the Default trait derive macro. I don't see us ever choosing to implement an alternative default so I think there is no need for this test.

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.

2 participants