query

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package query provides the datatypes and functions for construction queries using the Axiom Processing Language (APL) and working with their results.

Usage:

import "github.com/axiomhq/axiom-go/axiom/query"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// Time is the time the event occurred. Matches SysTime if not specified
	// during ingestion.
	Time time.Time `json:"_time"`
	// SysTime is the time the event was recorded on the server.
	SysTime time.Time `json:"_sysTime"`
	// RowID is the unique ID of the event row. It can be used as a cursor to
	// resume a query. See [query.SetCursor].
	RowID string `json:"_rowId"`
	// Data contains the raw data of the event (with filters and aggregations
	// applied).
	Data map[string]any `json:"data"`
}

Entry is an event that matched a query and is thus part of the result set.

type EntryGroup

type EntryGroup struct {
	// ID is the unique the group.
	ID uint64 `json:"id"`
	// Group maps the fieldnames to the unique values for the entry.
	Group map[string]any `json:"group"`
	// Aggregations of the group.
	Aggregations []EntryGroupAgg `json:"aggregations"`
}

EntryGroup is a group of queried event.

type EntryGroupAgg

type EntryGroupAgg struct {
	// Alias is the aggregations alias. If it wasn't specified at query time, it
	// is the uppercased string representation of the aggregation operation.
	Alias string `json:"op"`
	// Value is the result value of the aggregation.
	Value any `json:"value"`
}

EntryGroupAgg is an aggregation which is part of a group of queried events.

type Interval

type Interval struct {
	// StartTime of the interval.
	StartTime time.Time `json:"startTime"`
	// EndTime of the interval.
	EndTime time.Time `json:"endTime"`
	// Groups of the interval.
	Groups []EntryGroup `json:"groups"`
}

Interval is the interval of queried time series.

type Message

type Message struct {
	// Priority of the message.
	Priority MessagePriority `json:"priority"`
	// Code of the message.
	Code MessageCode `json:"code"`
	// Count describes how often a message of this type was raised by the query.
	Count uint `json:"count"`
	// Text is a human readable text representation of the message.
	Text string `json:"msg"`
}

Message is a message associated with a query result.

type MessageCode

type MessageCode uint8

MessageCode represents the code of a message associated with a query.

const (
	VirtualFieldFinalizeError   MessageCode // virtual_field_finalize_error
	MissingColumn                           // missing_column
	LicenseLimitForQueryWarning             // license_limit_for_query_warning
	DefaultLimitWarning                     // default_limit_warning

	// CompilerWarning is a generic code. Please inspect the message text for
	// more details.
	CompilerWarning // apl_
)

All available message codes.

func (MessageCode) MarshalJSON added in v0.12.0

func (mc MessageCode) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the message code to its string representation because that's what the server expects.

func (MessageCode) String

func (i MessageCode) String() string

func (*MessageCode) UnmarshalJSON

func (mc *MessageCode) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the message code from the string representation the server returns.

type MessagePriority

type MessagePriority uint8

MessagePriority represents the priority of a message associated with a query.

const (
	Trace MessagePriority // trace
	Debug                 // debug
	Info                  // info
	Warn                  // warn
	Error                 // error
	Fatal                 // fatal
)

All available message priorities.

func (MessagePriority) MarshalJSON added in v0.12.0

func (mp MessagePriority) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the message priority to its string representation because that's what the server expects.

func (MessagePriority) String

func (i MessagePriority) String() string

func (*MessagePriority) UnmarshalJSON

func (mp *MessagePriority) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the message priority from the string representation the server returns.

type Option added in v0.13.0

type Option func(*Options)

An Option applies an optional parameter to a query.

func SetCursor added in v0.14.0

func SetCursor(cursor string, include bool) Option

SetCursor specifies the cursor of the query. If include is set to true the event that matches the cursor will be included in the result. When using this option, please make sure to use the initial query's start and end times.

func SetEndTime added in v0.13.0

func SetEndTime(endTime time.Time) Option

SetEndTime specifies the end time of the query interval. When also using SetCursor, please make sure to use the end time of the query that returned the cursor that will be used.

func SetStartTime added in v0.13.0

func SetStartTime(startTime time.Time) Option

SetStartTime specifies the start time of the query interval. When also using SetCursor, please make sure to use the start time of the query that returned the cursor that will be used.

func SetVariable added in v0.15.2

func SetVariable(name string, value any) Option

SetVariable adds a variable that can be referenced by the APL query. This option can be called multiple times to add multiple variables. If a variable with the same name already exists, it will be overwritten. Defining variables in APL using the "let" keyword takes precedence over variables provided via the query options.

func SetVariables added in v0.15.2

func SetVariables(variables map[string]any) Option

SetVariables sets the variables that can be referenced by the APL query. It will overwrite any existing variables. Defining variables in APL using the "let" keyword takes precedence over variables provided via the query options.

type Options

type Options struct {
	// StartTime for the interval to query.
	StartTime time.Time `json:"startTime,omitempty"`
	// EndTime of the interval to query.
	EndTime time.Time `json:"endTime,omitempty"`
	// Cursor to use for pagination. When used, don't specify new start and end
	// times but rather use the start and end times of the query that returned
	// the cursor that will be used.
	Cursor string `json:"cursor,omitempty"`
	// IncludeCursor specifies whether the event that matches the cursor should
	// be included in the result.
	IncludeCursor bool `json:"includeCursor,omitempty"`
	// Variables is an optional set of additional variables can be referenced by
	// the APL query. Defining variables in APL using the "let" keyword takes
	// precedence over variables provided via the query options.
	Variables map[string]any `json:"variables,omitempty"`
}

Options specifies the optional parameters for a query.

type Result

type Result struct {
	// The datasets that were queried in order to create the result.
	Datasets []string `json:"datasetNames"`
	// Status of the query result.
	Status Status `json:"status"`
	// Matches are the events that matched the query.
	Matches []Entry `json:"matches"`
	// Buckets are the time series buckets.
	Buckets Timeseries `json:"buckets"`
	// GroupBy is a list of field names to group the query result by. Only valid
	// when at least one aggregation is specified.
	GroupBy []string `json:"-"`
	// TraceID is the ID of the trace that was generated by the server for this
	// results query request.
	TraceID string `json:"-"`
}

Result is the result of an APL query.

type Status

type Status struct {
	// ElapsedTime is the duration it took the query to execute.
	ElapsedTime time.Duration `json:"elapsedTime"`
	// BlocksExamined is the amount of blocks that have been examined by the
	// query.
	BlocksExamined uint64 `json:"blocksExamined"`
	// RowsExamined is the amount of rows that have been examined by the query.
	RowsExamined uint64 `json:"rowsExamined"`
	// RowsMatched is the amount of rows that matched the query.
	RowsMatched uint64 `json:"rowsMatched"`
	// NumGroups is the amount of groups returned by the query.
	NumGroups uint32 `json:"numGroups"`
	// IsPartial describes if the query result is a partial result.
	IsPartial bool `json:"isPartial"`
	// ContinuationToken is populated when IsPartial is true and must be passed
	// to the next query request to retrieve the next result set.
	ContinuationToken string `json:"continuationToken"`
	// IsEstimate describes if the query result is estimated.
	IsEstimate bool `json:"isEstimate"`
	// MinBlockTime is the timestamp of the oldest block examined.
	MinBlockTime time.Time `json:"minBlockTime"`
	// MaxBlockTime is the timestamp of the newest block examined.
	MaxBlockTime time.Time `json:"maxBlockTime"`
	// Messages associated with the query.
	Messages []Message `json:"messages"`
	// MinCursor is the id of the oldest row, as seen server side. May be lower
	// than what the results include if the server scanned more data than
	// included in the results. Can be used to efficiently resume time-sorted
	// non-aggregating queries (i.e. filtering only).
	MinCursor string `json:"minCursor"`
	// MaxCursor is the id of the newest row, as seen server side. May be higher
	// than what the results include if the server scanned more data than
	// included in the results. Can be used to efficiently resume time-sorted
	// non-aggregating queries (i.e. filtering only).
	MaxCursor string `json:"maxCursor"`
}

Status is the status of a query result.

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It is in place to marshal the elapsed time into its microsecond representation because that's what the server expects.

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler. It is in place to unmarshal the elapsed time into a proper time.Duration value because the server returns it in microseconds.

type Timeseries

type Timeseries struct {
	// Series are the intervals that build a time series.
	Series []Interval `json:"series"`
	// Totals of the time series.
	Totals []EntryGroup `json:"totals"`
}

Timeseries are queried time series.

Jump to

Keyboard shortcuts

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