mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 08:33:00 +08:00
Add support for sending health check to datasource plugins. (#22771)
closes #21519 ref grafana/grafana-plugin-sdk-go#93
This commit is contained in:
@ -185,14 +185,27 @@ func (p *BackendPlugin) CollectMetrics(ctx context.Context, ch chan<- prometheus
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *BackendPlugin) checkHealth(ctx context.Context) (*pluginv2.CheckHealthResponse, error) {
|
||||
func (p *BackendPlugin) checkHealth(ctx context.Context, config *PluginConfig) (*pluginv2.CheckHealthResponse, error) {
|
||||
if p.diagnostics == nil || p.client == nil || p.client.Exited() {
|
||||
return &pluginv2.CheckHealthResponse{
|
||||
Status: pluginv2.CheckHealthResponse_UNKNOWN,
|
||||
}, nil
|
||||
}
|
||||
|
||||
res, err := p.diagnostics.CheckHealth(ctx, &pluginv2.CheckHealthRequest{})
|
||||
jsonDataBytes, err := config.JSONData.ToDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pconfig := &pluginv2.PluginConfig{
|
||||
OrgId: config.OrgID,
|
||||
PluginId: config.PluginID,
|
||||
JsonData: jsonDataBytes,
|
||||
DecryptedSecureJsonData: config.DecryptedSecureJSONData,
|
||||
LastUpdatedMS: config.Updated.UnixNano() / int64(time.Millisecond),
|
||||
}
|
||||
|
||||
res, err := p.diagnostics.CheckHealth(ctx, &pluginv2.CheckHealthRequest{Config: pconfig})
|
||||
if err != nil {
|
||||
if st, ok := status.FromError(err); ok {
|
||||
if st.Code() == codes.Unimplemented {
|
||||
|
Reference in New Issue
Block a user