Documentation ¶
Overview ¶
Package backend provides SDK handler interfaces and contracts for implementing and serving backend plugins.
Index ¶
- Constants
- Variables
- func Serve(opts ServeOpts) error
- func SetupPluginEnvironment(pluginID string)
- func StandaloneServe(dsopts ServeOpts, address string) error
- type AppInstanceSettings
- type CallResourceHandler
- type CallResourceHandlerFunc
- type CallResourceRequest
- type CallResourceResponse
- type CallResourceResponseSender
- type CheckHealthHandler
- type CheckHealthHandlerFunc
- type CheckHealthRequest
- type CheckHealthResult
- type CollectMetricsHandler
- type CollectMetricsHandlerFunc
- type CollectMetricsResult
- type ConvertFromProtobuf
- func (f ConvertFromProtobuf) AppInstanceSettings(proto *pluginv2.AppInstanceSettings) *AppInstanceSettings
- func (f ConvertFromProtobuf) CallResourceRequest(protoReq *pluginv2.CallResourceRequest) *CallResourceRequest
- func (f ConvertFromProtobuf) CallResourceResponse(protoResp *pluginv2.CallResourceResponse) *CallResourceResponse
- func (f ConvertFromProtobuf) CheckHealthRequest(protoReq *pluginv2.CheckHealthRequest) *CheckHealthRequest
- func (f ConvertFromProtobuf) CheckHealthResponse(protoResp *pluginv2.CheckHealthResponse) *CheckHealthResult
- func (f ConvertFromProtobuf) CollectMetricsResponse(protoResp *pluginv2.CollectMetricsResponse) *CollectMetricsResult
- func (f ConvertFromProtobuf) DataQuery(proto *pluginv2.DataQuery) *DataQuery
- func (f ConvertFromProtobuf) DataSourceInstanceSettings(proto *pluginv2.DataSourceInstanceSettings) *DataSourceInstanceSettings
- func (f ConvertFromProtobuf) PluginContext(proto *pluginv2.PluginContext) PluginContext
- func (f ConvertFromProtobuf) PublishStreamRequest(protoReq *pluginv2.PublishStreamRequest) *PublishStreamRequest
- func (f ConvertFromProtobuf) PublishStreamResponse(protoReq *pluginv2.PublishStreamResponse) *PublishStreamResponse
- func (f ConvertFromProtobuf) QueryDataRequest(protoReq *pluginv2.QueryDataRequest) *QueryDataRequest
- func (f ConvertFromProtobuf) QueryDataResponse(protoRes *pluginv2.QueryDataResponse) (*QueryDataResponse, error)
- func (f ConvertFromProtobuf) RunStreamRequest(protoReq *pluginv2.RunStreamRequest) *RunStreamRequest
- func (f ConvertFromProtobuf) StreamPacket(protoReq *pluginv2.StreamPacket) *StreamPacket
- func (f ConvertFromProtobuf) SubscribeStreamRequest(protoReq *pluginv2.SubscribeStreamRequest) *SubscribeStreamRequest
- func (f ConvertFromProtobuf) SubscribeStreamResponse(protoReq *pluginv2.SubscribeStreamResponse) *SubscribeStreamResponse
- func (f ConvertFromProtobuf) TimeRange(proto *pluginv2.TimeRange) TimeRange
- func (f ConvertFromProtobuf) User(user *pluginv2.User) *User
- type ConvertToProtobuf
- func (t ConvertToProtobuf) AppInstanceSettings(s *AppInstanceSettings) *pluginv2.AppInstanceSettings
- func (t ConvertToProtobuf) CallResourceRequest(req *CallResourceRequest) *pluginv2.CallResourceRequest
- func (t ConvertToProtobuf) CallResourceResponse(resp *CallResourceResponse) *pluginv2.CallResourceResponse
- func (t ConvertToProtobuf) CheckHealthResponse(res *CheckHealthResult) *pluginv2.CheckHealthResponse
- func (t ConvertToProtobuf) DataQuery(q DataQuery) *pluginv2.DataQuery
- func (t ConvertToProtobuf) DataSourceInstanceSettings(s *DataSourceInstanceSettings) *pluginv2.DataSourceInstanceSettings
- func (t ConvertToProtobuf) HealthStatus(status HealthStatus) pluginv2.CheckHealthResponse_HealthStatus
- func (t ConvertToProtobuf) PluginContext(pluginCtx PluginContext) *pluginv2.PluginContext
- func (t ConvertToProtobuf) PublishStreamRequest(req *PublishStreamRequest) *pluginv2.PublishStreamRequest
- func (t ConvertToProtobuf) PublishStreamResponse(req *PublishStreamResponse) *pluginv2.PublishStreamResponse
- func (t ConvertToProtobuf) QueryDataRequest(req *QueryDataRequest) *pluginv2.QueryDataRequest
- func (t ConvertToProtobuf) QueryDataResponse(res *QueryDataResponse) (*pluginv2.QueryDataResponse, error)
- func (t ConvertToProtobuf) RunStreamRequest(req *RunStreamRequest) *pluginv2.RunStreamRequest
- func (t ConvertToProtobuf) StreamPacket(p *StreamPacket) *pluginv2.StreamPacket
- func (t ConvertToProtobuf) SubscribeStreamRequest(req *SubscribeStreamRequest) *pluginv2.SubscribeStreamRequest
- func (t ConvertToProtobuf) SubscribeStreamResponse(req *SubscribeStreamResponse) *pluginv2.SubscribeStreamResponse
- func (t ConvertToProtobuf) TimeRange(tr TimeRange) *pluginv2.TimeRange
- func (t ConvertToProtobuf) User(user *User) *pluginv2.User
- type DataQuery
- type DataResponse
- type DataSourceInstanceSettings
- type GRPCSettings
- type HealthStatus
- type PluginContext
- type PublishStreamRequest
- type PublishStreamResponse
- type PublishStreamStatus
- type QueryDataHandler
- type QueryDataHandlerFunc
- type QueryDataRequest
- type QueryDataResponse
- type Responses
- type RunStreamRequest
- type ServeOpts
- type StreamHandler
- type StreamPacket
- type StreamPacketSender
- type SubscribeStreamRequest
- type SubscribeStreamResponse
- type SubscribeStreamStatus
- type TimeRange
- type User
Constants ¶
const ( // PluginProfilerEnv is a constant for the GF_PLUGINS_PROFILER environment variable used to enable pprof. PluginProfilerEnv = "GF_PLUGINS_PROFILER" // PluginProfilerPortEnv is a constant for the GF_PLUGINS_PROFILER_PORT environment variable use to specify a pprof port (default 6060). PluginProfilerPortEnv = "GF_PLUGINS_PROFILER_PORT" )
const ( // SubscribeStreamStatusOK means subscription is allowed. SubscribeStreamStatusOK SubscribeStreamStatus = 0 // SubscribeStreamStatusNotFound means stream does not exist at all. SubscribeStreamStatusNotFound = 1 // SubscribeStreamStatusPermissionDenied means that user is not allowed to subscribe. SubscribeStreamStatusPermissionDenied = 2 )
const ( // PublishStreamStatusOK means publication is allowed. PublishStreamStatusOK PublishStreamStatus = 0 // PublishStreamStatusNotFound means stream does not exist at all. PublishStreamStatusNotFound = 1 // PublishStreamStatusPermissionDenied means that user is not allowed to publish. PublishStreamStatusPermissionDenied = 2 )
Variables ¶
var Logger = log.DefaultLogger
Logger is the default logger instance. This can be used directly to log from your plugin to grafana-server with calls like backend.Logger.Debug(...).
Functions ¶
func SetupPluginEnvironment ¶ added in v0.29.0
func SetupPluginEnvironment(pluginID string)
SetupPluginEnvironment will read the environment variables and apply the standard environment behavior.
As the SDK evolves, this will likely change.
Currently this function enables and configures profiling with pprof.
func StandaloneServe ¶ added in v0.92.0
StandaloneServe starts a gRPC server that is not managed by hashicorp
Types ¶
type AppInstanceSettings ¶ added in v0.54.0
type AppInstanceSettings struct { // JSONData repeats the properties at this level of the object (excluding DataSourceConfig), and also includes any // custom properties associated with the plugin config instance. JSONData json.RawMessage // DecryptedSecureJSONData contains key,value pairs where the encrypted configuration plugin instance in Grafana // server have been decrypted before passing them to the plugin. DecryptedSecureJSONData map[string]string // Updated is the last time this plugin instance's configuration was updated. Updated time.Time }
AppInstanceSettings represents settings for an app instance.
In Grafana an app instance is an app plugin of certain type that have been configured and enabled in a Grafana organization.
type CallResourceHandler ¶
type CallResourceHandler interface {
CallResource(ctx context.Context, req *CallResourceRequest, sender CallResourceResponseSender) error
}
CallResourceHandler handles resource calls.
type CallResourceHandlerFunc ¶ added in v0.61.0
type CallResourceHandlerFunc func(ctx context.Context, req *CallResourceRequest, sender CallResourceResponseSender) error
CallResourceHandlerFunc is an adapter to allow the use of ordinary functions as backend.CallResourceHandler. If f is a function with the appropriate signature, CallResourceHandlerFunc(f) is a Handler that calls f.
func (CallResourceHandlerFunc) CallResource ¶ added in v0.61.0
func (fn CallResourceHandlerFunc) CallResource(ctx context.Context, req *CallResourceRequest, sender CallResourceResponseSender) error
CallResource calls fn(ctx, req, sender).
type CallResourceRequest ¶
type CallResourceRequest struct { PluginContext PluginContext Path string Method string URL string Headers map[string][]string Body []byte }
CallResourceRequest represents a request for a resource call.
type CallResourceResponse ¶
CallResourceResponse represents a response from a resource call.
type CallResourceResponseSender ¶
type CallResourceResponseSender interface {
Send(*CallResourceResponse) error
}
CallResourceResponseSender is used for sending resource call responses.
type CheckHealthHandler ¶
type CheckHealthHandler interface {
CheckHealth(ctx context.Context, req *CheckHealthRequest) (*CheckHealthResult, error)
}
CheckHealthHandler enables users to send health check requests to a backend plugin
type CheckHealthHandlerFunc ¶ added in v0.61.0
type CheckHealthHandlerFunc func(ctx context.Context, req *CheckHealthRequest) (*CheckHealthResult, error)
CheckHealthHandlerFunc is an adapter to allow the use of ordinary functions as backend.CheckHealthHandler. If f is a function with the appropriate signature, CheckHealthHandlerFunc(f) is a Handler that calls f.
func (CheckHealthHandlerFunc) CheckHealth ¶ added in v0.61.0
func (fn CheckHealthHandlerFunc) CheckHealth(ctx context.Context, req *CheckHealthRequest) (*CheckHealthResult, error)
CheckHealth calls fn(ctx, req).
type CheckHealthRequest ¶
type CheckHealthRequest struct {
PluginContext PluginContext
}
CheckHealthRequest contains the healthcheck request
type CheckHealthResult ¶
type CheckHealthResult struct { Status HealthStatus Message string JSONDetails []byte }
CheckHealthResult contains the healthcheck response
type CollectMetricsHandler ¶ added in v0.67.0
type CollectMetricsHandler interface {
CollectMetrics(ctx context.Context) (*CollectMetricsResult, error)
}
CollectMetricsHandler handles metric collection.
type CollectMetricsHandlerFunc ¶ added in v0.67.0
type CollectMetricsHandlerFunc func(ctx context.Context) (*CollectMetricsResult, error)
CollectMetricsHandlerFunc is an adapter to allow the use of ordinary functions as backend.CollectMetricsHandler. If f is a function with the appropriate signature, CollectMetricsHandlerFunc(f) is a Handler that calls f.
func (CollectMetricsHandlerFunc) CollectMetrics ¶ added in v0.67.0
func (fn CollectMetricsHandlerFunc) CollectMetrics(ctx context.Context) (*CollectMetricsResult, error)
CollectMetrics calls fn(ctx, req).
type CollectMetricsResult ¶ added in v0.67.0
type CollectMetricsResult struct {
PrometheusMetrics []byte
}
CollectMetricsResult collect metrics result.
type ConvertFromProtobuf ¶ added in v0.54.0
type ConvertFromProtobuf struct{}
ConvertFromProtobuf has a collection of methods for converting from the autogenerated protobuf go code to our SDK objects. This object exists to attach a collection of conversion methods to.
This is used internally by the SDK and inside Grafana-server, plugin authors should not need this functionality.
func FromProto ¶ added in v0.54.0
func FromProto() ConvertFromProtobuf
FromProto returns a new ConvertFromProtobuf.
func (ConvertFromProtobuf) AppInstanceSettings ¶ added in v0.54.0
func (f ConvertFromProtobuf) AppInstanceSettings(proto *pluginv2.AppInstanceSettings) *AppInstanceSettings
AppInstanceSettings converts protobuf version of an AppInstanceSettings to the SDK version.
func (ConvertFromProtobuf) CallResourceRequest ¶ added in v0.54.0
func (f ConvertFromProtobuf) CallResourceRequest(protoReq *pluginv2.CallResourceRequest) *CallResourceRequest
CallResourceRequest converts protobuf version of a CallResourceRequest to the SDK version.
func (ConvertFromProtobuf) CallResourceResponse ¶ added in v0.67.0
func (f ConvertFromProtobuf) CallResourceResponse(protoResp *pluginv2.CallResourceResponse) *CallResourceResponse
CallResourceResponse converts protobuf version of a CallResourceResponse to the SDK version.
func (ConvertFromProtobuf) CheckHealthRequest ¶ added in v0.67.0
func (f ConvertFromProtobuf) CheckHealthRequest(protoReq *pluginv2.CheckHealthRequest) *CheckHealthRequest
CheckHealthRequest converts protobuf version of a CheckHealthRequest to the SDK version.
func (ConvertFromProtobuf) CheckHealthResponse ¶ added in v0.67.0
func (f ConvertFromProtobuf) CheckHealthResponse(protoResp *pluginv2.CheckHealthResponse) *CheckHealthResult
CheckHealthResponse converts protobuf version of a HealthCheckResponse to the SDK version.
func (ConvertFromProtobuf) CollectMetricsResponse ¶ added in v0.67.0
func (f ConvertFromProtobuf) CollectMetricsResponse(protoResp *pluginv2.CollectMetricsResponse) *CollectMetricsResult
CollectMetricsResponse converts protobuf version of a CollectMetricsResponse to the SDK version.
func (ConvertFromProtobuf) DataQuery ¶ added in v0.54.0
func (f ConvertFromProtobuf) DataQuery(proto *pluginv2.DataQuery) *DataQuery
DataQuery converts protobuf version of a DataQuery to the SDK version.
func (ConvertFromProtobuf) DataSourceInstanceSettings ¶ added in v0.54.0
func (f ConvertFromProtobuf) DataSourceInstanceSettings(proto *pluginv2.DataSourceInstanceSettings) *DataSourceInstanceSettings
DataSourceInstanceSettings converts protobuf version of a DataSourceInstanceSettings to the SDK version.
func (ConvertFromProtobuf) PluginContext ¶ added in v0.54.0
func (f ConvertFromProtobuf) PluginContext(proto *pluginv2.PluginContext) PluginContext
PluginContext converts protobuf version of a PluginContext to the SDK version.
func (ConvertFromProtobuf) PublishStreamRequest ¶ added in v0.91.0
func (f ConvertFromProtobuf) PublishStreamRequest(protoReq *pluginv2.PublishStreamRequest) *PublishStreamRequest
PublishStreamRequest ...
func (ConvertFromProtobuf) PublishStreamResponse ¶ added in v0.91.0
func (f ConvertFromProtobuf) PublishStreamResponse(protoReq *pluginv2.PublishStreamResponse) *PublishStreamResponse
PublishStreamResponse ...
func (ConvertFromProtobuf) QueryDataRequest ¶ added in v0.54.0
func (f ConvertFromProtobuf) QueryDataRequest(protoReq *pluginv2.QueryDataRequest) *QueryDataRequest
QueryDataRequest converts protobuf version of a QueryDataRequest to the SDK version.
func (ConvertFromProtobuf) QueryDataResponse ¶ added in v0.54.0
func (f ConvertFromProtobuf) QueryDataResponse(protoRes *pluginv2.QueryDataResponse) (*QueryDataResponse, error)
QueryDataResponse converts protobuf version of a QueryDataResponse to the SDK version.
func (ConvertFromProtobuf) RunStreamRequest ¶ added in v0.89.0
func (f ConvertFromProtobuf) RunStreamRequest(protoReq *pluginv2.RunStreamRequest) *RunStreamRequest
RunStreamRequest ...
func (ConvertFromProtobuf) StreamPacket ¶ added in v0.89.0
func (f ConvertFromProtobuf) StreamPacket(protoReq *pluginv2.StreamPacket) *StreamPacket
StreamPacket ...
func (ConvertFromProtobuf) SubscribeStreamRequest ¶ added in v0.91.0
func (f ConvertFromProtobuf) SubscribeStreamRequest(protoReq *pluginv2.SubscribeStreamRequest) *SubscribeStreamRequest
SubscribeStreamRequest ...
func (ConvertFromProtobuf) SubscribeStreamResponse ¶ added in v0.91.0
func (f ConvertFromProtobuf) SubscribeStreamResponse(protoReq *pluginv2.SubscribeStreamResponse) *SubscribeStreamResponse
SubscribeStreamResponse ...
type ConvertToProtobuf ¶ added in v0.54.0
type ConvertToProtobuf struct{}
ConvertToProtobuf has a collection of methods for converting the autogenerated protobuf go code to our SDK objects. This object exists to attach a collection of conversion methods to.
This is used internally by the SDK and inside Grafana-server, plugin authors should not need this functionality.
func ToProto ¶ added in v0.54.0
func ToProto() ConvertToProtobuf
ToProto returns a new ConvertToProtobuf.
func (ConvertToProtobuf) AppInstanceSettings ¶ added in v0.54.0
func (t ConvertToProtobuf) AppInstanceSettings(s *AppInstanceSettings) *pluginv2.AppInstanceSettings
AppInstanceSettings converts the SDK version of an AppInstanceSettings to the protobuf version.
func (ConvertToProtobuf) CallResourceRequest ¶ added in v0.54.0
func (t ConvertToProtobuf) CallResourceRequest(req *CallResourceRequest) *pluginv2.CallResourceRequest
CallResourceRequest converts the SDK version of a CallResourceRequest to the protobuf version.
func (ConvertToProtobuf) CallResourceResponse ¶ added in v0.54.0
func (t ConvertToProtobuf) CallResourceResponse(resp *CallResourceResponse) *pluginv2.CallResourceResponse
CallResourceResponse converts the SDK version of a CallResourceResponse to the protobuf version.
func (ConvertToProtobuf) CheckHealthResponse ¶ added in v0.54.0
func (t ConvertToProtobuf) CheckHealthResponse(res *CheckHealthResult) *pluginv2.CheckHealthResponse
CheckHealthResponse converts the SDK version of a CheckHealthResponse to the protobuf version.
func (ConvertToProtobuf) DataQuery ¶ added in v0.54.0
func (t ConvertToProtobuf) DataQuery(q DataQuery) *pluginv2.DataQuery
DataQuery converts the SDK version of a DataQuery to the protobuf version.
func (ConvertToProtobuf) DataSourceInstanceSettings ¶ added in v0.54.0
func (t ConvertToProtobuf) DataSourceInstanceSettings(s *DataSourceInstanceSettings) *pluginv2.DataSourceInstanceSettings
DataSourceInstanceSettings converts the SDK version of a DataSourceInstanceSettings to the protobuf version.
func (ConvertToProtobuf) HealthStatus ¶ added in v0.54.0
func (t ConvertToProtobuf) HealthStatus(status HealthStatus) pluginv2.CheckHealthResponse_HealthStatus
HealthStatus converts the SDK version of a HealthStatus to the protobuf version.
func (ConvertToProtobuf) PluginContext ¶ added in v0.54.0
func (t ConvertToProtobuf) PluginContext(pluginCtx PluginContext) *pluginv2.PluginContext
PluginContext converts the SDK version of a PluginContext to the protobuf version.
func (ConvertToProtobuf) PublishStreamRequest ¶ added in v0.91.0
func (t ConvertToProtobuf) PublishStreamRequest(req *PublishStreamRequest) *pluginv2.PublishStreamRequest
PublishStreamRequest ...
func (ConvertToProtobuf) PublishStreamResponse ¶ added in v0.91.0
func (t ConvertToProtobuf) PublishStreamResponse(req *PublishStreamResponse) *pluginv2.PublishStreamResponse
PublishStreamResponse ...
func (ConvertToProtobuf) QueryDataRequest ¶ added in v0.54.0
func (t ConvertToProtobuf) QueryDataRequest(req *QueryDataRequest) *pluginv2.QueryDataRequest
QueryDataRequest converts the SDK version of a QueryDataRequest to the protobuf version.
func (ConvertToProtobuf) QueryDataResponse ¶ added in v0.54.0
func (t ConvertToProtobuf) QueryDataResponse(res *QueryDataResponse) (*pluginv2.QueryDataResponse, error)
QueryDataResponse converts the SDK version of a QueryDataResponse to the protobuf version. It will set the RefID on the frames to the RefID key in Responses if a Frame's RefId property is an empty string.
func (ConvertToProtobuf) RunStreamRequest ¶ added in v0.89.0
func (t ConvertToProtobuf) RunStreamRequest(req *RunStreamRequest) *pluginv2.RunStreamRequest
RunStreamRequest ...
func (ConvertToProtobuf) StreamPacket ¶ added in v0.89.0
func (t ConvertToProtobuf) StreamPacket(p *StreamPacket) *pluginv2.StreamPacket
StreamPacket ...
func (ConvertToProtobuf) SubscribeStreamRequest ¶ added in v0.91.0
func (t ConvertToProtobuf) SubscribeStreamRequest(req *SubscribeStreamRequest) *pluginv2.SubscribeStreamRequest
SubscribeStreamRequest ...
func (ConvertToProtobuf) SubscribeStreamResponse ¶ added in v0.91.0
func (t ConvertToProtobuf) SubscribeStreamResponse(req *SubscribeStreamResponse) *pluginv2.SubscribeStreamResponse
SubscribeStreamResponse ...
type DataQuery ¶
type DataQuery struct { // RefID is the unique identifier of the query, set by the frontend call. RefID string // QueryType is an optional identifier for the type of query. // It can be used to distinguish different types of queries. QueryType string // MaxDataPoints is the maximum number of datapoints that should be returned from a time series query. MaxDataPoints int64 // Interval is the suggested duration between time points in a time series query. Interval time.Duration // TimeRange is the Start and End of the query as sent by the frontend. TimeRange TimeRange // JSON is the raw JSON query and includes the above properties as well as custom properties. JSON json.RawMessage }
DataQuery represents a single query as sent from the frontend. A slice of DataQuery makes up the Queries property of a QueryDataRequest.
type DataResponse ¶ added in v0.35.0
type DataResponse struct { // The data returned from the Query. Each Frame repeats the RefID. Frames data.Frames // Error is a property to be set if the the corresponding DataQuery has an error. Error error }
DataResponse contains the results from a DataQuery. A map of RefIDs (unique query identifers) to this type makes up the Responses property of a QueryDataResponse. The Error property is used to allow for partial success responses from the containing QueryDataResponse.
func FrameResponse ¶ added in v0.80.0
func FrameResponse(f data.Framer) *DataResponse
FrameResponse creates a DataResponse that contains the Framer's data.Frames.
func FrameResponseWithError ¶ added in v0.80.0
func FrameResponseWithError(f data.Framer, err error) *DataResponse
FrameResponseWithError creates a DataResponse with the error's contents (if not nil), and the Framer's data.Frames. This function is particularly useful if you have a function that returns `(StructX, error)`, where StructX implements Framer, which is a very common pattern.
func (DataResponse) MarshalJSON ¶ added in v0.90.0
func (r DataResponse) MarshalJSON() ([]byte, error)
MarshalJSON writes the results as json
type DataSourceInstanceSettings ¶ added in v0.54.0
type DataSourceInstanceSettings struct { // ID is the Grafana assigned numeric identifier of the the data source instance. ID int64 // UID is the Grafana assigned string identifier of the the data source instance. UID string // Name is the configured name of the data source instance. Name string // URL is the configured URL of a data source instance (e.g. the URL of an API endpoint). URL string // User is a configured user for a data source instance. This is not a Grafana user, rather an arbitrary string. User string // Database is the configured database for a data source instance. (e.g. the default Database a SQL data source would connect to). Database string // BasicAuthEnabled indicates if this data source instance should use basic authentication. BasicAuthEnabled bool // BasicAuthUser is the configured user for basic authentication. (e.g. when a data source uses basic // authentication to connect to whatever API it fetches data from). BasicAuthUser string // JSONData contains the raw DataSourceConfig as JSON as stored by Grafana server. It repeats the properties in // this object and includes custom properties. JSONData json.RawMessage // DecryptedSecureJSONData contains key,value pairs where the encrypted configuration in Grafana server have been // decrypted before passing them to the plugin. DecryptedSecureJSONData map[string]string // Updated is the last time the configuration for the data source instance was updated. Updated time.Time }
DataSourceInstanceSettings represents settings for a data source instance.
In Grafana a data source instance is a data source plugin of certain type that have been configured and created in a Grafana organization.
type GRPCSettings ¶ added in v0.61.0
type GRPCSettings struct { // MaxReceiveMsgSize the max gRPC message size in bytes the plugin can receive. // If this is <= 0, gRPC uses the default 16MB. MaxReceiveMsgSize int // MaxSendMsgSize the max gRPC message size in bytes the plugin can send. // If this is <= 0, gRPC uses the default `math.MaxInt32`. MaxSendMsgSize int }
GRPCSettings settings for gRPC.
type HealthStatus ¶
type HealthStatus int
HealthStatus is the status of the plugin.
const ( // HealthStatusUnknown means the status of the plugin is unknown. HealthStatusUnknown HealthStatus = iota // HealthStatusOk means the status of the plugin is good. HealthStatusOk // HealthStatusError means the plugin is in an error state. HealthStatusError )
func (HealthStatus) String ¶ added in v0.67.0
func (hs HealthStatus) String() string
String textual represntation of the status.
type PluginContext ¶ added in v0.54.0
type PluginContext struct { // OrgID is The Grafana organization identifier the request originating from. OrgID int64 // PluginID is the unique identifier of the plugin that the request is for. PluginID string // User is the Grafana user making the request. // // Will not be provided if Grafana backend initiated the request, // for example when request is coming from Grafana Alerting. User *User // AppInstanceSettings is the configured app instance settings. // // In Grafana an app instance is an app plugin of certain // type that have been configured and enabled in a Grafana organization. // // Will only be set if request targeting an app instance. AppInstanceSettings *AppInstanceSettings // DataSourceConfig is the configured data source instance // settings. // // In Grafana a data source instance is a data source plugin of certain // type that have been configured and created in a Grafana organization. // // Will only be set if request targeting a data source instance. DataSourceInstanceSettings *DataSourceInstanceSettings }
PluginContext holds contextual information about a plugin request, such as Grafana organization, user and plugin instance settings.
type PublishStreamRequest ¶ added in v0.91.0
type PublishStreamRequest struct { PluginContext PluginContext Path string Data json.RawMessage }
PublishStreamRequest is EXPERIMENTAL and is a subject to change till Grafana 8.
type PublishStreamResponse ¶ added in v0.91.0
type PublishStreamResponse struct { Status PublishStreamStatus Data json.RawMessage }
PublishStreamResponse is EXPERIMENTAL and is a subject to change till Grafana 8.
type PublishStreamStatus ¶ added in v0.91.0
type PublishStreamStatus int32
PublishStreamStatus is a status of publication response.
type QueryDataHandler ¶
type QueryDataHandler interface { // QueryData handles multiple queries and returns multiple responses. // req contains the queries []DataQuery (where each query contains RefID as a unique identifier). // The QueryDataResponse contains a map of RefID to the response for each query, and each response // contains Frames ([]*Frame). // // The Frames' RefID property, when it is an empty string, will be automatically set to // the RefID in QueryDataResponse.Responses map. This is done before the QueryDataResponse is // sent to Grafana. Therefore one does not need to be set that property on frames when using this method. QueryData(ctx context.Context, req *QueryDataRequest) (*QueryDataResponse, error) }
QueryDataHandler handles data queries.
type QueryDataHandlerFunc ¶ added in v0.61.0
type QueryDataHandlerFunc func(ctx context.Context, req *QueryDataRequest) (*QueryDataResponse, error)
QueryDataHandlerFunc is an adapter to allow the use of ordinary functions as backend.QueryDataHandler. If f is a function with the appropriate signature, QueryDataHandlerFunc(f) is a Handler that calls f.
func (QueryDataHandlerFunc) QueryData ¶ added in v0.61.0
func (fn QueryDataHandlerFunc) QueryData(ctx context.Context, req *QueryDataRequest) (*QueryDataResponse, error)
QueryData calls fn(ctx, req).
type QueryDataRequest ¶
type QueryDataRequest struct { PluginContext PluginContext Headers map[string]string Queries []DataQuery }
QueryDataRequest contains a single request which contains multiple queries. It is the input type for a QueryData call.
type QueryDataResponse ¶
type QueryDataResponse struct { // Responses is a map of RefIDs (Unique Query ID) to *DataResponse. Responses Responses }
QueryDataResponse contains the results from a QueryDataRequest. It is the return type of a QueryData call.
func NewQueryDataResponse ¶ added in v0.42.0
func NewQueryDataResponse() *QueryDataResponse
NewQueryDataResponse returns a QueryDataResponse with the Responses property initialized.
func (QueryDataResponse) MarshalJSON ¶ added in v0.90.0
func (r QueryDataResponse) MarshalJSON() ([]byte, error)
MarshalJSON writes the results as json
func (*QueryDataResponse) UnmarshalJSON ¶ added in v0.90.0
func (r *QueryDataResponse) UnmarshalJSON(b []byte) error
UnmarshalJSON will read JSON into a QueryDataResponse
type Responses ¶ added in v0.42.0
type Responses map[string]DataResponse
Responses is a map of RefIDs (Unique Query ID) to DataResponses. The QueryData method the QueryDataHandler method will set the RefId property on the DataRespones' frames based on these RefIDs.
type RunStreamRequest ¶ added in v0.89.0
type RunStreamRequest struct { PluginContext PluginContext Path string }
RunStreamRequest is EXPERIMENTAL and is a subject to change till Grafana 8.
type ServeOpts ¶
type ServeOpts struct { // CheckHealthHandler handler for health checks. CheckHealthHandler CheckHealthHandler // CallResourceHandler handler for resource calls. // Optional to implement. CallResourceHandler CallResourceHandler // QueryDataHandler handler for data queries. // Required to implement if data source. QueryDataHandler QueryDataHandler // StreamHandler handler for streaming queries. // This is EXPERIMENTAL and is a subject to change till Grafana 8. StreamHandler StreamHandler // GRPCSettings settings for gPRC. GRPCSettings GRPCSettings }
ServeOpts options for serving plugins.
type StreamHandler ¶ added in v0.89.0
type StreamHandler interface { // SubscribeStream called when a user tries to subscribe to a plugin/datasource // managed channel path – thus plugin can check subscribe permissions and communicate // options with Grafana Core. SubscribeStream(context.Context, *SubscribeStreamRequest) (*SubscribeStreamResponse, error) // PublishStream called when a user tries to publish to a plugin/datasource // managed channel path. Here plugin can check publish permissions and // modify publication data if required. PublishStream(context.Context, *PublishStreamRequest) (*PublishStreamResponse, error) // RunStream will be initiated by Grafana to consume a stream where use_run_stream // option set to true. In this case RunStream will only be called once for the // first client successfully subscribed to a channel path. When Grafana detects // that there are no longer any subscribers inside a channel, the call will be // terminated until next active subscriber appears. Call termination can happen // with a delay. RunStream(context.Context, *RunStreamRequest, StreamPacketSender) error }
StreamHandler handles streams. This is EXPERIMENTAL and is a subject to change till Grafana 8.
type StreamPacket ¶ added in v0.89.0
type StreamPacket struct {
Data json.RawMessage
}
StreamPacket is EXPERIMENTAL and is a subject to change till Grafana 8.
type StreamPacketSender ¶ added in v0.89.0
type StreamPacketSender interface {
Send(*StreamPacket) error
}
StreamPacketSender is EXPERIMENTAL and is a subject to change till Grafana 8.
type SubscribeStreamRequest ¶ added in v0.91.0
type SubscribeStreamRequest struct { PluginContext PluginContext Path string }
SubscribeStreamRequest is EXPERIMENTAL and is a subject to change till Grafana 8.
type SubscribeStreamResponse ¶ added in v0.91.0
type SubscribeStreamResponse struct { Status SubscribeStreamStatus Data json.RawMessage UseRunStream bool }
SubscribeStreamResponse is EXPERIMENTAL and is a subject to change till Grafana 8.
type SubscribeStreamStatus ¶ added in v0.91.0
type SubscribeStreamStatus int32
SubscribeStreamStatus is a status of subscription response.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package datasource provides utilities for creating and serving a data source plugin over gRPC.
|
Package datasource provides utilities for creating and serving a data source plugin over gRPC. |
Package grpcplugin provides support for serving plugin over gRPC.
|
Package grpcplugin provides support for serving plugin over gRPC. |
Package instancemgmt provides utilities for managing plugin instances.
|
Package instancemgmt provides utilities for managing plugin instances. |
Package log provides a logging interface to send logs from plugins to Grafana server.
|
Package log provides a logging interface to send logs from plugins to Grafana server. |
Package resource provides utils for handling resource calls.
|
Package resource provides utils for handling resource calls. |
httpadapter
Package httpadapter provides support for handling resource calls using an http.Handler.
|
Package httpadapter provides support for handling resource calls using an http.Handler. |