sdk

package module
v0.0.0-...-58ddf24 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

Grafana Plugin SDK for Go

Warning: This SDK is currently in alpha and will likely have major breaking changes during early development. Please do not consider this SDK published until this warning has been removed.

Develop Grafana backend plugins with this Go SDK.

Usage

package main

import (
	"context"
	"log"
	"os"

	gf "github.com/grafana/grafana/pkg/plugins/sdk"
)

const pluginID = "myorg-custom-datasource"

type MyDataSource struct {
	logger *log.Logger
}

func (d *MyDataSource) Query(ctx context.Context, tr gf.TimeRange, ds gf.DataSourceInfo, queries []gf.Query) ([]gf.QueryResult, error) {
	return []gf.QueryResult{}, nil
}

func main() {
	logger := log.New(os.Stderr, "", 0)

	srv := gf.NewServer()

	srv.HandleDataSource(pluginID, &MyDataSource{
		logger: logger,
	})

	if err := srv.Serve(); err != nil {
		logger.Fatal(err)
	}
}

Developing

Generate Go code for Protobuf definitions:

make build-proto

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataSourceHandler

type DataSourceHandler interface {
	Query(ctx context.Context, tr TimeRange, ds DataSourceInfo, queries []Query) ([]QueryResult, error)
}

DataSourceHandler handles data source queries.

type DataSourceInfo

type DataSourceInfo struct {
	ID       int64
	OrgID    int64
	Name     string
	Type     string
	URL      string
	JSONData json.RawMessage
}

DataSourceInfo holds metadata for the queried data source.

type Query

type Query struct {
	RefID         string
	MaxDataPoints int64
	Interval      time.Duration
	ModelJSON     json.RawMessage
}

Query represents the query as sent from the frontend.

type QueryResult

type QueryResult struct {
	Error      string
	RefID      string
	MetaJSON   string
	DataFrames []*dataframe.Frame
}

QueryResult holds the results for a given query.

type Server

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

Server serves all registered data source handlers.

func NewServer

func NewServer() *Server

NewServer returns a new instance of Server.

func (*Server) HandleDataSource

func (g *Server) HandleDataSource(pluginID string, p DataSourceHandler)

HandleDataSource registers a new data source.

The plugin ID should be in the format <org>-<name>-datasource.

func (*Server) Serve

func (g *Server) Serve() error

Serve starts serving the registered handlers over gRPC.

type TimeRange

type TimeRange struct {
	From time.Time
	To   time.Time
}

TimeRange represents a time range for a query.

Directories

Path Synopsis
genproto

Jump to

Keyboard shortcuts

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