apache / apache/cassandra-gocql-driver

CASSGO-39 Add query attempt interceptor

Open
#1,786 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.7k
Forks
658
PR merge metrics
No merged PRs in 30d

Description

There are use-cases for wrapping the executions of individual query attempts.

We currently have QueryObserver and BatchObserver that allow observing the query attempts, but don't allow modification of behavior.

One use case that requires modification of behavior is a request rate limiter (#1756) or a semaphore to limit request concurrency.

It seems that instead of adding an individual interface for each use case, a single interceptor-like interface could serve all of them.

The following `QueryAttemptInterceptor` could be used to implement the rate limiter, however we will need to make changes the interface to be able to replace the `QueryObserver` and `BatchObserver`:

```
type QueryAttemptInterceptor interface {
// AttemptQuery executes the query on the given connection.
// The attempt function does the actual work, the AttempQuery implementation is free to execute code
// before/after the call to the attempt function or skip the call altogether.
// If error is nil, the returned *Iter must be non-nil.
AttemptQuery(ctx context.Context, query ExecutableQuery, conn *Conn, attempt func(ctx context, query ExecutableQuery, conn *Conn) *Iter) (*Iter, error))
}
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the existing QueryObserver and BatchObserver handling and the individual query-attempt execution path. Compare those paths with the proposed QueryAttemptInterceptor contract and determine how both observers would be replaced. Done means the interceptor design and integration support wrapping, skipping, or modifying query attempts, including the stated rate-limiter and concurrency use cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.