mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 10:02:26 +08:00
Backend plugins: Implement support for resources (#21805)
Implements initial support for resources using v0.14.0 of SDK. Ref #21512
This commit is contained in:

committed by
GitHub

parent
5345868148
commit
0390b5601e
85
pkg/plugins/backendplugin/contracts.go
Normal file
85
pkg/plugins/backendplugin/contracts.go
Normal file
@ -0,0 +1,85 @@
|
||||
package backendplugin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2"
|
||||
)
|
||||
|
||||
// HealthStatus is the status of the plugin.
|
||||
type HealthStatus int
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
var healthStatusNames = map[int]string{
|
||||
0: "UNKNOWN",
|
||||
1: "OK",
|
||||
2: "ERROR",
|
||||
}
|
||||
|
||||
func (hs HealthStatus) String() string {
|
||||
s, exists := healthStatusNames[int(hs)]
|
||||
if exists {
|
||||
return s
|
||||
}
|
||||
return strconv.Itoa(int(hs))
|
||||
}
|
||||
|
||||
// CheckHealthResult check health result.
|
||||
type CheckHealthResult struct {
|
||||
Status HealthStatus
|
||||
Info string
|
||||
}
|
||||
|
||||
func checkHealthResultFromProto(protoResp *pluginv2.CheckHealth_Response) *CheckHealthResult {
|
||||
status := HealthStatusUnknown
|
||||
switch protoResp.Status {
|
||||
case pluginv2.CheckHealth_Response_ERROR:
|
||||
status = HealthStatusError
|
||||
case pluginv2.CheckHealth_Response_OK:
|
||||
status = HealthStatusOk
|
||||
}
|
||||
|
||||
return &CheckHealthResult{
|
||||
Status: status,
|
||||
Info: protoResp.Info,
|
||||
}
|
||||
}
|
||||
|
||||
type PluginInstance struct {
|
||||
ID int64
|
||||
Name string
|
||||
Type string
|
||||
URL string
|
||||
JSONData json.RawMessage
|
||||
}
|
||||
|
||||
type PluginConfig struct {
|
||||
PluginID string
|
||||
OrgID int64
|
||||
Instance *PluginInstance
|
||||
}
|
||||
|
||||
type CallResourceRequest struct {
|
||||
Config PluginConfig
|
||||
Path string
|
||||
Method string
|
||||
URL string
|
||||
Headers map[string][]string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
// CallResourceResult call resource result.
|
||||
type CallResourceResult struct {
|
||||
Status int
|
||||
Headers map[string][]string
|
||||
Body []byte
|
||||
}
|
Reference in New Issue
Block a user