mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 14:32:15 +08:00
SQL Datasources: Use health check for config test (#59867)
* SQL Datasources: Use health check for config test * Remove unnecessary test * Fix test errors * Revert mysql go driver update * Use transform query error * Use TransformQueryError from sql_engine
This commit is contained in:
@ -140,6 +140,25 @@ func (s *Service) getDataSourceHandler(pluginCtx backend.PluginContext) (*sqleng
|
||||
return instance, nil
|
||||
}
|
||||
|
||||
// CheckHealth pings the connected SQL database
|
||||
func (s *Service) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||
dsHandler, err := s.getDataSourceHandler(req.PluginContext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = dsHandler.Ping()
|
||||
|
||||
if err != nil {
|
||||
var driverErr *mysql.MySQLError
|
||||
if errors.As(err, &driverErr) {
|
||||
return &backend.CheckHealthResult{Status: backend.HealthStatusError, Message: dsHandler.TransformQueryError(logger, driverErr).Error()}, nil
|
||||
}
|
||||
return &backend.CheckHealthResult{Status: backend.HealthStatusError, Message: dsHandler.TransformQueryError(logger, err).Error()}, nil
|
||||
}
|
||||
return &backend.CheckHealthResult{Status: backend.HealthStatusOk, Message: "Database Connection OK"}, nil
|
||||
}
|
||||
|
||||
func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
dsHandler, err := s.getDataSourceHandler(req.PluginContext)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user