Fail open when the write buffer cap check cannot reach Redis

What does this MR do and why?

With analytics_write_buffer_protection enabled (global on production since 2026-11-12 09:51 UTC), every write buffer add runs an LLEN before its RPUSH to enforce the 500,000-row cap. That length check had no rescue, so a Redis error on the extra round trip raised out of the tracking call and the event was lost before the push was ever attempted. Two such errors were reported right after the flip, one from the usage-data tracking API and one from the Duo workflow status worker, both failing in the redis-client connection handshake.

The cap is a guard against unbounded growth, not a gate on writes. This MR rescues Redis errors in the cap check of both buffers, tracks the exception, and admits the rows. The push still raises on its own if Redis is really unreachable, which is exactly the behavior the add path had before the cap.

  • Analytics::DatabaseWriteBuffer#drop_rows_past_cap returns the rows unchanged on a Redis error.
  • ClickHouse::WriteBuffer.add treats a failed length check as "not past the cap".

References

Screenshots or screen recordings

Not applicable, backend only.

How to set up and validate locally

  1. In a Rails console enable the flag: Feature.enable(:analytics_write_buffer_protection).

  2. Make the length check fail and add a row; the row must still land in Redis and the error must be tracked:

    buffer = Analytics::DatabaseWriteBuffer.new(buffer_key: 'demo')
    allow_redis_failure = ->(*) { raise Redis::CannotConnectError, 'boom' }
    buffer.define_singleton_method(:pending, &allow_redis_failure)
    buffer.add({ n: 1 })
    Gitlab::Redis::SharedState.with { |r| r.llen('demo_db_write_buffer') } # => 1
  3. The same holds for ClickHouse::WriteBuffer.add('ai_usage_events', { n: 1 }) when ClickHouse::WriteBuffer.pending raises.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading
Loading