utils

package
v0.23.4 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTimeFieldWithRange added in v0.11.0

func AddTimeFieldWithRange(expr string, timeRange backend.TimeRange) string

AddTimeFieldWithRange adds time field with range to the query

func CalculateStep added in v0.8.0

func CalculateStep(minInterval time.Duration, timeRange backend.TimeRange, maxDataPoints int64) time.Duration

CalculateStep calculates step by provided max datapoints and timerange

func GetIntervalFrom added in v0.8.0

func GetIntervalFrom(dsInterval, queryInterval string, queryIntervalMS int64, defaultInterval time.Duration) (time.Duration, error)

GetIntervalFrom returns the minimum interval. dsInterval is the string representation of data source min interval, if configured. queryInterval is the string representation of query interval (min interval), e.g. "10ms" or "10s". queryIntervalMS is a pre-calculated numeric representation of the query interval in milliseconds.

func GetLocalTimezoneOffsetNsecs added in v0.19.0

func GetLocalTimezoneOffsetNsecs() int64

GetLocalTimezoneOffsetNsecs returns local timezone offset in nanoseconds. It accounts for DST automatically.

func GetTime

func GetTime(s string) (time.Time, error)

GetTime returns time from the given string.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses duration string in Prometheus format

func ParseTime

func ParseTime(s string) (float64, error)

ParseTime parses time s in different formats.

See https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#timestamp-formats

It returns unix timestamp in seconds.

func ParseTimeAt

func ParseTimeAt(s string, currentTimestamp float64) (float64, error)

ParseTimeAt parses time s in different formats, assuming the given currentTimestamp.

See https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#timestamp-formats

It returns unix timestamp in seconds.

func Ptr added in v0.20.0

func Ptr[T any](v T) *T

Ptr returns a pointer to the given value.

func ReplaceTemplateVariable added in v0.5.0

func ReplaceTemplateVariable(expr string, interval int64, timeRange backend.TimeRange) string

ReplaceTemplateVariable get query and use it expression to remove grafana template variables with

func TryParseTimestampRFC3339Nano added in v0.19.0

func TryParseTimestampRFC3339Nano(s string) (int64, bool)

TryParseTimestampRFC3339Nano parses s as RFC3339 with optional nanoseconds part and timezone offset and returns unix timestamp in nanoseconds.

If s doesn't contain timezone offset, then the local timezone is used.

The returned timestamp can be negative if s is smaller than 1970 year.x

func WithIntervalVariable added in v0.8.0

func WithIntervalVariable(expr string) bool

WithIntervalVariable checks if the expression contains interval variable

Types

type StreamField added in v0.16.1

type StreamField struct {
	Label string
	Value string
}

StreamField represents the label values pair of the _stream fields in the log struct

func ParseStreamFields added in v0.16.1

func ParseStreamFields(streamFields string) ([]StreamField, error)

ParseStreamFields collect labels values pair from the _stream field

Jump to

Keyboard shortcuts

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