Documentation
¶
Index ¶
- Constants
- func KVOrphanedRecords() int64
- type Action
- type AuthorizeFunc
- type ContextProvider
- type EventRecords
- type KVResolver
- type KVStore
- func (s *KVStore) Begin(ctx context.Context, rec query.SessionRecord) error
- func (s *KVStore) Delete(ctx context.Context, id string) error
- func (s *KVStore) Get(ctx context.Context, id string) (query.SessionRecord, bool, error)
- func (s *KVStore) Lineage(ctx context.Context, ids []string) (map[string][]string, error)
- func (s *KVStore) List(ctx context.Context, filter query.SessionFilter) (query.SessionPage, error)
- func (s *KVStore) Update(ctx context.Context, id string, status query.SessionStatus) error
- type KVStoreOptions
- type Options
- type ProfileStoreProvider
- type Runner
- type RunnerOptions
- type Service
- type SessionEventLog
- type Store
- func (s *Store) Append(_ context.Context, e query.Event) error
- func (s *Store) Begin(ctx context.Context, rec query.SessionRecord) error
- func (s *Store) BindResolver(resolve func(id string) (*query.Session, bool))
- func (s *Store) Close() error
- func (s *Store) CloseSession(_ context.Context, id string) error
- func (s *Store) Events(ctx context.Context, id string) ([]query.Event, error)
- func (s *Store) Flush() error
- func (s *Store) Get(ctx context.Context, id string) (query.SessionRecord, bool, error)
- func (s *Store) HasEvents(ctx context.Context, id string) (bool, error)
- func (s *Store) Lineage(ctx context.Context, ids []string) (map[string][]string, error)
- func (s *Store) List(ctx context.Context, filter query.SessionFilter) (query.SessionPage, error)
- func (s *Store) Prune(ctx context.Context) error
- func (s *Store) Update(ctx context.Context, id string, status query.SessionStatus) error
- type TopOptions
- type TraceOptions
Constants ¶
const DefaultSessionTTL = 30 * 24 * time.Hour
DefaultSessionTTL is how long a kv session record lives from its start.
Variables ¶
This section is empty.
Functions ¶
func KVOrphanedRecords ¶ added in v0.1.38
func KVOrphanedRecords() int64
KVOrphanedRecords counts the start records any KVStore in this process found without their status — evicted under maxmemory, say — and removed, with their index entries, rather than failing every list that reached them.
Types ¶
type Action ¶ added in v0.1.38
type Action string
Action is what a caller does with a session: read it, or control it.
type AuthorizeFunc ¶ added in v0.1.38
AuthorizeFunc decides whether r may perform action on a session of profile. A non-nil error refuses. On a route naming a session id, a caller who may not read the session is answered 404 exactly as for a session that does not exist; a caller who may read it but not control it gets 403 with the error. Where the caller named the profile itself, a refusal is 403 with the error.
type ContextProvider ¶
type EventRecords ¶ added in v0.1.38
type EventRecords interface {
Meta(ctx context.Context, stream string) (recordstore.Meta, error)
Scan(ctx context.Context, stream string, afterSeq int64, fn func(seq int64, row recordstore.Row) error) error
Tail(ctx context.Context, stream string, afterSeq int64, fn func(seq int64, row recordstore.Row) error) error
}
EventRecords reads the record streams a session's status.events names: recordstore.Notifier is one.
type KVResolver ¶ added in v0.1.38
KVResolver names the cache a request's session records live in and the key prefix that isolates its environment (e.g. "oipa.lab:").
type KVStore ¶ added in v0.1.38
type KVStore struct {
// contains filtered or unexported fields
}
KVStore is a query.SessionStore over a clicky cache.Store:
<prefix>sessions:v1:<id>:start immutable SessionStart JSON <prefix>sessions:v1:<id>:status SessionStatus JSON, expiry pinned to start <prefix>sessions:v1:index ZSET id → startedAt (unix ms)
func NewKVStore ¶ added in v0.1.38
func NewKVStore(resolve KVResolver, options KVStoreOptions) (*KVStore, error)
NewKVStore stores records in the cache resolve names for each call; the cache is shared with every process using it.
func NewMemoryKVStore ¶ added in v0.1.38
func NewMemoryKVStore(options KVStoreOptions) (*KVStore, error)
NewMemoryKVStore stores records in this process's memory for its lifetime.
func (*KVStore) Delete ¶ added in v0.1.38
Delete removes a persisted session's start, status, and list index entry.
func (*KVStore) Lineage ¶ added in v0.1.38
Lineage reads only the records that could name ids: those started no earlier than the earliest of them, since a restart always starts after what it restarts.
func (*KVStore) List ¶ added in v0.1.38
func (s *KVStore) List(ctx context.Context, filter query.SessionFilter) (query.SessionPage, error)
List reads every record in the filter's startedAt window (bounded by the ttl), dropping index entries whose start expired, then filters in Go.
type KVStoreOptions ¶ added in v0.1.38
type KVStoreOptions struct {
// TTL is how long a record lives from its StartedAt; zero is
// DefaultSessionTTL.
TTL time.Duration
}
KVStoreOptions configures a KVStore.
type Options ¶
type Options struct {
Profiles ProfileStoreProvider
Context ContextProvider
Registry *query.SessionRegistry
// Store answers for sessions that are not live in the registry: the list,
// info, lineage, and the records restart and replay start from. Nil lists
// only the registry's sessions.
Store query.SessionStore
// EventLog replays the events of a stream session that recorded no
// status.events, after it left the registry.
EventLog SessionEventLog
// Records replays a session's status.events after its owner process is
// gone, and follows it while this process still writes it.
Records EventRecords
// Authorize decides whether r may read or control a session of the named
// profile. It is asked before a session starts, stops, extends or restarts
// (ActionControl) and before a session's info, events or result is served
// (ActionRead): routes that name no profile, so a gate on profile paths
// alone cannot cover them. A session the caller may not read is answered
// 404, as a missing one is, so its id never confirms it exists; any other
// refusal is answered 403 with its error. The list, its totals, its
// lookups and restartedAs leave out refused profiles. Nil allows
// every caller everything, which is right only when every profile served
// has the same permission. A connection trace session is named by its
// virtual profile, connection-<id>-sql-xevent.
Authorize AuthorizeFunc
// Principal names the caller of r, for a stop reason and the principal of
// a restarted session. Nil stops "via API" and restarts as the previous
// principal.
Principal func(r *http.Request) string
}
type ProfileStoreProvider ¶
type ProfileStoreProvider func() (profilestore.Store, error)
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func NewRunner ¶
func NewRunner(options RunnerOptions) (*Runner, error)
type RunnerOptions ¶
type RunnerOptions struct {
Profiles ProfileStoreProvider
Context ContextProvider
Stdout io.Writer
Stderr io.Writer
// BeforeExecute, when set, prepares a CLI session's data as it starts and
// before every later sample — the hook the profile service runs, so a
// session reads what a one-off run of the profile would.
BeforeExecute profilestore.BeforeExecuteFunc
}
type SessionEventLog ¶ added in v0.1.38
type SessionEventLog interface {
Events(ctx context.Context, id string) ([]query.Event, error)
// HasEvents reports whether the log holds any event of session id, which
// is what a session's eventsAvailable says without reading them all.
HasEvents(ctx context.Context, id string) (bool, error)
}
SessionEventLog holds the events a capture stream session emitted through the registry's EventSink, for replay after the session left the registry.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the database-backed query.SessionStore and query.EventSink of the query server: session records in the sessions table, and the events of capture stream sessions batch-written to session_events, which is what a session's events are replayed from after it left the registry.
func (*Store) Append ¶ added in v0.1.38
Append buffers the event, flushing synchronously once a full batch has accumulated. It returns the failure of an earlier background flush of the session, so the session emitting it fails.
func (*Store) BindResolver ¶
BindResolver wires the live-session lookup used to fail sessions whose events cannot be persisted by the background flusher.
func (*Store) CloseSession ¶ added in v0.1.41
CloseSession writes whatever the session still has buffered, along with any failure the background flusher recorded for it while it had no live handle. The registry calls it as the session ends, before its terminal status is written, so the record a reader finds is never ahead of the events table.
func (*Store) Flush ¶
Flush writes all buffered events, joining any errors (including flush failures recorded for sessions with no live handle).
func (*Store) HasEvents ¶ added in v0.1.38
HasEvents reports whether any event of session id is buffered or persisted.
func (*Store) List ¶
func (s *Store) List(ctx context.Context, filter query.SessionFilter) (query.SessionPage, error)
List filters the scalar fields and the window in SQL, and authorizes by narrowing to the allowed profiles among those that match. Without a label filter SQL also counts, sorts and pages; labels live in the start JSON, so with one the matches are paged in Go.