query

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDatasourceType

func GetDatasourceType(ctx context.Context, cfg config.NamespacedRESTConfig, uid string) (string, error)

GetDatasourceType fetches datasource type from the API.

func NormalizeKind

func NormalizeKind(pluginID string) string

NormalizeKind converts a Grafana datasource plugin ID to its short kind name. Some plugins use the short name directly (e.g., "prometheus"), while others use a longer ID (e.g., "grafana-pyroscope-datasource"). If the plugin ID is not recognized, it is returned as-is.

func ParseDuration

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

ParseDuration parses a duration string that can be: - Go duration (e.g., "1h30m", "5m"). - Prometheus-style duration (e.g., "1h", "30m", "5s").

func ParseTime

func ParseTime(s string, now time.Time) (time.Time, error)

ParseTime parses a time string that can be either: - RFC3339 format (e.g., "2024-01-15T10:30:00Z"). - Unix timestamp (e.g., "1705315800"). - Relative time (e.g., "now", "now-1h", "now-30m", "now-7d").

func RegisterCodecs

func RegisterCodecs(ioOpts *cmdio.Options)

RegisterCodecs registers the table, wide, and graph codecs on the given IO options.

func ResolveDatasourceFlag

func ResolveDatasourceFlag(flagValue string, cfgCtx *config.Context, kind string) (string, error)

ResolveDatasourceFlag resolves a datasource UID from the -d flag value or config fallback. If flagValue is non-empty it is returned directly. Otherwise the UID is looked up from cfgCtx (the current context's datasources.<kind> config key). cfgCtx may be nil when config loading failed. If neither flag nor config provides a UID, an error is returned mentioning both the -d flag and the config key.

func ResolveTypedArgs

func ResolveTypedArgs(args []string, defaultUID string, kind string) (string, string, error)

ResolveTypedArgs parses positional args for typed subcommands. Typed subcommands accept: [DATASOURCE_UID] EXPR If only one arg is provided, it is EXPR and DATASOURCE_UID is resolved from defaultUID. If two args are provided, arg[0] is DATASOURCE_UID and arg[1] is EXPR.

func ValidateDatasourceType

func ValidateDatasourceType(actualType, expectedKind string) error

ValidateDatasourceType checks that the datasource's actual type matches the expected kind.

Types

type SharedOpts

type SharedOpts struct {
	TimeRangeOpts

	IO   cmdio.Options
	Step string
}

SharedOpts holds flags shared across typed query subcommands.

func (*SharedOpts) ParseTimes

func (opts *SharedOpts) ParseTimes(now time.Time) (time.Time, time.Time, time.Duration, error)

ParseTimes parses From/To/Step into time.Time and time.Duration values.

func (*SharedOpts) Setup

func (opts *SharedOpts) Setup(flags *pflag.FlagSet)

Setup registers shared query flags on the given flag set.

func (*SharedOpts) Validate

func (opts *SharedOpts) Validate() error

Validate validates shared flags and resolves --since into From/To.

type TimeRangeOpts

type TimeRangeOpts struct {
	From  string
	To    string
	Since string
}

TimeRangeOpts holds --from, --to, and --since flags for time range resolution. It can be embedded by any command that needs time range support without the full SharedOpts (e.g., traces get which has no Step or shared IO).

func (*TimeRangeOpts) IsRange

func (opts *TimeRangeOpts) IsRange() bool

IsRange returns true when both From and To are set, indicating a range query. It should be called after ValidateTimeRange() which resolves --since into From/To.

func (*TimeRangeOpts) ParseTimeRange

func (opts *TimeRangeOpts) ParseTimeRange(now time.Time) (time.Time, time.Time, error)

ParseTimeRange parses From/To into time.Time values.

func (*TimeRangeOpts) SetupTimeFlags

func (opts *TimeRangeOpts) SetupTimeFlags(flags *pflag.FlagSet)

SetupTimeFlags registers --from, --to, and --since flags on the given flag set.

func (*TimeRangeOpts) ValidateTimeRange

func (opts *TimeRangeOpts) ValidateTimeRange() error

ValidateTimeRange validates --from/--to pairing and resolves --since into From/To.

Jump to

Keyboard shortcuts

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