providers

package
v0.1.50 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 59 Imported by: 0

Documentation

Overview

Package providers contains the built-in data providers for the query engine. Each provider self-registers via init(); consumers enable them with a blank import:

import _ "github.com/flanksource/commons-db/query/providers"

Index

Constants

View Source
const SQLXEventProviderType = "sqlserver-xevent"

SQLXEventProviderType names the Extended Events provider in a profile's `provider.type`. A profile naming it must also declare `trace:` — the capture has no single-shot form, so Execute refuses.

Variables

This section is empty.

Functions

func FilterOpenSearch

func FilterOpenSearch(body string, filters []query.ColumnFilterValue) (string, error)

FilterOpenSearch folds the given selections into an already-rendered query body, for a caller that assembled its own DSL rather than a stored profile — the connection browser.

It exists so there is one clause compiler in the codebase: a second implementation would be a second set of rules for what excluding a value means, and the two would disagree on the day one of them was fixed.

With no active filter it returns the body byte for byte, so turning filtering on cannot change what an unfiltered query sends.

func FilterSQL

func FilterSQL(driver, statement string, filters []query.ColumnFilterValue) (string, []any, error)

FilterSQL wraps an operator-authored statement so the given selections narrow its result rather than its text, for a caller that runs its own SQL rather than a stored profile — the connection browser.

It exists so there is one CTE wrapper and one predicate builder in the codebase: a second implementation would be a second set of quoting and binding rules to keep correct, and the two would disagree on the day one of them was fixed.

driver is the connection type (models.ConnectionType*), not a registry key.

func NeedsOpenSearchTimeFieldMapping

func NeedsOpenSearchTimeFieldMapping(params []esdsl.ParamBinding) bool

NeedsOpenSearchTimeFieldMapping reports whether resolved parameters contain a non-empty time bound.

func OpenSQLServer added in v0.1.49

func OpenSQLServer(ctx context.Context, reference string) (*sql.DB, func(), error)

OpenSQLServer leases the SQL Server connection named reference and opens a client on it for an Extended Events capture; release closes the client and gives the lease back. A connection of any other type is refused.

func ReadOpenTelemetrySpans added in v0.1.49

func ReadOpenTelemetrySpans(ctx context.Context, read OpenTelemetryRead, emit func(query.Row)) error

ReadOpenTelemetrySpans emits each span read, normalized as the opentelemetry provider's rows are, with source_index and source_id naming its document. It reads in the date field's order with search_after, opening no point in time, so a follow sees what lands after it started.

Types

type OpenSearchTimeFieldMappingRequest

type OpenSearchTimeFieldMappingRequest struct {
	Searcher   *opensearch.Searcher
	Index      string
	Search     esdsl.Search
	Params     []esdsl.ParamBinding
	Inspection query.InspectionOptions
}

ResolveOpenSearchTimeFieldMapping reads the exact field used by active time-role parameters. The mapping is runtime metadata and never becomes part of the stored profile.

type OpenTelemetryRead added in v0.1.49

type OpenTelemetryRead struct {
	// Connection is the opentelemetry connection, and Options the
	// opentelemetry provider's options for its index and fields.
	Connection string
	Options    map[string]any
	// From and To bound the read on the date field, as date math such as
	// now-1h or RFC3339; empty leaves that side open.
	From, To string
	// Follow keeps reading the spans indexed after the read caught up, until
	// ctx ends; it has no To.
	Follow bool
	// Poll is how long a caught-up follow waits before asking again; zero is
	// two seconds. Lag holds a follow behind now, so spans indexed late still
	// land before the read passes their instant.
	Poll, Lag time.Duration
}

OpenTelemetryRead is one read of span documents.

type SQLPageRequest

type SQLPageRequest struct {
	// Connection names the connection client is, for the SQL statement tap.
	Connection       string
	Query            string
	QueryArgs        []any
	QueryIdentifiers []string
	Filters          []query.ColumnFilterValue
	Order            query.Order
	Position         query.CursorPosition
	Page             query.PageRequest
	Diagnostics      *query.ProviderDiagnostics
}

type SQLPageResult

type SQLPageResult struct {
	Rows        []query.Row
	ColumnTypes []*sql.ColumnType
	Total       *query.Total
	HasMore     bool
}

func ReadSQLPage

func ReadSQLPage(ctx context.Context, client *sql.DB, driver string, request SQLPageRequest) (result SQLPageResult, err error)

type XEventCaptureOptions added in v0.1.49

type XEventCaptureOptions struct {
	// SessionName names the Extended Events session on the server. Required:
	// the session is visible in sys.dm_xe_sessions to everyone on the instance,
	// so what it is called is the profile author's to say, not this package's.
	// A unique suffix is appended so concurrent captures of one profile do not
	// collide on the server.
	SessionName string `json:"sessionName"`

	// Databases scopes the session by database name; empty uses the
	// connection's own, and "*" captures the whole instance.
	Databases []string `json:"databases,omitempty"`

	Users []string `json:"users,omitempty"`
	Apps  []string `json:"apps,omitempty"`
	Hosts []string `json:"hosts,omitempty"`

	// Events selects the Extended Events to capture; empty uses xetrace's
	// defaults. Add sp_statement_completed to see statements inside procedures.
	Events []string `json:"events,omitempty"`

	// Types narrows to statement types (SELECT/INSERT/UPDATE/DELETE/MERGE/EXEC/DML).
	Types []string `json:"types,omitempty"`
	// Tables narrows to referenced tables, or a procedure name for an EXEC.
	Tables []string `json:"tables,omitempty"`

	// MinDuration drops statements faster than this threshold, e.g. "10ms".
	MinDuration string `json:"minDuration,omitempty"`
	// Poll is the ring-buffer poll cadence, e.g. "1s". Empty uses xetrace's.
	Poll string `json:"poll,omitempty"`

	// MaxEvents caps the ring buffer's event count; MaxMemoryKB its size.
	MaxEvents   int `json:"maxEvents,omitempty"`
	MaxMemoryKB int `json:"maxMemoryKb,omitempty"`
}

XEventCaptureOptions are the capture knobs a profile sets under `provider.options`. Databases/Users/Apps/Hosts are pushed into the Extended Events predicate so they filter inside SQL Server; Types/Tables are applied to the parsed events, because the predicate has no structured statement type or referenced-object to match on. All of them take collections.MatchItem patterns (exact, prefix/suffix `*` wildcard, `!` exclusion).

The sizing and poll knobs are zero by default so an unset one means "take the documented default" rather than a number this struct has to keep in step with xetrace.

func (XEventCaptureOptions) CaptureOptions added in v0.1.49

CaptureOptions projects the decoded options onto the two xetrace option sets, rejecting any value the session could not honour.

It is separate from Stream so a bad profile fails at decode with the option named, rather than as an opaque SQL Server syntax error once a session is half-created.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL