I’m currently working on a task where, in essence, I’d like to reimplement Grafana’s bundled PostgreSQL plugin as a third-party/external plugin, and then adjust its functionality (specifically, some additions + simplifications to the query builder, and some changes to the configuration)
This can be done by adding the changes to a new core plugin folder, then building grafana from source, but this is somewhat cumbersome, and every time grafana updates, it will be necessary to build from source again to get the new updates.
Instead, I’ve been working on implementing the interface with the new React third party plugin structure.
Upon reaching the backend, however, I’ve hit a blocking point.
To reimplement the postgres functionality, it seems it will be necessary to copy the postgres go files (such as locker_test.go, tlsmanager.go, etc) from <grafana>\pkg\tsdb\postgres
to <plugins>\<my_plugin>\pkg
, or possibly <plugins>\<my_plugin>\pkg\plugin>
, adapting the applicable endpoints to integrate better with the current third-party plugin API (adding a checkhealth method in the go files instead of having the testDatasource
method in datasource.ts
, for example)
However, when moving these files into the plugin folder, after running go mod tidy
to update dependencies, some imports are causing problems, eg
postgres.go
package main
import (
...
"github.com/grafana/grafana/pkg/infra/log"
...
"github.com/grafana/grafana/pkg/tsdb/sqleng"
)
Running go mod tidy
, the following sort of error appears in the error log:
github.com/grafana/grafana-starter-datasource-backend/pkg/plugin imports
github.com/grafana/grafana/pkg/infra/log: module github.com/grafana/grafana@latest found (v6.1.6+incompatible), but does not contain package github.com/grafana/grafana/pkg/infra/log
Basically, for several packages, it attempts to import them from module github.com/grafana/grafana@latest found (v6.1.6+incompatible)
, but does not find them
How would I go about fixing this? The core plugin files manage to import these packages, so they are accessible somewhere. Or is there some other way to get the functionality defined in those modules in the third party plugin? Or perhaps further, is there some other way of implementing the existing core PostgreSQL plugin such that Grafana can be updated without necessitating that Grafana be rebuilt from source each time it updates?