Documentation
¶
Overview ¶
Package apidiag records bounded, content-free API timeout diagnostics.
Index ¶
- func Begin(ctx context.Context, stage Stage) func()
- func IsContextFailure(ctx context.Context, err error) bool
- func IsTimeout(err error) bool
- func MethodName(method string) string
- func RecordError(ctx context.Context, err error)
- type DatabaseProvider
- type DatabaseSnapshot
- type DeadlineKind
- type Pool
- type Recorder
- type Report
- type Snapshot
- type Stage
- type State
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Begin ¶
Begin returns an idempotent stage completion function. Excess concurrent stages are ignored rather than allowing unbounded diagnostic state.
func IsContextFailure ¶
IsContextFailure identifies errors that belong in request diagnostics, not a second unstructured error event. Cancellation remains distinct from timeout.
func MethodName ¶
func RecordError ¶
RecordError reports nested operation deadlines as well as request deadlines. It never copies the error text, which may contain private request contents.
Types ¶
type DatabaseProvider ¶
type DatabaseProvider interface {
APIDiagnostics() DatabaseSnapshot
}
DatabaseProvider is optional; existing database interfaces remain unchanged. Implementations must not query SQL, inspect files, or wait for application locks.
type DatabaseSnapshot ¶
type DeadlineKind ¶
type DeadlineKind uint8
const ( RequestDeadline DeadlineKind = iota OperationDeadline )
func (DeadlineKind) String ¶
func (k DeadlineKind) String() string
type Pool ¶
type Pool struct {
WaitDuration time.Duration
WaitCount int64
Max int
Open int
InUse int
Idle int
Available bool
}
Pool contains process-wide counters, not attribution to an individual request.
func PoolSnapshot ¶
PoolSnapshot reads in-memory database/sql counters, never a connection/query.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is scoped to one request. Timings of nested stages are inclusive, so their sum is not the request's elapsed time.
func FromContext ¶
func New ¶
func New(ctx context.Context, method string, transport Transport, queueWait time.Duration, snapshot func() Snapshot, emit func(Report), clock clockwork.Clock, ) (context.Context, *Recorder)
New starts diagnostics without changing the context's deadline or cancellation. Snapshot and emit run outside the recorder lock and must be safe concurrently.
func (*Recorder) Finish ¶
func (r *Recorder) Finish()
Finish detaches the deadline callback after the complete response lifecycle. A deadline racing completion is reported once, never lost or duplicated.
func (*Recorder) Report ¶
func (r *Recorder) Report(kind DeadlineKind)
type Snapshot ¶
type Snapshot struct {
MediaDB DatabaseSnapshot
UserDB DatabaseSnapshot
Scraping State
MediaPlaying State
Recovery State
}
type Stage ¶
type Stage uint8
Stage identifies code-owned phases, never request-supplied operation names.