Documentation
¶
Index ¶
- Constants
- func BuildExploreURL(host string, orgID int64, panes map[string]any, extra map[string]string) string
- func EncodeAndHandleExplore(cmd *cobra.Command, encode func() error, opts ExploreLinkOpts, ...) error
- func ExploreDatasource(dsType, uid string) map[string]any
- func ExploreMessages(subject string) (string, string)
- func ExploreRange(from, to string, instant bool) (string, string)
- func GetDatasourceType(ctx context.Context, cfg config.NamespacedRESTConfig, uid string) (string, error)
- func HandleExploreLink(cmd *cobra.Command, opts ExploreLinkOpts, url string, ...) error
- func NormalizeKind(pluginID string) string
- func OrgID(cfgCtx *config.Context) int64
- func ParseDuration(s string) (time.Duration, error)
- func ParseTime(s string, now time.Time) (time.Time, error)
- func RegisterCodecs(ioOpts *cmdio.Options, enableGraph bool)
- func ResolveAndSaveDatasource(ctx context.Context, saver DatasourceSaver, flagValue string, ...) (string, error)
- func ResolveDatasourceFlag(flagValue string, cfgCtx *config.Context, kind string) (string, error)
- func ResolveTypedArgs(args []string, defaultUID string, kind string) (string, string, error)
- func ShortExploreRange(from, to string) (string, string)
- func SinglePane(datasourceUID string, queries []any, from, to string, extra map[string]any) map[string]any
- func ValidateDatasourceType(actualType, expectedKind string) error
- type DatasourceResolution
- type DatasourceSaver
- type ExploreLink
- type ExploreLinkOpts
- type ExploreQuery
- type SharedOpts
- func (opts *SharedOpts) ParseTimes(now time.Time) (time.Time, time.Time, time.Duration, error)
- func (opts *SharedOpts) ResolveExpr(args []string, exprArgIndex int) (string, error)
- func (opts *SharedOpts) Setup(flags *pflag.FlagSet, enableGraph bool)
- func (opts *SharedOpts) SetupExprFlag(flags *pflag.FlagSet)
- func (opts *SharedOpts) Validate() error
- type TimeRangeOpts
Constants ¶
const DefaultExplorePaneID = "gcx"
const ( // DefaultLokiLimit is the default result cap for Loki queries when --limit // is not explicitly provided. A smaller value avoids overwhelming output; // use --limit 0 for no cap or --limit N for a custom value. DefaultLokiLimit = 50 )
Variables ¶
This section is empty.
Functions ¶
func BuildExploreURL ¶ added in v0.2.12
func BuildExploreURL(host string, orgID int64, panes map[string]any, extra map[string]string) string
BuildExploreURL renders the final Grafana Explore URL.
func EncodeAndHandleExplore ¶ added in v0.2.12
func EncodeAndHandleExplore(cmd *cobra.Command, encode func() error, opts ExploreLinkOpts, link ExploreLink) error
EncodeAndHandleExplore writes command output and then handles the optional Explore link side effects.
func ExploreDatasource ¶ added in v0.2.12
ExploreDatasource renders the datasource reference block expected by Explore.
func ExploreMessages ¶ added in v0.2.12
ExploreMessages returns the standard unavailable/open-failed messages for a successfully completed command subject.
func ExploreRange ¶ added in v0.2.12
ExploreRange normalizes the visible Explore time range.
func GetDatasourceType ¶
func GetDatasourceType(ctx context.Context, cfg config.NamespacedRESTConfig, uid string) (string, error)
GetDatasourceType fetches datasource type from the API.
func HandleExploreLink ¶ added in v0.2.12
func HandleExploreLink(cmd *cobra.Command, opts ExploreLinkOpts, url string, unavailableMsg, failedOpenMsg string) error
HandleExploreLink prints and/or opens a Grafana Explore URL. Missing URLs are warned about but do not fail the command after successful data retrieval.
func NormalizeKind ¶
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 ¶
ParseDuration delegates to dates.ParseDuration. Kept for backward compatibility with existing callers.
func ParseTime ¶
ParseTime delegates to dates.ParseTime. Kept for backward compatibility with existing callers.
func RegisterCodecs ¶
RegisterCodecs registers the table and wide codecs, plus graph when enabled, on the given IO options.
func ResolveAndSaveDatasource ¶ added in v0.2.3
func ResolveAndSaveDatasource(ctx context.Context, saver DatasourceSaver, flagValue string, cfgCtx *config.Context, restCfg config.NamespacedRESTConfig, kind string) (string, error)
ResolveAndSaveDatasource resolves a datasource UID and best-effort persists it to config when the resolver inferred it from cloud.stack.
func ResolveDatasourceFlag ¶
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 ¶
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 ShortExploreRange ¶ added in v0.2.12
ShortExploreRange normalizes the visible Explore time range using a short default lookback window when no explicit range was provided.
func SinglePane ¶ added in v0.2.12
func SinglePane(datasourceUID string, queries []any, from, to string, extra map[string]any) map[string]any
SinglePane renders a single Explore pane payload under the default pane ID.
func ValidateDatasourceType ¶
ValidateDatasourceType checks that the datasource's actual type matches the expected kind.
Types ¶
type DatasourceResolution ¶ added in v0.2.3
DatasourceResolution describes the outcome of datasource resolution.
func ResolveDatasource ¶ added in v0.2.3
func ResolveDatasource(ctx context.Context, flagValue string, cfgCtx *config.Context, restCfg config.NamespacedRESTConfig, kind string) (DatasourceResolution, error)
ResolveDatasource resolves a datasource UID from the -d flag, config fallback, or auto-discovery from Grafana when a single matching datasource is visible.
Resolution order:
- Explicit -d/--datasource flag.
- Context config via datasources.<kind> (or legacy default-*-datasource keys).
- Auto-discovery via /api/datasources when Grafana exposes a single matching datasource kind, or a canonical Grafana Cloud datasource name for the configured stack slug (from cloud.stack, GRAFANA_CLOUD_STACK, or grafana.server-derived cloud context).
type DatasourceSaver ¶ added in v0.2.3
DatasourceSaver persists an inferred datasource UID into config.
type ExploreLink ¶ added in v0.2.12
ExploreLink describes optional Grafana Explore link handling after a command succeeds.
type ExploreLinkOpts ¶ added in v0.2.12
type ExploreLinkOpts struct {
Open bool
}
ExploreLinkOpts controls optional Grafana Explore link output for query-like commands.
func (*ExploreLinkOpts) Enabled ¶ added in v0.2.12
func (opts *ExploreLinkOpts) Enabled() bool
Enabled reports whether either share/open behavior was requested.
type ExploreQuery ¶ added in v0.2.12
type ExploreQuery struct {
DatasourceUID string
DatasourceType string
Expr string
From string
To string
Instant bool
Step time.Duration
OrgID int64
}
ExploreQuery describes the query state encoded into a Grafana Explore URL.
type SharedOpts ¶
type SharedOpts struct {
}
SharedOpts holds flags shared across typed query subcommands.
func (*SharedOpts) ParseTimes ¶
ParseTimes parses From/To/Step into time.Time and time.Duration values.
func (*SharedOpts) ResolveExpr ¶ added in v0.2.6
func (opts *SharedOpts) ResolveExpr(args []string, exprArgIndex int) (string, error)
ResolveExpr resolves the query expression from either the --expr flag or a positional argument at exprArgIndex. Exactly one source must provide the expression.
func (*SharedOpts) Setup ¶
func (opts *SharedOpts) Setup(flags *pflag.FlagSet, enableGraph bool)
Setup registers shared query flags on the given flag set.
func (*SharedOpts) SetupExprFlag ¶ added in v0.2.6
func (opts *SharedOpts) SetupExprFlag(flags *pflag.FlagSet)
SetupExprFlag registers the --expr flag on the given flag set. Exposed separately from Setup for commands that register flags manually (e.g., logs query, profiles metrics).
func (*SharedOpts) Validate ¶
func (opts *SharedOpts) Validate() error
Validate validates shared flags and resolves --since into From/To.
type TimeRangeOpts ¶
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 ¶
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.