mysql additional decoupling steps (#86168)

* mysql additional decoupling steps

* updated snapshot test
This commit is contained in:
Gábor Farkas 2024-04-16 11:50:41 +02:00 committed by GitHub
parent 2c304c5fdf
commit 2379498228
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 62 additions and 2 deletions

View File

@ -1118,7 +1118,7 @@
"keywords": null
},
"dependencies": {
"grafanaDependency": "",
"grafanaDependency": ">=10.4.0",
"grafanaVersion": "*",
"plugins": []
},

View 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)
}

View 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)
}
}

View File

@ -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,