Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
778 changes: 364 additions & 414 deletions api-server/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ regex = "1"
base64 = "0.22"
flate2 = "1.0"
brotli = "7.0"
redis = { version = "1", features = ["r2d2"] }
redis = { version = "0.27", features = ["r2d2", "tokio-comp", "aio", "connection-manager"] }
r2d2 = "0.8"

[dev-dependencies]
Expand Down
4 changes: 1 addition & 3 deletions api-server/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ pub fn invalidate_pattern(pattern: &str) {

/// Scan for keys matching a Redis glob `pattern` and delete them.
fn redis_delete_matching(conn: &mut redis::Connection, pattern: &str) -> redis::RedisResult<()> {
let keys: Vec<String> = conn
.scan_match::<_, String>(pattern)?
.collect::<Result<Vec<String>, redis::RedisError>>()?;
let keys: Vec<String> = conn.scan_match::<_, String>(pattern)?.collect();
if !keys.is_empty() {
let _: () = conn.del(keys)?;
}
Expand Down
11 changes: 8 additions & 3 deletions api-server/src/circuit_breaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ impl CircuitBreaker {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
.as_millis() as u64;
let last_failure = self.last_failure_time.load(Ordering::SeqCst);
let timeout_ms = if self.config.timeout_secs == 0 {
5
} else {
self.config.timeout_secs * 1000
};

if now.saturating_sub(last_failure) >= self.config.timeout_secs {
if now.saturating_sub(last_failure) >= timeout_ms {
let prev = *state;
*state = CircuitState::HalfOpen;
self.half_open_calls.store(0, Ordering::SeqCst);
Expand Down Expand Up @@ -137,7 +142,7 @@ impl CircuitBreaker {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
.as_millis() as u64;
self.last_failure_time.store(now, Ordering::SeqCst);

let state = self.get_state();
Expand Down
32 changes: 17 additions & 15 deletions api-server/src/distributed_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,21 @@ pub async fn distributed_tracing_middleware(

let cx = Context::current_with_span(span.clone_as_boxed_ref());
// Attach a compatible context so tracing:: macros pick up the OTel trace-ID.
let _guard = cx.clone().attach();

// Expose trace context to downstream handlers via extensions.
req.extensions_mut().insert(trace_ctx.clone());

tracing::info!(
trace_id = %trace_ctx.trace_id,
span_id = %trace_ctx.span_id,
parent_span_id = ?trace_ctx.parent_span_id,
method = %method,
uri = %uri,
"request started"
);
{
let _guard = cx.clone().attach();

// Expose trace context to downstream handlers via extensions.
req.extensions_mut().insert(trace_ctx.clone());

tracing::info!(
trace_id = %trace_ctx.trace_id,
span_id = %trace_ctx.span_id,
parent_span_id = ?trace_ctx.parent_span_id,
method = %method,
uri = %uri,
"request started"
);
}

let mut response = next.run(req).await;
let duration = trace_ctx.start_time.elapsed();
Expand Down Expand Up @@ -314,11 +316,11 @@ pub fn get_trace_context(headers: &HeaderMap) -> DistributedTraceContext {
// ── Trait to allow span boxing without object-safety constraints ──────────────

trait SpanExt {
fn clone_as_boxed_ref(&mut self) -> opentelemetry::trace::BoxedSpan;
fn clone_as_boxed_ref(&mut self) -> opentelemetry::global::BoxedSpan;
}

impl<S: Span> SpanExt for S {
fn clone_as_boxed_ref(&mut self) -> opentelemetry::trace::BoxedSpan {
fn clone_as_boxed_ref(&mut self) -> opentelemetry::global::BoxedSpan {
// For the context guard we start a no-op placeholder; the real span
// lives in `span` and is ended explicitly above.
opentelemetry::global::tracer("atomic-patent")
Expand Down
Loading
Loading