sdk

package module
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: Apache-2.0 Imports: 0 Imported by: 0

README

Grafana Plugin SDK for Go

Develop Grafana backend plugins with this Go SDK.

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.

Usage

package main

import (
	"context"
	"log"
	"os"

	gf "github.com/grafana/grafana-plugin-sdk-go"
)

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 protobuf
Changing generic_*.go files in the data package

Currently genny is used for generating some go code. If you make changes to generic template files then genny needs to be installed, and then mage dataGenerate. Changed generated files should be committed with the change in the template files.

Documentation

Overview

Package sdk is the root of the packages used to access Grafana Plugin SDK for Go. See https://pkg.go.dev/github.com/grafana/grafana-plugin-sdk-go for a full list of sub-packages.

Directories

Path Synopsis
Package backend provides SDK handler interfaces and contracts for implementing and serving backend plugins.
Package backend provides SDK handler interfaces and contracts for implementing and serving backend plugins.
grpcplugin
Package grpcplugin provides support for serving plugin over gRPC.
Package grpcplugin provides support for serving plugin over gRPC.
log
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.
resource/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.
Package data provides data structures that Grafana recognizes.
Package data provides data structures that Grafana recognizes.
sqlutil
Package sqlutil provides helpers for scanning database/sql responses into a data.Frame.
Package sqlutil provides helpers for scanning database/sql responses into a data.Frame.
Package experimental is a place where we include interfaces and structures that may be useful, but require additional testing and feedback before we think they should be added to the main SDK.
Package experimental is a place where we include interfaces and structures that may be useful, but require additional testing and feedback before we think they should be added to the main SDK.
genproto

Jump to

Keyboard shortcuts

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