diff --git a/pkg/tests/api/plugins/data/expectedListResp.json b/pkg/tests/api/plugins/data/expectedListResp.json index 2723c7388e8..e04e45cce5f 100644 --- a/pkg/tests/api/plugins/data/expectedListResp.json +++ b/pkg/tests/api/plugins/data/expectedListResp.json @@ -1118,7 +1118,7 @@ "keywords": null }, "dependencies": { - "grafanaDependency": "", + "grafanaDependency": ">=10.4.0", "grafanaVersion": "*", "plugins": [] }, diff --git a/pkg/tsdb/mysql/standalone/datasource.go b/pkg/tsdb/mysql/standalone/datasource.go new file mode 100644 index 00000000000..3a2a1e160db --- /dev/null +++ b/pkg/tsdb/mysql/standalone/datasource.go @@ -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) +} diff --git a/pkg/tsdb/mysql/standalone/main.go b/pkg/tsdb/mysql/standalone/main.go new file mode 100644 index 00000000000..fd78c834330 --- /dev/null +++ b/pkg/tsdb/mysql/standalone/main.go @@ -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) + } +} diff --git a/public/app/plugins/datasource/mysql/plugin.json b/public/app/plugins/datasource/mysql/plugin.json index 48e1d39d735..bf93440a617 100644 --- a/public/app/plugins/datasource/mysql/plugin.json +++ b/public/app/plugins/datasource/mysql/plugin.json @@ -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,