victorialogs

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package victorialogs implements providers.LogsProvider against VictoriaLogs, querying with LogsQL and normalizing the NDJSON response into log lines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client queries a VictoriaLogs backend.

func New

func New(baseURL string) *Client

New builds a client for a VictoriaLogs base URL, unauthenticated.

func NewWithAuth added in v0.3.0

func NewWithAuth(baseURL, tokenEnv string, headers map[string]string) *Client

NewWithAuth builds a client that adds optional auth to every request. tokenEnv names an env var holding a bearer token (empty, or pointing at an unset/empty var, ⇒ no Authorization header); headers are static request headers (e.g. "X-Scope-OrgID" for a multi-tenant backend). The token is read from the environment at request-build time and is never logged.

func (*Client) FieldNames added in v0.9.0

func (c *Client) FieldNames(ctx context.Context, query string, w providers.TimeWindow) ([]providers.FieldCount, error)

FieldNames lists the field names present in the logs matching query over the window, via /select/logsql/field_names — the log-schema discovery path so a query that assumed the wrong collector field names can be corrected. Results are most-frequent first, as the backend orders them.

func (*Client) Hits added in v0.9.0

func (c *Client) Hits(ctx context.Context, query string, w providers.TimeWindow, step time.Duration) ([]providers.Bucket, error)

Hits returns the per-step match count over the window, split by log level when the level field is present, via /select/logsql/hits (field=level). It powers the logs_error_summary histogram ("3/5m baseline → 412/5m spike"). A step <= 0 defaults to one minute. Buckets carry Level="" for the unsplit series a backend without a level field returns.

func (*Client) Query

Query runs a LogsQL query over the window and returns normalized log lines.

It pages with limit+offset up to maxLines so a high-volume window is not silently capped at a single page; when the cap binds (the page that reaches it was full, implying more matched), a sentinel line signals the partial view.

Offset pagination orders by the largest _time values; concurrent ingestion into the queried range could shift the page boundary, but incidents query a settled past window, so this is acceptable for v1.

func (*Client) TopMessages added in v0.9.0

func (c *Client) TopMessages(ctx context.Context, query string, w providers.TimeWindow, k int) ([]providers.MsgCount, error)

TopMessages returns up to k dominant messages over the window. It runs `<query> | collapse_nums | stats by (_msg) count() rows, min(_time) first, max(_time) last | sort by (rows desc) | limit k` — collapse_nums normalizes numeric tokens so "took 12ms" and "took 907ms" group into one message. The stats pipe streams NDJSON rows through the raw query endpoint. k <= 0 defaults to 10.

func (*Client) WithLevelField added in v0.9.0

func (c *Client) WithLevelField(field string) *Client

WithLevelField overrides the severity field Hits splits by (config.logs.fields). An empty name is ignored so a caller passing an unset config keeps the default. It returns the client to allow one-line construction: New(url).WithLevelField(f).

Jump to

Keyboard shortcuts

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