Loki: Decouple data source plugin (#107242)

* WIP

* Update yarn.lock

* Align uuid dependency

* Add e2e test and update

* Update cue version

* Fix lint

* Update snapshot test

* Fix test that was importing from coupled module

* Fix lint

* Update public/app/plugins/datasource/loki/package.json

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>

---------

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
Ivana Huckova
2025-06-27 15:09:45 +02:00
committed by GitHub
co-authored by Zoltán Bedi
parent f4ee58db50
commit f7eab21f9f
17 changed files with 280 additions and 49 deletions
@@ -209,7 +209,7 @@
"path": "public/app/plugins/datasource/azuremonitor/img/azure_monitor_cpu.png"
}
],
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": [
"azure",
@@ -880,7 +880,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
@@ -934,7 +934,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": [
"grafana",
@@ -1190,34 +1190,34 @@
},
"description": "Open source, end-to-end distributed tracing",
"links": [
{
"name": "Learn more",
"url": "https://www.jaegertracing.io"
},
{
"name": "Jaeger GitHub Project",
"url": "https://github.com/jaegertracing/jaeger"
},
{
"name": "Repository",
"url": "https://github.com/grafana/grafana"
},
{
"name": "Raise issue",
"url": "https://github.com/grafana/grafana/issues/new"
},
{
"name": "Documentation",
"url": "https://grafana.com/docs/grafana/latest/datasources/jaeger/"
}
],
{
"name": "Learn more",
"url": "https://www.jaegertracing.io"
},
{
"name": "Jaeger GitHub Project",
"url": "https://github.com/jaegertracing/jaeger"
},
{
"name": "Repository",
"url": "https://github.com/grafana/grafana"
},
{
"name": "Raise issue",
"url": "https://github.com/grafana/grafana/issues/new"
},
{
"name": "Documentation",
"url": "https://grafana.com/docs/grafana/latest/datasources/jaeger/"
}
],
"logos": {
"small": "public/app/plugins/datasource/jaeger/img/jaeger_logo.svg",
"large": "public/app/plugins/datasource/jaeger/img/jaeger_logo.svg"
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
@@ -1325,12 +1325,12 @@
},
"build": {},
"screenshots": null,
"version": "",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
"dependencies": {
"grafanaDependency": "",
"grafanaDependency": "\u003e=10.4.0",
"grafanaVersion": "*",
"plugins": [],
"extensions": {
@@ -1375,7 +1375,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
@@ -1425,7 +1425,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
@@ -1629,7 +1629,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": [
"grafana",
@@ -1734,7 +1734,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
@@ -2042,7 +2042,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
@@ -2092,7 +2092,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
@@ -2445,7 +2445,7 @@
},
"build": {},
"screenshots": null,
"version": "11.6.0-pre",
"version": "12.1.0-pre",
"updated": "",
"keywords": null
},
+40
View File
@@ -0,0 +1,40 @@
package main
import (
"context"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/grafana/grafana-plugin-sdk-go/backend/tracing"
loki "github.com/grafana/grafana/pkg/tsdb/loki"
)
var (
_ backend.QueryDataHandler = (*Datasource)(nil)
_ backend.CheckHealthHandler = (*Datasource)(nil)
_ backend.CallResourceHandler = (*Datasource)(nil)
)
func NewDatasource(context.Context, backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
return &Datasource{
Service: loki.ProvideService(httpclient.NewProvider(), tracing.DefaultTracer()),
}, nil
}
type Datasource struct {
Service *loki.Service
}
func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
return d.Service.QueryData(ctx, req)
}
func (d *Datasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
return d.Service.CallResource(ctx, req, sender)
}
func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
return d.Service.CheckHealth(ctx, req)
}
+23
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("loki", NewDatasource, datasource.ManageOpts{}); err != nil {
log.DefaultLogger.Error(err.Error())
os.Exit(1)
}
}