Skip to content

fix: API deprecation headers, OTel sampling, email queue drain, and pool metrics (#680 #681 #682 #683) - #830

Merged
hman38705 merged 4 commits into
solutions-plug:mainfrom
Grace-CODE-D:main
May 30, 2026
Merged

fix: API deprecation headers, OTel sampling, email queue drain, and pool metrics (#680 #681 #682 #683)#830
hman38705 merged 4 commits into
solutions-plug:mainfrom
Grace-CODE-D:main

Conversation

@Grace-CODE-D

Copy link
Copy Markdown
Contributor

Summary

Resolves four independent backend issues across observability, reliability, and API contracts.


Changes

fix(#683) — RFC 8594 Deprecation / Sunset headers (versioning.rs, API_SPEC.md)

  • Fixed Deprecation: falseDeprecation: true (RFC 8594 boolean signals deprecation).
  • Added DEPRECATED_VERSIONS constant (["v1"]) to track which versions are deprecated.
  • Added tracing::warn! in versioning_middleware when a deprecated version is detected in the request header.
  • Added tracing::warn! in v1_deprecation_middleware on every response so server-side monitoring can track client migration progress.
  • Created services/api/API_SPEC.md documenting the deprecation policy, sunset date (2026-04-25), version selection, and migration guide.

fix(#681) — OTel sampling env vars with 10 % production default (tracing_config.rs, TRACING.md)

  • Added pub fn sample_rate_from_env(default_rate: f64) -> f64 that reads OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG per the OpenTelemetry SDK environment variable specification.
  • init_tracing now calls sample_rate_from_env at the top; OTel standard env vars take precedence over the legacy TRACE_SAMPLE_RATE config value.
  • Default production sampling rate is 10 % (traceidratio at 0.1) when neither env var is set.
  • Supports always_on, always_off, traceidratio, parentbased_always_on, parentbased_always_off, parentbased_traceidratio.
  • Updated TRACING.md to document all sampler options, the 10 % default, and updated all examples to use the OTel standard vars.

fix(#682) — Email queue drain with dedicated configurable timeout (shutdown.rs, main.rs)

  • Added pub fn email_queue_drain_timeout() -> Duration to shutdown.rs reading EMAIL_QUEUE_DRAIN_TIMEOUT_SECS (default 60 s — more generous than the 30 s global timeout because losing in-flight emails is more costly than delaying exit).
  • Gave the email queue worker its own ShutdownCoordinator::new(1) in main.rs, separate from the blockchain workers coordinator.
  • Shutdown sequence now: (1) drain email queue with EMAIL_QUEUE_DRAIN_TIMEOUT_SECS, then (2) drain blockchain workers with SHUTDOWN_TIMEOUT_SECS. Both timeouts are independently configurable via env var.

fix(#680) — SQLx pool utilisation metrics (metrics.rs, grafana-dashboard.json)

  • Added db_pool_connections_active (IntGaugeVec) — connections currently checked out.
  • Added db_pool_connections_idle (IntGaugeVec) — connections sitting idle in the pool.
  • Added db_pool_acquire_duration_seconds (HistogramVec) — time spent waiting to acquire a connection; buckets from 0.1 ms to 1 s.
  • Added observe_pool_connections(pool, active, idle) and observe_pool_acquire(pool, duration) methods.
  • Updated Grafana dashboard panel 7 to reference the real metric names (db_pool_connections_active / db_pool_connections_idle).
  • Added Grafana panel 10 showing p50 / p95 pool acquire duration with a 100 ms alert threshold.

Closes

Closes #683
Closes #681
Closes #682
Closes #680

Grace-CODE-D and others added 4 commits May 30, 2026 13:16
…server-side warnings for deprecated API versions

- Fix Deprecation header value from false to true (RFC 8594 boolean)
- Add tracing::warn! in v1_deprecation_middleware for every deprecated call
- Add tracing::warn! in versioning_middleware when a deprecated version is detected
- Add DEPRECATED_VERSIONS constant to track which versions are deprecated
- Document deprecation schedule and policy in API_SPEC.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…LER_ARG env vars with 10% production default

- Add sample_rate_from_env() that reads the OTel standard env vars and falls back to
  the passed-in rate (which itself defaults from TRACE_SAMPLE_RATE / 0.1)
- Call sample_rate_from_env() at the top of init_tracing so env vars take precedence
- Update TRACING.md to document OTEL_TRACES_SAMPLER / OTEL_TRACES_SAMPLER_ARG,
  clarify 10% as the production default, and update all sampling examples

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ed configurable timeout

- Add email_queue_drain_timeout() to shutdown.rs reading EMAIL_QUEUE_DRAIN_TIMEOUT_SECS
  (defaults to 60 s — more generous than the global 30 s to avoid losing in-flight emails)
- Give the email queue worker its own ShutdownCoordinator so its drain timeout is
  independent of the global background-worker shutdown timeout
- In main.rs shutdown sequence: drain email first, then drain blockchain workers,
  so in-flight email jobs have the best chance to complete before process exit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…dle connections, acquire duration)

- Add db_pool_connections_active and db_pool_connections_idle IntGaugeVec metrics
- Add db_pool_acquire_duration_seconds HistogramVec metric with fine-grained buckets
- Add observe_pool_connections() and observe_pool_acquire() methods to Metrics
- Update Grafana dashboard panel 7 to use the new pool metric names (active vs idle)
- Add new Grafana panel 10 for p50/p95 pool acquire duration with a 100ms alert threshold

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented May 30, 2026

Copy link
Copy Markdown

@Grace-CODE-D Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

hman38705 added a commit that referenced this pull request May 30, 2026
…pool metrics from PRs #829 and #830

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@hman38705
hman38705 merged commit cd806a7 into solutions-plug:main May 30, 2026
12 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants