Documentation
¶
Overview ¶
Package logs manages asynchronous log sessions, source discovery, and streaming. Accepted sessions retain context values but outlive creation RPC cancellation. Resource sessions retain their native-generation lease until producers exit.
Index ¶
- Constants
- func RegisterLogPluginServer(registrar grpc.ServiceRegistrar, server logspb.LogPluginServer)
- func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error
- type ActionTargetBuilder
- type ChannelSink
- type CreateSessionOptions
- type Handler
- type LogHandlerFunc
- type LogLevel
- type LogLine
- type LogLineOrigin
- type LogSession
- type LogSessionOptions
- type LogSessionStatus
- type LogSource
- type LogStreamCommand
- type LogStreamEvent
- type LogStreamEventType
- type LogStreamRequest
- type Manager
- func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
- func (m *Manager) Close()
- func (m *Manager) CloseSession(_ *types.PluginContext, sessionID string) error
- func (m *Manager) CreateResourceSession(pluginctx *types.PluginContext, opts CreateSessionOptions) (*LogSession, error)
- func (m *Manager) CreateSession(pluginctx *types.PluginContext, opts CreateSessionOptions) (*LogSession, error)
- func (m *Manager) GetSession(_ *types.PluginContext, sessionID string) (*LogSession, error)
- func (m *Manager) GetSupportedResources(_ *types.PluginContext) []Handler
- func (m *Manager) ListSessions(_ *types.PluginContext) ([]*LogSession, error)
- func (m *Manager) Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- func (m *Manager) UpdateSessionOptions(_ *types.PluginContext, sessionID string, opts LogSessionOptions) (*LogSession, error)
- func (m *Manager) Wait()
- type ManagerConfig
- type OutputSink
- type Plugin
- type PluginClient
- func (c *PluginClient) CloseSession(ctx *types.PluginContext, sessionID string) error
- func (c *PluginClient) CreateResourceSession(ctx *types.PluginContext, opts CreateSessionOptions) (*LogSession, error)
- func (c *PluginClient) CreateSession(ctx *types.PluginContext, opts CreateSessionOptions) (*LogSession, error)
- func (c *PluginClient) GetSession(ctx *types.PluginContext, sessionID string) (*LogSession, error)
- func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) []Handler
- func (c *PluginClient) ListSessions(ctx *types.PluginContext) ([]*LogSession, error)
- func (c *PluginClient) Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- func (c *PluginClient) UpdateSessionOptions(ctx *types.PluginContext, sessionID string, opts LogSessionOptions) (*LogSession, error)
- type PluginOpts
- type PluginServer
- func (s *PluginServer) CloseSession(ctx context.Context, in *logspb.LogSessionByIdRequest) (*logspb.CloseLogSessionResponse, error)
- func (s *PluginServer) CreateResourceSession(ctx context.Context, in *logspb.CreateLogSessionRequest) (*logspb.ResourceLogSessionResponse, error)
- func (s *PluginServer) CreateSession(ctx context.Context, in *logspb.CreateLogSessionRequest) (*logspb.CreateLogSessionResponse, error)
- func (s *PluginServer) GetSession(ctx context.Context, in *logspb.LogSessionByIdRequest) (*logspb.LogSessionByIdResponse, error)
- func (s *PluginServer) GetSupportedResources(ctx context.Context, _ *emptypb.Empty) (*logspb.GetSupportedLogResourcesResponse, error)
- func (s *PluginServer) ListSessions(ctx context.Context, _ *emptypb.Empty) (*logspb.ListLogSessionsResponse, error)
- func (s *PluginServer) Stream(stream logspb.LogPlugin_StreamServer) (streamErr error)
- func (s *PluginServer) UpdateSessionOptions(ctx context.Context, in *logspb.UpdateLogSessionOptionsRequest) (*logspb.LogSessionByIdResponse, error)
- type Provider
- type ReplayCountFunc
- type ResourceSessionProvider
- type SourceBuilderFunc
- type SourceEvent
- type SourceEventType
- type SourceResolver
- type SourceResolverOptions
- type SourceResolverResult
- type StreamInput
- type StreamOutput
Constants ¶
const ( // MaxConcurrentStreamsPerSession bounds simultaneous source readers in one session. MaxConcurrentStreamsPerSession = 20 // MaxScannerBuffer limits a single log line to one mebibyte. MaxScannerBuffer = 1024 * 1024 // ReconnectMaxAttempts bounds retries after the initial stream attempt. ReconnectMaxAttempts = 5 // ReconnectInitialDelay is the first retry's backoff. ReconnectInitialDelay = 1 * time.Second // ReconnectMaxDelay caps exponential retry backoff. ReconnectMaxDelay = 30 * time.Second )
const ( // ParamReplayMarkers is the session parameter a reader sets to [ReplayMarkersOn] // in [LogSessionOptions.Params] to ask for replay markers: the [LogLine.Replay] flag // on the lines of each source's replay, and a [StreamEventSourceCaughtUp] event when // the last of them has been delivered. Only a reader that asks is ever sent the // event: a reader whose SDK predates it decodes the event as a source joining. // // Parameter names that start with "omniview." are reserved to the SDK. ParamReplayMarkers = "omniview.log.replay-markers" // ParamReplayMarkersAccepted is how the create reply says the plugin accepted: // the key is set to [ReplayMarkersOn] in the reply's Options.Params. A plugin that // predates replay markers echoes the reader's own parameters, which never carry this key: // the SDK removes it from every create and update request it encodes, so a reader // cannot forge it, even by reusing the options of an accepted session. // [LogSession.ReplayMarkers] is this key read back. ParamReplayMarkersAccepted = "omniview.log.replay-markers.accepted" // ReplayMarkersOn is the value of both parameters. ReplayMarkersOn = "1" )
const ResourceSessionWireVersion uint32 = 2
ResourceSessionWireVersion identifies the independent canonical log-session wire.
Variables ¶
This section is empty.
Functions ¶
func RegisterLogPluginServer ¶ added in v0.9.0
func RegisterLogPluginServer(registrar grpc.ServiceRegistrar, server logspb.LogPluginServer)
RegisterLogPluginServer preserves generated lifecycle handlers while admitting resource session requests before generated decoding or provider side effects.
func RegisterPlugin ¶
func RegisterPlugin( p *sdk.Plugin, opts PluginOpts, ) error
RegisterPlugin registers the log capability with the plugin system.
Types ¶
type ActionTargetBuilder ¶
type ActionTargetBuilder struct {
Label string `json:"label"`
LabelSelector string `json:"label_selector"`
Paths []string `json:"paths"`
Selectors map[string]string `json:"selectors"`
}
ActionTargetBuilder builds a dynamic list of targets for an action.
func ActionTargetBuilderFromProto ¶
func ActionTargetBuilderFromProto(p *commonpb.ActionTargetBuilder) ActionTargetBuilder
ActionTargetBuilderFromProto converts a proto ActionTargetBuilder to the domain type.
func (ActionTargetBuilder) ToProto ¶
func (a ActionTargetBuilder) ToProto() *commonpb.ActionTargetBuilder
ToProto converts ActionTargetBuilder to its proto representation.
type ChannelSink ¶
type ChannelSink struct {
// contains filtered or unexported fields
}
ChannelSink writes StreamOutput to a channel with context-aware sends. Callers may inject it when a shared context should control delivery. If that context is canceled, sends stop blocking on a full channel.
func NewChannelSink ¶
func NewChannelSink(ctx context.Context, out chan StreamOutput) *ChannelSink
NewChannelSink creates a ChannelSink wrapping the given output channel. The context controls the lifetime — sends are dropped after cancellation.
func (*ChannelSink) OnEvent ¶
func (s *ChannelSink) OnEvent(sessionID string, event LogStreamEvent)
OnEvent sends a session event or returns when the sink context is canceled.
func (*ChannelSink) OnLine ¶
func (s *ChannelSink) OnLine(line LogLine)
OnLine sends a line or returns when the sink context is canceled.
type CreateSessionOptions ¶
type CreateSessionOptions struct {
// SessionID optionally binds resource-session acceptance to a host-generated UUID.
SessionID string `json:"session_id,omitempty"`
ResourceKey string `json:"resource_key"`
ResourceID string `json:"resource_id"`
ResourceData *resourcev2.Value `json:"resource_data"`
Reference *resourcev2.ResourceReference `json:"reference,omitempty"`
Route *resourcev2.AccessRoute `json:"route,omitempty"`
Options LogSessionOptions `json:"options"`
}
CreateSessionOptions contains everything needed to create a log session.
func CreateSessionOptionsFromProto ¶ added in v0.9.0
func CreateSessionOptionsFromProto(p *logspb.CreateLogSessionRequest) (CreateSessionOptions, error)
CreateSessionOptionsFromProto rejects unknown fields and unsupported versions before decoding canonical values. Optional reference, route, and body presence survives conversion.
func (CreateSessionOptions) HasResourceIntent ¶ added in v0.9.0
func (o CreateSessionOptions) HasResourceIntent() bool
HasResourceIntent reports whether options must use the resource-aware creation path.
func (CreateSessionOptions) ToProto ¶ added in v0.9.0
func (o CreateSessionOptions) ToProto() (*logspb.CreateLogSessionRequest, error)
ToProto validates options and bounds the encoded frame before allocating the resource body.
func (*CreateSessionOptions) UnmarshalJSON ¶ added in v0.9.0
func (o *CreateSessionOptions) UnmarshalJSON(data []byte) error
UnmarshalJSON preserves raw validation evidence and admits only exact field names.
func (CreateSessionOptions) Validate ¶ added in v0.9.0
func (o CreateSessionOptions) Validate() error
Validate checks canonical metadata and values without requiring a live connection.
type Handler ¶
type Handler struct {
Plugin string `json:"plugin"`
Resource string `json:"resource"`
TargetBuilder ActionTargetBuilder `json:"target_builder"`
// Handler opens the one stream of a source: its replay and its live lines together.
Handler LogHandlerFunc `json:"-"`
// ReplayCount, when set, lets a reader that asks for replay markers (see
// [ParamReplayMarkers]) know exactly where the source's replay ends instead of
// guessing from timing. The replay is the lines the source already held when its
// stream opened; they come first. ReplayCount is optional: a handler without it
// works as it always did, and its sessions never get replay markers.
//
// Handler is unchanged. It opens the same single stream, with the same request,
// whether or not ReplayCount is set and whether or not the reader asked: the SDK
// never splits it or filters it. (For a session that asked it opens the stream
// after ReplayCount returns, so the open is later by that call.) ReplayCount only
// says how many of the first lines of that stream are the replay. The SDK flags
// those lines ([LogLine.Replay]) and sends [StreamEventSourceCaughtUp] after the
// last one. It changes what the SDK says about the lines, never which lines it
// delivers.
//
// The SDK calls ReplayCount only for a session whose reader asked for replay
// markers, before each attempt to open a source and with the request Handler is
// about to get. A reopened source is an attempt too: its tail is delivered again
// and counted again. A request with Follow false is not asked: that stream ends,
// and its end is the boundary. Return how many lines, each ended by a newline, at
// the head of the stream Handler will open for that request were already in the
// source; zero for none. A source that can measure with a bounded read does so
// (Kubernetes: a follow=false read with the same tail, since and limit bounds,
// counting its complete lines, and nothing else: it needs none of the lines); a
// source that knows its boundary natively returns it.
//
// Count what the stream Handler will open delivers first, not what the source
// holds: a source of 50,000 lines opened with a tail of 1000 has a replay of 1000.
// Everything that limits that stream (tail, since, limit, IncludePrevious: it is
// the same request) limits the count. A count above what the stream delivers is
// the likeliest mistake and it fails silently: every line is flagged replay for
// good and the caught-up event never comes (see below).
//
// A count says how many lines come first, and the SDK flags that many, whichever
// lines they turn out to be. If the source changed between the count and the open,
// they can differ from the lines counted (the window of a tail-limited stream moves
// forward with the newest lines), but their number is the number counted. A stream
// that opens with more lines than counted (lines arrived in between and nothing
// limits the tail) has the extra ones live. One that opens with fewer (the source
// lost some in between, as a log rotation does) and then waits has its next live
// lines flagged as replay until the count is reached, and the caught-up event
// follows the counted line: a source that stays quiet holds it back, and until it
// comes the reader cannot tell the source's lines are live. None of this changes
// which lines are delivered. A count that cannot be given is an error, and a
// negative count is one: the attempt fails as a failed open does (retried, then
// reported) and no caught-up event is sent for it. Like Handler, ReplayCount is
// not bounded by the SDK: honour the context it is given. For different sources
// of one session it can run at the same time, and while it runs it holds the
// source's concurrency slot as the open does. For a session that asked, the
// caught-up event is sent whether or not the session set IncludeSourceEvents.
//
// A session for a group resource (a key with a [SourceResolver]) streams its
// resolved sources through the registered handler with the smallest key, so that
// handler's ReplayCount decides whether those sessions get replay markers.
ReplayCount ReplayCountFunc `json:"-"`
SourceBuilder SourceBuilderFunc `json:"-"`
}
Handler describes a log handler for a specific resource type.
func HandlerFromProto ¶
func HandlerFromProto(p *logspb.LogHandler) Handler
HandlerFromProto decodes handler metadata; callbacks must be registered locally.
func (Handler) ToProto ¶
func (h Handler) ToProto() *logspb.LogHandler
ToProto encodes handler metadata without its executable callbacks.
type LogHandlerFunc ¶
type LogHandlerFunc func(ctx *types.PluginContext, req LogStreamRequest) (io.ReadCloser, error)
LogHandlerFunc opens a log stream for a single source, returning an io.ReadCloser.
type LogLevel ¶
type LogLevel int
LogLevel represents the severity level of a log line.
const ( // LogLevelUnspecified indicates that no severity was assigned. LogLevelUnspecified LogLevel = iota // LogLevelTrace identifies fine-grained execution tracing. LogLevelTrace // LogLevelDebug identifies diagnostic output. LogLevelDebug // LogLevelInfo identifies routine informational output. LogLevelInfo // LogLevelWarn identifies a potential problem. LogLevelWarn // LogLevelError identifies a failed operation. LogLevelError // LogLevelFatal identifies a failure that prevents continued operation. LogLevelFatal )
func LogLevelFromProto ¶
LogLevelFromProto decodes severity, defaulting unknown values to unspecified.
type LogLine ¶
type LogLine struct {
SessionID string `json:"session_id"`
SourceID string `json:"source_id"`
Labels map[string]string `json:"labels"`
Timestamp time.Time `json:"timestamp"`
Content string `json:"content"`
Origin LogLineOrigin `json:"origin"`
// Replay is true for a line of a source's replay: one of the first lines of its
// stream, the ones the source already held when the stream opened, up to the
// source's next [StreamEventSourceCaughtUp] event. It is set only on a session
// whose plugin accepted replay markers ([LogSession.ReplayMarkers]); on any other
// it is false for every line and says nothing about whether the line is replay. It
// sits beside Origin, in the word that field leaves free, so the struct does not grow.
Replay bool `json:"replay,omitempty"`
Level LogLevel `json:"level"`
}
LogLine represents a single log line from any source.
func LogLineFromProto ¶
LogLineFromProto decodes line content, sharing Labels; an absent timestamp stays zero.
type LogLineOrigin ¶
type LogLineOrigin int32
LogLineOrigin indicates the origin of a log line. It is an int32 rather than an int so that a LogLine, which is allocated once per line, stays in the 96-byte size class it had before LogLine.Replay existed.
const ( // LogLineOriginCurrent identifies output from the current source instance. LogLineOriginCurrent LogLineOrigin = iota // LogLineOriginPrevious identifies output retained from a previous source instance. LogLineOriginPrevious // LogLineOriginSystem identifies messages generated by the log engine. LogLineOriginSystem )
func LogLineOriginFromProto ¶
func LogLineOriginFromProto(p logspb.LogLineOrigin) LogLineOrigin
LogLineOriginFromProto decodes the origin, defaulting unknown values to current.
func (LogLineOrigin) ToProto ¶
func (o LogLineOrigin) ToProto() logspb.LogLineOrigin
ToProto encodes the origin, defaulting unknown values to current.
type LogSession ¶
type LogSession struct {
ID string `json:"id"`
PluginID string `json:"plugin_id"`
ConnectionID string `json:"connection_id"`
ResourceKey string `json:"resource_key"`
ResourceID string `json:"resource_id"`
Options LogSessionOptions `json:"options"`
Status LogSessionStatus `json:"status"`
ActiveSources []LogSource `json:"active_sources"`
CreatedAt time.Time `json:"created_at"`
// ReplayMarkers is true when the plugin accepted the session's request for replay
// markers ([ParamReplayMarkers]): it flags the lines of each source's replay
// ([LogLine.Replay]) and sends [StreamEventSourceCaughtUp] when a source's replay
// is delivered. False means no caught-up event will ever come: the reader did not
// ask, the plugin's SDK predates replay markers, or its handler has no
// [Handler.ReplayCount]. It is known from the create reply and fixed for the
// session, so a reader tells "never" from "not yet" without a timeout. The wire
// carries it as [ParamReplayMarkersAccepted] in Options.Params, the one place a
// create reply can say it without a wire change; [LogSessionFromProto] reads it.
ReplayMarkers bool `json:"replay_markers,omitempty"`
}
LogSession represents an active log viewing session.
func LogSessionFromProto ¶
func LogSessionFromProto(p *logspb.LogSession) *LogSession
LogSessionFromProto decodes a session snapshot without opening native sources.
func (*LogSession) ToProto ¶
func (s *LogSession) ToProto() *logspb.LogSession
ToProto encodes the session snapshot and its active sources.
type LogSessionOptions ¶
type LogSessionOptions struct {
Reference *resourcev2.ResourceReference `json:"-"`
Route *resourcev2.AccessRoute `json:"-"`
Target string `json:"target"`
Follow bool `json:"follow"`
IncludePrevious bool `json:"include_previous"`
IncludeTimestamps bool `json:"include_timestamps"`
TailLines int64 `json:"tail_lines"`
SinceSeconds int64 `json:"since_seconds"`
SinceTime *time.Time `json:"since_time,omitempty"`
LimitBytes int64 `json:"limit_bytes"`
IncludeSourceEvents bool `json:"include_source_events"`
Params map[string]string `json:"params"`
}
LogSessionOptions contains options for creating or updating a log session.
func LogSessionOptionsFromProto ¶
func LogSessionOptionsFromProto(p *logspb.LogSessionOptions) LogSessionOptions
LogSessionOptionsFromProto decodes stream options and shares the wire Params map. Nil input produces zero options without resource admission metadata.
func (*LogSessionOptions) ToProto ¶
func (o *LogSessionOptions) ToProto() *logspb.LogSessionOptions
ToProto encodes stream options, sharing Params and omitting Reference and Route. A nil receiver produces nil; resource admission metadata travels separately.
type LogSessionStatus ¶
type LogSessionStatus int
LogSessionStatus represents the status of a log session.
const ( // LogSessionStatusActive indicates that the session is delivering logs. LogSessionStatusActive LogSessionStatus = iota // LogSessionStatusPaused indicates that log delivery is suspended. LogSessionStatusPaused // LogSessionStatusClosed indicates that the session has ended. LogSessionStatusClosed // LogSessionStatusError indicates that the session encountered a failure. LogSessionStatusError // LogSessionStatusConnecting indicates that native source acquisition is pending. LogSessionStatusConnecting // LogSessionStatusInitializing indicates that session setup is in progress. LogSessionStatusInitializing )
func LogSessionStatusFromProto ¶
func LogSessionStatusFromProto(p logspb.LogSessionStatus) LogSessionStatus
LogSessionStatusFromProto decodes a wire status, defaulting unknown values to active.
func (LogSessionStatus) ToProto ¶
func (s LogSessionStatus) ToProto() logspb.LogSessionStatus
ToProto converts the status to its wire value, defaulting unknown values to active.
type LogSource ¶
LogSource is a generic log-producing entity.
func LogSourceFromProto ¶
LogSourceFromProto decodes source identity and shares the wire Labels map.
type LogStreamCommand ¶
type LogStreamCommand int
LogStreamCommand represents a command from the client to control the stream.
const ( // StreamCommandPause requests suspension of log delivery. StreamCommandPause LogStreamCommand = iota // StreamCommandResume requests continuation of log delivery. StreamCommandResume // StreamCommandClose requests termination of the session. StreamCommandClose )
func LogStreamCommandFromProto ¶
func LogStreamCommandFromProto(p logspb.LogStreamCommand) LogStreamCommand
LogStreamCommandFromProto decodes the command, defaulting unknown values to pause.
func (LogStreamCommand) ToProto ¶
func (c LogStreamCommand) ToProto() logspb.LogStreamCommand
ToProto encodes the command, defaulting unknown values to pause.
type LogStreamEvent ¶
type LogStreamEvent struct {
Type LogStreamEventType `json:"type"`
SourceID string `json:"source_id"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
}
LogStreamEvent represents a lifecycle event during streaming.
func LogStreamEventFromProto ¶
func LogStreamEventFromProto(p *logspb.LogStreamEvent) LogStreamEvent
LogStreamEventFromProto decodes event details; an absent timestamp stays zero.
func (*LogStreamEvent) ToProto ¶
func (e *LogStreamEvent) ToProto() *logspb.LogStreamEvent
ToProto encodes the event details and timestamp.
type LogStreamEventType ¶
type LogStreamEventType int
LogStreamEventType represents the type of log stream event.
const ( // StreamEventSourceAdded announces a source joining the session. StreamEventSourceAdded LogStreamEventType = iota // StreamEventSourceRemoved announces a source leaving the session. StreamEventSourceRemoved // StreamEventStreamError reports a source stream failure. StreamEventStreamError // StreamEventReconnecting announces a pending source reconnection. StreamEventReconnecting // StreamEventReconnected announces a successful source reconnection. StreamEventReconnected // StreamEventStreamEnded announces completion of a source stream. StreamEventStreamEnded // StreamEventSessionReady announces completion of session source setup. StreamEventSessionReady // StreamEventSourceCaughtUp announces that one source's replay has been delivered: // the lines it sends after this event, until its stream opens again, are live. It // is sent only to a session that asked for replay markers with // [ParamReplayMarkers] and whose plugin accepted ([LogSession.ReplayMarkers]), at // most once for each opening of the source's stream: a source that reopens // delivers its tail again and is caught up again. StreamEventSourceCaughtUp )
const StreamEventUnknown LogStreamEventType = -1
StreamEventUnknown is what a reader decodes an event kind it does not know to. It has no wire value and is never sent: a newer plugin's event must neither vanish nor pass for a source joining the session.
func LogStreamEventTypeFromProto ¶
func LogStreamEventTypeFromProto(p logspb.LogStreamEventType) LogStreamEventType
LogStreamEventTypeFromProto decodes the event kind. A kind this SDK does not know (a newer plugin's) decodes to StreamEventUnknown, never to a source joining.
func (LogStreamEventType) String ¶
func (t LogStreamEventType) String() string
String returns the event name or a numeric description for unknown values.
func (LogStreamEventType) ToProto ¶
func (t LogStreamEventType) ToProto() logspb.LogStreamEventType
ToProto encodes the event kind; a value with no wire counterpart encodes as source-added.
type LogStreamRequest ¶
type LogStreamRequest struct {
SourceID string
Labels map[string]string
ResourceData *resourcev2.Value `json:"resource_data"`
Reference *resourcev2.ResourceReference `json:"reference,omitempty"`
Route *resourcev2.AccessRoute `json:"route,omitempty"`
Target string
Follow bool
IncludePrevious bool
IncludeTimestamps bool
TailLines int64
SinceSeconds int64
SinceTime *time.Time
LimitBytes int64
Params map[string]string
}
LogStreamRequest is the generic request to open a log stream for one source.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the lifecycle of log sessions within a plugin process.
func NewManager ¶
func NewManager(cfg ManagerConfig) *Manager
NewManager creates a new Manager with the given config.
func (*Manager) BindConnectionContextProvider ¶ added in v0.9.0
func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
BindConnectionContextProvider binds resource sessions to the active source generation.
func (*Manager) Close ¶
func (m *Manager) Close()
Close refuses every later session start, cancels the active sessions and waits for their goroutines to finish. It may be called more than once, and concurrently, as may Wait.
func (*Manager) CloseSession ¶
func (m *Manager) CloseSession(_ *types.PluginContext, sessionID string) error
CloseSession removes and cancels a session, waiting up to the shutdown timeout. An unknown ID returns an error; a timeout is logged rather than returned.
func (*Manager) CreateResourceSession ¶ added in v0.9.0
func (m *Manager) CreateResourceSession( pluginctx *types.PluginContext, opts CreateSessionOptions, ) (*LogSession, error)
CreateResourceSession admits a configured connection and registers a connecting session; native handler/resolver acquisition proceeds asynchronously. The returned session is not a readiness receipt. Its lifetime is independent of the initiating RPC and ends through CloseSession, generation retirement, or shutdown.
The configured-generation lease remains held until every native producer exits. Retirement cancels the session, but cannot destroy a client still in use.
func (*Manager) CreateSession ¶
func (m *Manager) CreateSession( pluginctx *types.PluginContext, opts CreateSessionOptions, ) (*LogSession, error)
CreateSession registers a legacy session and starts acquisition asynchronously. A successful return does not imply readiness; close the session explicitly.
func (*Manager) GetSession ¶
func (m *Manager) GetSession(_ *types.PluginContext, sessionID string) (*LogSession, error)
GetSession returns an independent session snapshot, or an error for an unknown ID.
func (*Manager) GetSupportedResources ¶
func (m *Manager) GetSupportedResources(_ *types.PluginContext) []Handler
GetSupportedResources returns the registered handler descriptions.
func (*Manager) ListSessions ¶
func (m *Manager) ListSessions(_ *types.PluginContext) ([]*LogSession, error)
ListSessions returns session snapshots sorted by ID.
func (*Manager) Stream ¶
func (m *Manager) Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
Stream starts command handling and returns the shared output channel. With a configured sink, output is nil. Cancellation or closed input cancels sessions.
func (*Manager) UpdateSessionOptions ¶
func (m *Manager) UpdateSessionOptions( _ *types.PluginContext, sessionID string, opts LogSessionOptions, ) (*LogSession, error)
UpdateSessionOptions replaces mutable options while preserving the admitted target. The enabled_sources parameter cancels disabled sources and restarts enabled sources that are not running, including sources that ended on their own.
Updates are serialised per session, from the sources they restart to the options they store, so the update that commits last decides which sources run, however many overlap (the log viewer syncs 300 ms after the last change, so a slow plugin makes two in flight plausible). The lock is not held while an update announces what it changed.
A session can take a source for as long as it is alive: while its initial sources run, and afterwards while one of its producers still does (see producers.Group). Once the last producer has returned, or the session is being closed, an update that would start a source is refused with a CONFLICT error (see resourcev2.ErrorCode) and changes nothing: not the options, not the sources. An update that starts no source is applied as ever, to a session that has ended too.
func (*Manager) Wait ¶
func (m *Manager) Wait()
Wait stops the manager from taking sessions, as Close does, and blocks until the sessions it holds have finished. Unlike Close it cancels none of them: a session that ends on its own is waited for, one that follows its source until it is closed is waited for until it is. A start that comes after Wait began, or that races it, is refused with a CONNECTION_ERROR (see resourcev2.ErrorCode), never admitted and never lost.
type ManagerConfig ¶
type ManagerConfig struct {
Logger logging.Logger
Settings settings.Provider
Handlers map[string]Handler
Resolvers map[string]SourceResolver
Sink OutputSink // optional: nil → bounded shared output channel
Clock timeutil.Clock // optional: nil → timeutil.RealClock
}
ManagerConfig configures the Manager.
type OutputSink ¶
type OutputSink interface {
OnLine(line LogLine)
OnEvent(sessionID string, event LogStreamEvent)
}
OutputSink receives log lines and stream events from the Manager. Tests inject RecordingOutput; callers may inject a custom sink instead of the Manager's default session-cancellable output channel.
type Plugin ¶
Plugin implements the hashicorp go-plugin interfaces for log capability.
func (*Plugin) BindConnectionContextProvider ¶ added in v0.9.0
func (p *Plugin) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
BindConnectionContextProvider forwards the source binding to providers that consume it.
func (*Plugin) GRPCClient ¶
func (p *Plugin) GRPCClient( _ context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn, ) (any, error)
GRPCClient creates a remote log provider using the supplied connection.
func (*Plugin) GRPCServer ¶
GRPCServer registers log lifecycle and raw resource-admission handlers.
type PluginClient ¶
type PluginClient struct {
// contains filtered or unexported fields
}
PluginClient adapts remote log RPCs to Provider without downgrading resource requests.
func (*PluginClient) CloseSession ¶
func (c *PluginClient) CloseSession(ctx *types.PluginContext, sessionID string) error
CloseSession requests remote cleanup for the named session.
func (*PluginClient) CreateResourceSession ¶ added in v0.9.0
func (c *PluginClient) CreateResourceSession(ctx *types.PluginContext, opts CreateSessionOptions) (*LogSession, error)
CreateResourceSession checks the trusted route and validates the admitted remote result.
func (*PluginClient) CreateSession ¶
func (c *PluginClient) CreateSession( ctx *types.PluginContext, opts CreateSessionOptions, ) (*LogSession, error)
CreateSession selects the resource RPC whenever options carry resource intent.
func (*PluginClient) GetSession ¶
func (c *PluginClient) GetSession( ctx *types.PluginContext, sessionID string, ) (*LogSession, error)
GetSession retrieves a remote session by ID.
func (*PluginClient) GetSupportedResources ¶
func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) []Handler
GetSupportedResources lists remote handlers, returning nil when discovery fails.
func (*PluginClient) ListSessions ¶
func (c *PluginClient) ListSessions(ctx *types.PluginContext) ([]*LogSession, error)
ListSessions returns the remote provider's current sessions.
func (*PluginClient) Stream ¶
func (c *PluginClient) Stream( ctx context.Context, in chan StreamInput, ) (chan StreamOutput, error)
Stream forwards input and output until cancellation or transport termination. Closing input closes the send side; the receiver owns and closes the output channel.
func (*PluginClient) UpdateSessionOptions ¶
func (c *PluginClient) UpdateSessionOptions( ctx *types.PluginContext, sessionID string, opts LogSessionOptions, ) (*LogSession, error)
UpdateSessionOptions changes streaming options for an existing remote session.
type PluginOpts ¶
type PluginOpts struct {
// Handlers maps resource keys to their log handlers.
// For example: "core::v1::Pod" -> Handler
Handlers map[string]Handler `json:"handlers"`
// SourceResolvers maps resource keys to source resolvers that resolve
// group resources into individual log sources.
// For example: "apps::v1::Deployment" -> SourceResolver
SourceResolvers map[string]SourceResolver `json:"-"`
}
PluginOpts contains the options for the log plugin.
type PluginServer ¶
type PluginServer struct {
Impl Provider
// contains filtered or unexported fields
}
PluginServer adapts a log provider to gRPC and preserves resource error classification.
func (*PluginServer) CloseSession ¶
func (s *PluginServer) CloseSession( ctx context.Context, in *logspb.LogSessionByIdRequest, ) (*logspb.CloseLogSessionResponse, error)
CloseSession requests provider cleanup for the named session.
func (*PluginServer) CreateResourceSession ¶ added in v0.9.0
func (s *PluginServer) CreateResourceSession( ctx context.Context, in *logspb.CreateLogSessionRequest, ) (*logspb.ResourceLogSessionResponse, error)
CreateResourceSession validates wire version, trusted route, and provider result before returning a session.
func (*PluginServer) CreateSession ¶
func (s *PluginServer) CreateSession( ctx context.Context, in *logspb.CreateLogSessionRequest, ) (*logspb.CreateLogSessionResponse, error)
CreateSession serves legacy requests and rejects resource intent without fallback.
func (*PluginServer) GetSession ¶
func (s *PluginServer) GetSession( ctx context.Context, in *logspb.LogSessionByIdRequest, ) (*logspb.LogSessionByIdResponse, error)
GetSession retrieves one session by ID through the provider.
func (*PluginServer) GetSupportedResources ¶
func (s *PluginServer) GetSupportedResources( ctx context.Context, _ *emptypb.Empty, ) (*logspb.GetSupportedLogResourcesResponse, error)
GetSupportedResources returns the provider's registered log handlers.
func (*PluginServer) ListSessions ¶
func (s *PluginServer) ListSessions( ctx context.Context, _ *emptypb.Empty, ) (*logspb.ListLogSessionsResponse, error)
ListSessions returns the provider's current sessions.
func (*PluginServer) Stream ¶
func (s *PluginServer) Stream(stream logspb.LogPlugin_StreamServer) (streamErr error)
Stream forwards bidirectional log traffic until the RPC ends or receiving fails.
func (*PluginServer) UpdateSessionOptions ¶
func (s *PluginServer) UpdateSessionOptions( ctx context.Context, in *logspb.UpdateLogSessionOptionsRequest, ) (*logspb.LogSessionByIdResponse, error)
UpdateSessionOptions applies streaming options to an existing session.
type Provider ¶
type Provider interface {
GetSupportedResources(ctx *types.PluginContext) []Handler
CreateSession(ctx *types.PluginContext, opts CreateSessionOptions) (*LogSession, error)
GetSession(ctx *types.PluginContext, sessionID string) (*LogSession, error)
ListSessions(ctx *types.PluginContext) ([]*LogSession, error)
CloseSession(ctx *types.PluginContext, sessionID string) error
UpdateSessionOptions(ctx *types.PluginContext, sessionID string, opts LogSessionOptions) (*LogSession, error)
Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
}
Provider is the interface satisfied by the plugin server and client to provide log viewing functionality.
type ReplayCountFunc ¶ added in v0.22.0
type ReplayCountFunc func(ctx *types.PluginContext, req LogStreamRequest) (int64, error)
ReplayCountFunc reports how many of the first lines of the stream a handler opens for req are replay, lines the source already held; see Handler.ReplayCount.
type ResourceSessionProvider ¶ added in v0.9.0
type ResourceSessionProvider interface {
CreateResourceSession(*types.PluginContext, CreateSessionOptions) (*LogSession, error)
}
ResourceSessionProvider extends the existing log lifecycle without converting resource bodies through JSON maps or Struct. Resource data remains a canonical Value; references and routes are optional actual caller bindings. Resource creation never falls back to the legacy CreateSession RPC. Admission inherits creation cancellation; accepted native callbacks retain its values under the native-generation lifetime. A missing serialized plugin context does not create a connection or authority; explicit routes still require a matching connection supplied through the caller's plugin metadata. SessionID correlates acceptance and cleanup only; it confers no authority and does not make creation idempotent. Owners must close the chosen ID after a failed or lost response. Manager retains the generation until producers drain.
type SourceBuilderFunc ¶
type SourceBuilderFunc func( resourceID string, resourceData *resourcev2.Value, opts LogSessionOptions, ) []LogSource
SourceBuilderFunc builds LogSources from resource data for direct handler streaming. Plugins implement this to translate their resource data into properly-labeled sources that the LogHandlerFunc can consume. For example, a K8s plugin extracts pod name, namespace, and container names from the pod spec.
type SourceEvent ¶
type SourceEvent struct {
Type SourceEventType
Source LogSource
}
SourceEvent represents a source lifecycle change.
type SourceEventType ¶
type SourceEventType int
SourceEventType represents the type of source lifecycle event.
const ( // SourceAdded announces a newly available log source. SourceAdded SourceEventType = iota // SourceRemoved announces that a log source is no longer available. SourceRemoved )
type SourceResolver ¶
type SourceResolver func( ctx *types.PluginContext, resourceData *resourcev2.Value, opts SourceResolverOptions, ) (*SourceResolverResult, error)
SourceResolver resolves a "group" resource into individual log sources.
type SourceResolverOptions ¶
type SourceResolverOptions struct {
Reference *resourcev2.ResourceReference
Route *resourcev2.AccessRoute
Watch bool // if true, also return a channel for source changes
Target string // optional filter (e.g., specific container name)
Params map[string]string // plugin-specific resolver params
}
SourceResolverOptions configures how sources are resolved.
type SourceResolverResult ¶
type SourceResolverResult struct {
Sources []LogSource // current sources
Events <-chan SourceEvent // source lifecycle stream (nil if Watch=false)
}
SourceResolverResult contains the resolved sources and optional event channel.
type StreamInput ¶
type StreamInput struct {
SessionID string `json:"session_id"`
Command LogStreamCommand `json:"command"`
}
StreamInput is a control message from the client to the stream.
func StreamInputFromProto ¶
func StreamInputFromProto(p *logspb.LogStreamInput) StreamInput
StreamInputFromProto decodes a session-scoped stream control message.
func (*StreamInput) ToProto ¶
func (i *StreamInput) ToProto() *logspb.LogStreamInput
ToProto encodes a session-scoped stream control message.
type StreamOutput ¶
type StreamOutput struct {
SessionID string
Line *LogLine
Event *LogStreamEvent
}
StreamOutput is a log line or event from the stream.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package logtest provides programmable log sources, output recorders, and a harness that exercises the real log manager with context-aware test streams.
|
Package logtest provides programmable log sources, output recorders, and a harness that exercises the real log manager with context-aware test streams. |