mirror of
https://github.com/grafana/grafana.git
synced 2025-07-28 02:32:07 +08:00
Docs: Plugins doc reorganization, part 1 (#69864)
* Initial commit * Prettier fixes * Doc-validator fixes part 1 * Doc-validator fixes part 2 * More doc-validator fixes * More doc-validator fixes * Test * link test * Linnk test * Link test * More fixes * More fixes * Doc-validator fixes * Doc-validator fixes * fix broken link * Fix * Testing * Doc fixes * Link fixes * Fix links * Update docs/sources/developers/plugins/create-a-grafana-plugin/_index.md Co-authored-by: David Harris <david.harris@grafana.com> * Testing * Testing * Testing * Testing * Doc-validator fixes * Doc-validator fixes * Doc-validator fixes * Fix broken links for plugins reorganization project * Prettier fixes * Prettier fixes * Incorporate reviewer feedback * Link fixes * Link fixes * Link fixes * Link fix * Deleted space * Codeowners fix * Change grafana.com links to absolute URLs for Hugo --------- Co-authored-by: David Harris <david.harris@grafana.com>
This commit is contained in:
@ -0,0 +1,99 @@
|
||||
---
|
||||
title: Backend plugins
|
||||
aliases:
|
||||
- ../../plugins/developing/backend-plugins-guide/
|
||||
- ../../plugins/backend/
|
||||
keywords:
|
||||
- grafana
|
||||
- plugins
|
||||
- backend
|
||||
- plugin
|
||||
- backend-plugins
|
||||
- documentation
|
||||
description: Learn about the Grafana plugin system for backend development of Grafana integrations.
|
||||
---
|
||||
|
||||
# Backend plugins
|
||||
|
||||
The Grafana plugin system for backend development allows you to integrate Grafana with virtually anything and offer custom visualizations. This document explains the system's background, use cases, and key features.
|
||||
|
||||
## Background
|
||||
|
||||
Grafana added support for _frontend plugins_ in version 3.0 so that the Grafana community could create custom panels and data sources. It was wildly successful and has made Grafana much more useful for our user community.
|
||||
|
||||
However, one limitation of these plugins is that they run on the client side, in the browser. Therefore, they can't support use cases that require server-side features.
|
||||
|
||||
Since Grafana v7.0, we have supported server-side plugins that remove this limitation. We use the term _backend plugin_ to denote that a plugin has a backend component. A backend plugin usually requires frontend components as well. For example, some backend data source plugins need query editor components on the frontend.
|
||||
|
||||
## Use cases for implementing a backend plugin
|
||||
|
||||
The following examples give some common use cases for backend plugins:
|
||||
|
||||
- Enable [Grafana Alerting]({{< relref "../../../../alerting" >}}) for data sources.
|
||||
- Connect to SQL database servers and other non-HTTP services that normally can't be connected to from a browser.
|
||||
- Keep state between users, for example, by query caching for data sources.
|
||||
- Use custom authentication methods and/or authorization checks that aren't supported in Grafana.
|
||||
- Use a custom data source request proxy (refer to [Resources]({{< relref "#resources" >}}) for more information).
|
||||
|
||||
## Grafana backend plugin system
|
||||
|
||||
The Grafana backend plugin system is based on HashiCorp's [Go Plugin System over RPC](https://github.com/hashicorp/go-plugin). Our implementation of the Grafana server launches each backend plugin as a subprocess and communicates with it over [gRPC](https://grpc.io/).
|
||||
|
||||
### Benefits for plugin development
|
||||
|
||||
Grafana's approach has benefits for developers:
|
||||
|
||||
- **Stability:** Plugins can't crash your Grafana process: a panic in a plugin doesn't panic the server.
|
||||
- **Ease of development:** Plugins can be written in any language that supports gRPC (for example, write a Go application and run `go build`).
|
||||
- **Security:** Plugins only have access to the interfaces and arguments given to them, not to the entire memory space of the process.
|
||||
|
||||
### Capabilities of the backend plugin system
|
||||
|
||||
Grafana's backend plugin system exposes several key capabilities, or building blocks, that your backend plugin can implement:
|
||||
|
||||
- Query data
|
||||
- Resources
|
||||
- Health checks
|
||||
- Collect metrics
|
||||
- Streaming
|
||||
|
||||
#### Query data
|
||||
|
||||
The query data capability allows a backend plugin to handle data source queries that are submitted from a [dashboard]({{< relref "../../../../dashboards" >}}), [Explore]({{< relref "../../../../explore" >}}) or [Grafana Alerting]({{< relref "../../../../alerting" >}}). The response contains [data frames]({{< relref "../data-frames.md" >}}), which are used to visualize metrics, logs, and traces.
|
||||
|
||||
{{% admonition type="note" %}} Backend data source plugins are required to implement the query data capability.{{%
|
||||
/admonition %}}
|
||||
|
||||
#### Resources
|
||||
|
||||
The resources capability allows a backend plugin to handle custom HTTP requests sent to the Grafana HTTP API and respond with custom HTTP responses. Here, the request and response formats can vary. For example, you can use JSON, plain text, HTML, or static resources such as images and files, and so on.
|
||||
|
||||
Compared to the query data capability, where the response contains data frames, the resources capability gives the plugin developer more flexibility for extending and opening up Grafana for new and interesting use cases.
|
||||
|
||||
### Use cases
|
||||
|
||||
Examples of use cases for implementing resources:
|
||||
|
||||
- Implement a custom data source proxy to provide certain authentication, authorization, or other requirements that are not supported in Grafana's [built-in data proxy]({{< relref "../../../http_api/data_source#data-source-proxy-calls" >}}).
|
||||
- Return data or information in a format suitable for use within a data source query editor to provide auto-complete functionality.
|
||||
- Return static resources such as images or files.
|
||||
- Send a command to a device, such as a microcontroller or IoT device.
|
||||
- Request information from a device, such as a microcontroller or IoT device.
|
||||
- Extend Grafana's HTTP API with custom resources, methods and actions.
|
||||
- Use [chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) to return large data responses in chunks or to enable certain streaming capabilities.
|
||||
|
||||
#### Health checks
|
||||
|
||||
The health checks capability allows a backend plugin to return the status of the plugin. For data source backend plugins, the health check is automatically called when a user edits a data source and selects _Save & Test_ in the UI.
|
||||
|
||||
A plugin's health check endpoint is exposed in the Grafana HTTP API and allows external systems to continuously poll the plugin's health to make sure that it's running and working as expected.
|
||||
|
||||
#### Collect metrics
|
||||
|
||||
A backend plugin can collect and return runtime, process, and custom metrics using the text-based Prometheus [exposition format](https://prometheus.io/docs/instrumenting/exposition_formats/). If you're using the [Grafana Plugin SDK for Go]({{< relref "./grafana-plugin-sdk-for-go.md" >}}) to implement your backend plugin, then the [Prometheus instrumentation library for Go applications](https://github.com/prometheus/client_golang) is built-in. This SDK gives you Go runtime metrics and process metrics out of the box. You can use the [Prometheus instrumentation library](https://github.com/prometheus/client_golang) to add custom metrics to instrument your backend plugin.
|
||||
|
||||
The Grafana HTTP API offers an endpoint (`/api/plugins/<plugin id>/metrics`) that allows you to configure a Prometheus instance to scrape the metrics.
|
||||
|
||||
#### Streaming
|
||||
|
||||
The streaming capability allows a backend plugin to handle data source queries that are streaming. For more information, refer to [Build a streaming data source plugin]({{< relref "../../create-a-grafana-plugin/develop-a-plugin/build-a-streaming-data-source-plugin" >}}).
|
@ -0,0 +1,31 @@
|
||||
---
|
||||
title: Grafana plugin SDK for Go
|
||||
aliases:
|
||||
- ../../plugins/backend/grafana-plugin-sdk-for-go/
|
||||
keywords:
|
||||
- grafana
|
||||
- plugins
|
||||
- backend
|
||||
- plugin
|
||||
- backend-plugins
|
||||
- sdk
|
||||
- documentation
|
||||
description: Learn about the Grafana plugin SDK for Go, a Go module with packages for implementing a Grafana backend plugin.
|
||||
---
|
||||
|
||||
# Grafana plugin SDK for Go
|
||||
|
||||
The [Grafana plugin SDK for Go](https://pkg.go.dev/mod/github.com/grafana/grafana-plugin-sdk-go?tab=overview) is a [Go](https://golang.org/) module that provides a set of [packages](https://pkg.go.dev/mod/github.com/grafana/grafana-plugin-sdk-go?tab=packages) that you can use to implement a backend plugin.
|
||||
|
||||
The plugin SDK provides a high-level framework with APIs, utilities, and tooling. By using the SDK, you can avoid the need to learn the details of the [plugin protocol]({{< relref "./plugin-protocol.md" >}}) and RPC communication protocol, so you don't have to manage either one.
|
||||
|
||||
## Versioning
|
||||
|
||||
The Grafana plugin Go SDK is still in development. It is based on the [plugin protocol]({{< relref "./plugin-protocol" >}}), which is versioned separately and is considered stable. However, from time to time, we might introduce breaking changes in the SDK.
|
||||
|
||||
When we update the plugin SDK, those plugins that use an older version of the SDK should still work with Grafana. However, these older plugins may be unable to use the new features and capabilities we introduce in updated SDK versions.
|
||||
|
||||
## See also
|
||||
|
||||
- [SDK source code](https://github.com/grafana/grafana-plugin-sdk-go)
|
||||
- [Go reference documentation](https://pkg.go.dev/github.com/grafana/grafana-plugin-sdk-go)
|
@ -0,0 +1,48 @@
|
||||
---
|
||||
title: Plugin protocol
|
||||
aliases:
|
||||
- ../../plugins/backend/plugin-protocol/
|
||||
keywords:
|
||||
- grafana
|
||||
- plugins
|
||||
- backend
|
||||
- plugin
|
||||
- backend-plugins
|
||||
- documentation
|
||||
description: Learn about the Grafana wire protocol used for communication between the Grafana server and backend plugins.
|
||||
---
|
||||
|
||||
# Plugin protocol
|
||||
|
||||
The Grafana server uses a physical wire protocol to communicate with backend plugins. This protocol establishes a contract between Grafana and backend plugins to allow them to communicate with each other.
|
||||
|
||||
## Developing with the plugin protocol
|
||||
|
||||
{{% admonition type="caution" %}} We strongly recommend that backend plugin development not be implemented directly against the protocol. Instead, we prefer that you use the [Grafana Plugin SDK for Go]({{< relref "./grafana-plugin-sdk-for-go" >}}) that implements this protocol and provides higher-level APIs. {{%
|
||||
/admonition %}}
|
||||
|
||||
If you choose to develop against the plugin protocol directly, you can do so using [Protocol Buffers](https://developers.google.com/protocol-buffers) (that is, protobufs) with [gRPC](https://grpc.io/).
|
||||
|
||||
Grafana's plugin protocol protobufs are available in the [GitHub repository](https://github.com/grafana/grafana-plugin-sdk-go/blob/master/proto/backend.proto).
|
||||
|
||||
{{% admonition type="note" %}}
|
||||
The plugin protocol lives in the [Grafana Plugin SDK for Go]({{< relref "./grafana-plugin-sdk-for-go.md" >}}) because Grafana itself uses parts of the SDK as a dependency.
|
||||
{{% /admonition %}}
|
||||
|
||||
## Versioning
|
||||
|
||||
From time to time, Grafana will offer additions of services, messages, and fields in the latest version of the plugin protocol. We don't expect these updates to introduce any breaking changes. However, if we must introduce breaking changes to the plugin protocol, we'll create a new major version of the plugin protocol.
|
||||
|
||||
Grafana will release new major versions of the plugin protocol alongside new major Grafana releases. When this happens, we'll support both the old and the new plugin protocol for some time to make sure existing backend plugins continue to work.
|
||||
|
||||
The plugin protocol attempts to follow Grafana's versioning. However, that doesn't mean we will automatically create a new major version of the plugin protocol when a new major release of Grafana is released.
|
||||
|
||||
## Writing plugins without Go
|
||||
|
||||
If you want to write a backend plugin in a language other than Go, then it's possible as long as the language supports gRPC. However, we recommend that you develop your plugin in Go for several reasons:
|
||||
|
||||
- We offer an official plugin SDK.
|
||||
- The compiled output is a single binary.
|
||||
- Writing for multiple platforms is easy. Typically, no additional dependencies must be installed on the target platform.
|
||||
- Small footprint for binary size.
|
||||
- Small footprint for resource usage.
|
Reference in New Issue
Block a user