Documentation
¶
Overview ¶
Package connections is a branch-connections HTTP client that follows the patterns of github.com/planetscale/planetscale-go: a typed Client over shared auth, base-URL, and transport machinery. The auth header construction, error formatting, and response decode helpers mirror the equivalents in planetscale-go.
Index ¶
- func BlockingCounts(connections []Connection) map[int]int
- func DerefString(value *string) string
- func JoinInts(values []int) string
- func JoinWaitEvents(waitEventType, waitEvent string) string
- func SanitizeDisplayText(value string) string
- func SanitizeMultilineDisplayText(value string) string
- func SortConnections(connections []Connection, mode SortMode)
- func UserFacingError(err error, action string) error
- func UserFacingErrorText(err error, action string) string
- type ActionResult
- type ActionTarget
- type AvailableTargets
- type Client
- func (s *Client) CancelQuery(ctx context.Context, target ActionTarget) error
- func (s *Client) CancelQueryResult(ctx context.Context, target ActionTarget) (ActionResult, error)
- func (s *Client) List(ctx context.Context, sort SortMode) (ConnectionList, error)
- func (s *Client) TerminateConnection(ctx context.Context, target ActionTarget) error
- func (s *Client) TerminateConnectionResult(ctx context.Context, target ActionTarget) (ActionResult, error)
- func (s *Client) TerminateTransaction(ctx context.Context, target ActionTarget) error
- func (s *Client) TerminateTransactionResult(ctx context.Context, target ActionTarget) (ActionResult, error)
- type ClientConfig
- type Connection
- type ConnectionList
- type DatabaseKind
- type HTTPError
- type InstanceMeta
- type SortMode
- type Topology
- type UnknownInstanceError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockingCounts ¶
func BlockingCounts(connections []Connection) map[int]int
BlockingCounts returns each connection's downstream blocking depth by PID.
func DerefString ¶
DerefString returns the pointed-to string, or "" when nil.
func JoinWaitEvents ¶
JoinWaitEvents renders the wait-event type/event pair as "type/event", collapsing to whichever side is present when one is empty.
func SanitizeDisplayText ¶ added in v0.306.0
SanitizeDisplayText strips ASCII C0 controls, DEL, and C1 controls from text that will be written to a terminal. Connection observability fields such as query text, application_name, username, and client_addr can contain attacker-controlled escape sequences (CSI/OSC) from anyone with connect access to the observed branch.
func SanitizeMultilineDisplayText ¶ added in v0.306.0
SanitizeMultilineDisplayText sanitizes each line of value while preserving newline separators so multi-line query text stays readable in human output.
func SortConnections ¶
func SortConnections(connections []Connection, mode SortMode)
func UserFacingError ¶
func UserFacingErrorText ¶
Types ¶
type ActionResult ¶
type ActionTarget ¶
type ActionTarget struct {
Instance string
PID int
ConnectionID *string
TransactionID *string
QueryID *string
}
ActionTarget identifies the connection an action acts on. Instance and PID describe the selected row; ConnectionID, TransactionID, and QueryID are the server-issued IDs for connection, transaction, and query verification.
type AvailableTargets ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
func (*Client) CancelQuery ¶
func (s *Client) CancelQuery(ctx context.Context, target ActionTarget) error
CancelQuery asks the backend to cancel the active query identified by target.QueryID.
func (*Client) CancelQueryResult ¶
func (s *Client) CancelQueryResult(ctx context.Context, target ActionTarget) (ActionResult, error)
func (*Client) TerminateConnection ¶
func (s *Client) TerminateConnection(ctx context.Context, target ActionTarget) error
TerminateConnection force-terminates the connection identified by target.ConnectionID without regard to its current query or transaction. Operator-initiated; gated by a y/n confirmation in the TUI.
func (*Client) TerminateConnectionResult ¶
func (s *Client) TerminateConnectionResult(ctx context.Context, target ActionTarget) (ActionResult, error)
func (*Client) TerminateTransaction ¶
func (s *Client) TerminateTransaction(ctx context.Context, target ActionTarget) error
TerminateTransaction asks the backend to terminate the connection only if its current transaction matches target.TransactionID — i.e., reject if the connection has moved on. Same-transaction semantics live on the server.
func (*Client) TerminateTransactionResult ¶
func (s *Client) TerminateTransactionResult(ctx context.Context, target ActionTarget) (ActionResult, error)
TerminateTransactionResult asks the backend to terminate a transaction and returns any action metadata the backend provides.
type ClientConfig ¶
type Connection ¶
type Connection struct {
PID int `json:"pid"`
Instance string `json:"instance"`
InstanceRole string `json:"instance_role,omitempty"`
Username string `json:"username"`
ApplicationName string `json:"application_name"`
DatabaseName string `json:"database,omitempty"`
ClientAddr string `json:"client_addr"`
State string `json:"state"`
WaitEventType string `json:"wait_event_type"`
WaitEvent string `json:"wait_event"`
BackendType string `json:"backend_type"`
XactStart *time.Time `json:"xact_start,omitempty"`
QueryStart *time.Time `json:"query_start,omitempty"`
ConnectionID *string `json:"connection_id,omitempty"`
TransactionID *string `json:"transaction_id,omitempty"`
QueryID *string `json:"query_id,omitempty"`
Duration time.Duration `json:"duration"`
BlockedBy []int `json:"blocked_by,omitempty"`
QueryText string `json:"query_text,omitempty"`
}
func (Connection) HumanFields ¶
func (c Connection) HumanFields() [][2]string
HumanFields returns the connection's scalar fields as ordered (name, value) pairs for vertical, MySQL `\G`-style rendering. The query text is excluded — callers render it separately because it is multi-line. This is the single source of truth shared by the agent-cli `list --format human` output and the interactive detail view, so the two never drift.
type ConnectionList ¶
type ConnectionList struct {
CapturedAt time.Time `json:"captured_at"`
DatabaseKind DatabaseKind `json:"database_kind,omitempty"`
Connections []Connection `json:"connections"`
Sort SortMode `json:"sort"`
Instances []InstanceMeta `json:"instances,omitempty"`
Topology *Topology `json:"topology,omitempty"`
}
func NewConnectionList ¶
func NewConnectionList(capturedAt time.Time, connections []Connection, sort SortMode) ConnectionList
func (ConnectionList) HasUnreachableInstance ¶ added in v0.291.0
func (l ConnectionList) HasUnreachableInstance() bool
HasUnreachableInstance reports whether the server flagged any instance as unreachable in the list response. These partial fan-out failures drive the "N of M instances unreachable" banner.
type DatabaseKind ¶
type DatabaseKind string
const ( DatabaseKindMySQL DatabaseKind = "mysql" DatabaseKindPostgreSQL DatabaseKind = "postgresql" )
type HTTPError ¶
type HTTPError struct {
Op string
StatusCode int
Message string
Available AvailableTargets
}
type InstanceMeta ¶
type UnknownInstanceError ¶
UnknownInstanceError reports an --instance filter value that matches none of the instances in the list response.
func (*UnknownInstanceError) Error ¶
func (e *UnknownInstanceError) Error() string