Skip to content

Commit 53c78cd

Browse files
author
Elrond
committed
Merge refreshed operator cron base into owner preparation
Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
2 parents b689026 + 464a4e6 commit 53c78cd

14 files changed

Lines changed: 2401 additions & 814 deletions

File tree

‎.github/workflows/_ci-relay.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ jobs:
198198
with:
199199
name: desktop-e2e-relay
200200
path: target/ci
201+
- name: Restore relay executable permission
202+
run: chmod +x ./target/ci/buzz-relay
201203
- name: PostgreSQL-backed tests
202204
env:
203205
BUZZ_POSTGRES_ADMIN_URL: postgres://buzz:${{ env.BUZZ_TEST_POSTGRES_PASSWORD }}@localhost:5432/postgres

‎ARCHITECTURE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ pub enum AuthState { Pending { challenge: String }, Authenticated(AuthContext),
693693
| GET | `/.well-known/nostr.json` | NIP-05 identity |
694694
| GET | `/health` | Health check |
695695
| GET | `/_liveness` | Liveness probe |
696-
| GET | `/_readiness` | Readiness probe |
696+
| GET | `/_readiness` | Readiness probe — local process lifecycle only |
697697
| POST | `/events` | Submit a signed Nostr event over HTTP (same ingest path as WebSocket `EVENT`) |
698698
| POST | `/query` | Query Nostr events over HTTP with NIP-01 filters |
699699
| POST | `/count` | Count Nostr events over HTTP with NIP-45 filters |

‎Justfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ test-unit:
472472
# because they live in the binary target; the nested
473473
# `tests::postgres_tests::` stays in the PostgreSQL lane.
474474
cargo nextest run -p buzz-relay --lib --bin buzz-relay \
475-
-E 'test(/^api::admin::/) + test(/^handlers::channel_authz::/) + test(/^handlers::moderation_authz::/) + test(/^handlers::side_effects::tests::/) + test(/^storage_sweep::tests::/) + test(/^nip_fi_http::tests::/) + test(/^nip_fi_config::tests::/) + test(/^router::tests::/) + test(/^api::parse_query_tests::/) + test(/^api::git::transport::off_mode_precedence_tests::/) + (kind(bin) & (test(/^tests::/) + test(/^composition_tests::/)) - test(/^tests::postgres_tests::/))'
475+
-E 'test(/^api::admin::/) + test(/^handlers::channel_authz::/) + test(/^handlers::moderation_authz::/) + test(/^handlers::side_effects::tests::/) + test(/^storage_sweep::tests::/) + test(/^nip_fi_http::tests::/) + test(/^nip_fi_config::tests::/) + test(/^readiness::tests::/) + test(/^router::tests::/) + test(/^api::parse_query_tests::/) + test(/^api::git::transport::off_mode_precedence_tests::/) + test(=state::tests::neither_a_confirmed_inactive_community_nor_a_failed_lookup_admits_the_socket) + (kind(bin) & (test(/^tests::/) + test(/^composition_tests::/)) - test(/^tests::postgres_tests::/))'
476476
# ACP author-gate and queue tests protect the trust boundary between
477477
# relay events and agent prompts. They are infra-free; ignored lifecycle
478478
# tests remain excluded and run in their dedicated integration lanes.

‎crates/buzz-relay/src/lib.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub mod operator_listener;
4545
pub mod protocol;
4646
/// Durable NIP-PL matcher and delivery worker.
4747
pub mod push_runtime;
48-
mod readiness;
48+
/// Readiness-probe telemetry and the per-pod dependency sampler behind `/_status`.
49+
pub mod readiness;
4950
/// Axum router construction.
5051
pub mod router;
5152
/// Shared application state.

‎crates/buzz-relay/src/main.rs‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ async fn run_relay_main(boot: BootTracker) -> anyhow::Result<()> {
227227

228228
let usage_interval_secs = usage_metrics_interval_secs();
229229
let usage_idle_timeout_secs = usage_metrics_idle_timeout_secs(usage_interval_secs);
230+
let dependency_sample_completion_republish_interval =
231+
buzz_relay::readiness::dependency_sample_completion_republish_interval(
232+
usage_idle_timeout_secs,
233+
);
230234
let (boot, ()) = boot.run_required(
231235
StartupPhase::MetricsBind,
232236
|| relay_metrics::try_install(config.metrics_port, usage_idle_timeout_secs),
@@ -244,6 +248,7 @@ async fn run_relay_main(boot: BootTracker) -> anyhow::Result<()> {
244248
info!(
245249
port = config.metrics_port,
246250
idle_timeout_secs = usage_idle_timeout_secs,
251+
completion_republish_secs = dependency_sample_completion_republish_interval.as_secs(),
247252
"Prometheus metrics exporter started"
248253
);
249254

@@ -455,7 +460,13 @@ async fn run_relay_main(boot: BootTracker) -> anyhow::Result<()> {
455460
cfg.create_pool(Some(deadpool_redis::Runtime::Tokio1))
456461
.map_err(|e| anyhow::anyhow!("Redis pool creation failed: {e}"))?
457462
};
458-
let redis_health_pool = redis_pool.clone(); // cheap Arc clone — shared with readiness handler
463+
let redis_health_pool = redis_pool.clone(); // cheap Arc clone — shared with AppState
464+
// One-time bootstrap gate, deliberately before AppState and therefore before
465+
// the health listener binds. Post-start Redis failures are dependency
466+
// failures and must never move readiness; never having connected at all is
467+
// a broken deployment, not a blip.
468+
buzz_relay::state::verify_redis_command_path(&redis_health_pool).await?;
469+
info!("Redis command path connected");
459470
let pubsub = Arc::new(
460471
PubSubManager::new(&config.redis_url, redis_pool)
461472
.await
@@ -1100,6 +1111,16 @@ async fn run_relay_main(boot: BootTracker) -> anyhow::Result<()> {
11001111
));
11011112
}
11021113

1114+
// Per-pod dependency diagnostics runtime: one seam starts the dependency
1115+
// sampler and its independent completion-epoch republisher together.
1116+
{
1117+
let diagnostics_state = Arc::clone(&state);
1118+
buzz_relay::readiness::start_dependency_sampler_and_completion_publisher(
1119+
diagnostics_state,
1120+
dependency_sample_completion_republish_interval,
1121+
);
1122+
}
1123+
11031124
// Cross-pod connection-control consumer: receive disconnect commands from
11041125
// Redis pub/sub (published by the pod that recorded a ban) and close any
11051126
// matching local sockets. A member's live connections may land on any pod,
@@ -1273,6 +1294,8 @@ async fn run_relay_main(boot: BootTracker) -> anyhow::Result<()> {
12731294

12741295
serve(router, health_router, Arc::clone(&state)).await?;
12751296
state.community_revalidator_cancel.cancel();
1297+
state.dependency_sampler_cancel.cancel();
1298+
state.dependency_completion_publisher_cancel.cancel();
12761299

12771300
// Signal the audit worker to stop accepting, flush buffered entries, and
12781301
// exit. Uses a CancellationToken so it works regardless of how many

‎crates/buzz-relay/src/metrics.rs‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ pub fn try_install(port: u16, gauge_idle_timeout_secs: u64) -> Result<(), Metric
290290
metrics::set_global_recorder(recorder)
291291
.map_err(|_error| MetricsInstallError::RecorderConflict)?;
292292
describe_readiness_metrics();
293+
describe_community_admission_metrics();
293294
describe_db_pool_metrics();
294295
describe_auth_metrics();
295296
initialize_auth_metric_series();
@@ -306,24 +307,42 @@ pub fn install(port: u16, gauge_idle_timeout_secs: u64) {
306307
.unwrap_or_else(|error| panic!("metrics exporter must install exactly once: {error}"));
307308
}
308309

309-
/// Register the frozen readiness metric descriptions with the active recorder.
310+
/// Register the frozen readiness and dependency-diagnostic metric descriptions.
311+
///
312+
/// The two `buzz_readiness_*` probe families describe local process lifecycle.
313+
/// The dependency families keep their names for dashboard continuity but are
314+
/// published by the per-pod dependency sampler, not by the Kubernetes probe or
315+
/// by an `/_status` request — a shared-dependency failure no longer deroutes
316+
/// the pod, and nobody has to read the endpoint for the metrics to move.
310317
pub(crate) fn describe_readiness_metrics() {
311318
metrics::describe_counter!(
312319
"buzz_readiness_checks_total",
313-
"Kubernetes health-listener readiness probes by terminal bounded reason"
320+
"Kubernetes health-listener readiness probes by lifecycle reason (ready, shutting_down)"
314321
);
315322
metrics::describe_counter!(
316323
"buzz_readiness_dependency_checks_total",
317-
"Completed readiness dependency attempts by dependency and bounded outcome"
324+
"Completed dependency-sampler attempts by dependency and bounded outcome"
318325
);
319326
metrics::describe_histogram!(
320327
"buzz_readiness_check_duration_seconds",
321328
metrics::Unit::Seconds,
322-
"Completed readiness check duration without outcome label multiplication"
329+
"Completed dependency-sampler check duration without outcome label multiplication"
323330
);
324331
metrics::describe_gauge!(
325332
"buzz_readiness_state",
326-
"Latest publishable readiness state by check, where 1 is ready and 0 is not ready"
333+
"Latest private readiness-probe observation, where 1 is ready and 0 is shutting down"
334+
);
335+
metrics::describe_gauge!(
336+
"buzz_readiness_dependency_sample_completed_timestamp_seconds",
337+
"Unix time the cached /_status dependency report completed, absent until the first sample completes; sampler completion advances it and the publisher re-emits it"
338+
);
339+
}
340+
341+
/// Register the bounded community-admission contract.
342+
pub(crate) fn describe_community_admission_metrics() {
343+
metrics::describe_counter!(
344+
"buzz_community_admission_checks_total",
345+
"Durable community-active checks at socket admission by bounded outcome"
327346
);
328347
}
329348

@@ -541,7 +560,17 @@ pub(crate) fn readiness_test_recorder() -> (
541560
metrics_exporter_prometheus::PrometheusRecorder,
542561
metrics_exporter_prometheus::PrometheusHandle,
543562
) {
544-
let recorder = configured_prometheus_builder(300).build_recorder();
563+
readiness_test_recorder_with_idle_timeout(300)
564+
}
565+
566+
#[cfg(test)]
567+
pub(crate) fn readiness_test_recorder_with_idle_timeout(
568+
gauge_idle_timeout_secs: u64,
569+
) -> (
570+
metrics_exporter_prometheus::PrometheusRecorder,
571+
metrics_exporter_prometheus::PrometheusHandle,
572+
) {
573+
let recorder = configured_prometheus_builder(gauge_idle_timeout_secs).build_recorder();
545574
let handle = recorder.handle();
546575
(recorder, handle)
547576
}

0 commit comments

Comments
 (0)