mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
mysql additional decoupling steps (#86168)
* mysql additional decoupling steps * updated snapshot test
This commit is contained in:
parent
2c304c5fdf
commit
2379498228
@ -1118,7 +1118,7 @@
|
||||
"keywords": null
|
||||
},
|
||||
"dependencies": {
|
||||
"grafanaDependency": "",
|
||||
"grafanaDependency": ">=10.4.0",
|
||||
"grafanaVersion": "*",
|
||||
"plugins": []
|
||||
},
|
||||
|
32
pkg/tsdb/mysql/standalone/datasource.go
Normal file
32
pkg/tsdb/mysql/standalone/datasource.go
Normal file
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
|
||||
mysqlds "github.com/grafana/grafana/pkg/tsdb/mysql"
|
||||
)
|
||||
|
||||
var (
|
||||
_ backend.QueryDataHandler = (*Datasource)(nil)
|
||||
_ backend.CheckHealthHandler = (*Datasource)(nil)
|
||||
)
|
||||
|
||||
func NewDatasource(context.Context, backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||
return &Datasource{
|
||||
Service: mysqlds.ProvideService(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Datasource struct {
|
||||
Service *mysqlds.Service
|
||||
}
|
||||
|
||||
func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
return d.Service.QueryData(ctx, req)
|
||||
}
|
||||
|
||||
func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||
return d.Service.CheckHealth(ctx, req)
|
||||
}
|
23
pkg/tsdb/mysql/standalone/main.go
Normal file
23
pkg/tsdb/mysql/standalone/main.go
Normal file
@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Start listening to requests sent from Grafana. This call is blocking so
|
||||
// it won't finish until Grafana shuts down the process or the plugin choose
|
||||
// to exit by itself using os.Exit. Manage automatically manages life cycle
|
||||
// of datasource instances. It accepts datasource instance factory as first
|
||||
// argument. This factory will be automatically called on incoming request
|
||||
// from Grafana to create different instances of SampleDatasource (per datasource
|
||||
// ID). When datasource configuration changed Dispose method will be called and
|
||||
// new datasource instance created using NewSampleDatasource factory.
|
||||
if err := datasource.Manage("mysql", NewDatasource, datasource.ManageOpts{}); err != nil {
|
||||
log.DefaultLogger.Error(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
"type": "datasource",
|
||||
"name": "MySQL",
|
||||
"id": "mysql",
|
||||
"executable": "gpx_mysql",
|
||||
"category": "sql",
|
||||
|
||||
"info": {
|
||||
@ -13,7 +14,11 @@
|
||||
"logos": {
|
||||
"small": "img/mysql_logo.svg",
|
||||
"large": "img/mysql_logo.svg"
|
||||
}
|
||||
},
|
||||
"version": "%VERSION%"
|
||||
},
|
||||
"dependencies": {
|
||||
"grafanaDependency": ">=10.4.0"
|
||||
},
|
||||
|
||||
"alerting": true,
|
||||
|
Loading…
Reference in New Issue
Block a user