datasources

package
v0.2.13 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProvider added in v0.2.8

func RegisterProvider(dp DatasourceProvider)

RegisterProvider adds a datasource provider to the global registry. Panics if a provider with the same Kind() is already registered.

Types

type APIError added in v0.2.8

type APIError struct {
	Operation  string
	Identifier string
	StatusCode int
	Message    string
}

APIError is a typed error returned by the Grafana datasource REST API.

func NewAPIError added in v0.2.8

func NewAPIError(operation, identifier string, statusCode int, body []byte) *APIError

func (*APIError) APIServiceName added in v0.2.8

func (e *APIError) APIServiceName() string

func (*APIError) APIUserMessage added in v0.2.8

func (e *APIError) APIUserMessage() string

func (*APIError) Error added in v0.2.8

func (e *APIError) Error() string

func (*APIError) HTTPStatusCode added in v0.2.8

func (e *APIError) HTTPStatusCode() int

type Client

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

Client queries Grafana datasources via the NamespacedRESTConfig transport, ensuring OAuth proxy mode and token refresh are respected. It mirrors the approach used by internal/query/prometheus and internal/query/loki.

func NewClient

func NewClient(cfg config.NamespacedRESTConfig) (*Client, error)

NewClient creates a client backed by the given REST config's transport (including WrapTransport / RefreshTransport in OAuth proxy mode).

func (*Client) GetByName

func (c *Client) GetByName(ctx context.Context, name string) (*Datasource, error)

GetByName returns the datasource with the given display name.

func (*Client) GetByUID

func (c *Client) GetByUID(ctx context.Context, uid string) (*Datasource, error)

GetByUID returns the datasource with the given UID.

func (*Client) List

func (c *Client) List(ctx context.Context) ([]*Datasource, error)

List returns all datasources visible to the authenticated user.

type Datasource

type Datasource struct {
	UID             string `json:"uid"`
	Name            string `json:"name"`
	Type            string `json:"type"`
	URL             string `json:"url"`
	Access          string `json:"access"`
	IsDefault       bool   `json:"isDefault"`
	ReadOnly        bool   `json:"readOnly"`
	Database        string `json:"database"`
	BasicAuth       bool   `json:"basicAuth"`
	WithCredentials bool   `json:"withCredentials"`
	JSONData        any    `json:"jsonData"`
}

Datasource holds the fields returned by the legacy Grafana datasource REST API.

type DatasourceProvider added in v0.2.8

type DatasourceProvider interface {
	// Kind returns the datasource kind (e.g., "prometheus", "loki", "pyroscope", "tempo").
	Kind() string

	// ShortDesc returns a one-line description of the datasource provider.
	ShortDesc() string

	// QueryCmd returns the query subcommand. Every datasource must support querying.
	QueryCmd(loader *providers.ConfigLoader) *cobra.Command

	// ExtraCommands returns additional subcommands (labels, metrics, etc.).
	// Returns nil when the provider has no commands beyond query.
	ExtraCommands(loader *providers.ConfigLoader) []*cobra.Command
}

DatasourceProvider defines the interface for a datasource type plugin. Each implementation registers under `datasources $KIND` with its own set of subcommands - query is required, extra commands are optional.

The ConfigLoader is created and flag-bound by the mounting code in cmd/gcx/datasources/, so providers don't manage flag binding themselves.

func AllProviders added in v0.2.8

func AllProviders() []DatasourceProvider

AllProviders returns all registered datasource providers. Returns a non-nil empty slice when no providers have been registered.

Directories

Path Synopsis
Package providers registers DatasourceProvider implementations for built-in Grafana datasource types.
Package providers registers DatasourceProvider implementations for built-in Grafana datasource types.

Jump to

Keyboard shortcuts

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