* Add lint rules * Backend decoupling - Add standalone files - Add graphite query type - Add logger to Service - Create logger in the ProvideService method - Use a pointer for the HTTP client provider - Update logger usage everywhere - Update tracer type - Replace simplejson with json - Add dummy CallResource and CheckHealth methods - Update tests * Update ConfigEditor imports * Update types imports * Update datasource - Switch to using semver package - Update imports * Update store imports * Update helper imports and notification creation * Update context import * Update version numbers and logic * Copy array_move from core * Test updates * Add required files and update plugin.json * Update core references and packages * Remove commented code * Update wire * Lint * Fix import * Copy null type * More lint * Update snapshot * Add tests * Review * Fix packages
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/tracing"
|
|
graphite "github.com/grafana/grafana/pkg/tsdb/graphite"
|
|
)
|
|
|
|
var (
|
|
_ backend.QueryDataHandler = (*Datasource)(nil)
|
|
_ backend.CheckHealthHandler = (*Datasource)(nil)
|
|
_ backend.CallResourceHandler = (*Datasource)(nil)
|
|
)
|
|
|
|
func NewDatasource(context.Context, backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
|
return &Datasource{
|
|
Service: graphite.ProvideService(httpclient.NewProvider(), tracing.DefaultTracer()),
|
|
}, nil
|
|
}
|
|
|
|
type Datasource struct {
|
|
Service *graphite.Service
|
|
}
|
|
|
|
func contextualMiddlewares(ctx context.Context) context.Context {
|
|
cfg := backend.GrafanaConfigFromContext(ctx)
|
|
return httpclient.WithContextualMiddleware(ctx, httpclient.ResponseLimitMiddleware(cfg.ResponseLimit()))
|
|
}
|
|
|
|
func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
|
ctx = contextualMiddlewares(ctx)
|
|
return d.Service.QueryData(ctx, req)
|
|
}
|
|
|
|
func (d *Datasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
|
|
ctx = contextualMiddlewares(ctx)
|
|
return d.Service.CallResource(ctx, req, sender)
|
|
}
|
|
|
|
func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
|
ctx = contextualMiddlewares(ctx)
|
|
return d.Service.CheckHealth(ctx, req)
|
|
}
|