Could not start plugin : Plugin unavailable

Hello,
I am building a data source backend plugin from this documentation.

I can run the npm run dev and the mage -v build:linux without any error.

When I start Grafana with docker compose up (with WSL) I can see my brand new plugin and add it to a new datasource. However in a dashboard, it says that the plugin is unavailable :

In the docker logs I’ve got this message :

amf-elasticiotoffice-datasource | logger=plugin.loader t=2023-12-07T14:38:55.730352164Z level=error msg="Could not start plugin" pluginId=amf-elasticiotoffice-datasource err="Unrecognized remote plugin message: \nThis usually means\n the plugin was not compiled for this architecture,\n the plugin is missing dynamic-link libraries necessary to run,\n the plugin is not executable by this process due to file permissions, or\n the plugin failed to negotiate the initial go-plugin protocol handshake\n\nAdditional notes about plugin:\n Path: /var/lib/grafana/plugins/amf-elasticiotoffice-datasource/gpx_elasticiotoffice_linux_amd64\n Mode: -rwxrwxrwx\n Owner: 1000 [?] (current: 0 [root])\n Group: 1000 [?] (current: 0 [root])\n ELF architecture: EM_X86_64 (current architecture: amd64)\n"

I don’t know how to fix this.
What is the difference between EM_X86_64 and amd64 ?
What are the dynamic-link libraries that are missing ?
Which file needs more permissions and what about the “failed to negotiate…”
Where to find /var/lib/grafana/plugins/amf-elasticiotoffice-datasource/gpx_elasticiotoffice_linux_amd64, I only have /dist/gpx_elasticiotoffice_linux_amd64

Postscript : Grafana runs in development mode

1 Like

Hello!

Those messages about the libraries, permissions, “failed to negotiate” etc are hints about what could be wrong. It does not necessarily mean all those things are wrong.

According to the additional notes in the log line, the architecture and permissions are correct, but the plugin binary may be exiting prematurely or printing something to stdout, causing the error in Grafana.

There may also be more log lines above the one you sent that could give more hints about what went wrong.

Can you please enable debug logging by adding the following lines in docker-compose.yml, under the grafana service:

environment:
  - GF_LOG_LEVEL=debug

like this:

version: '3.0'

services:
  grafana:
    container_name: 'test-test-datasource'
    platform: 'linux/amd64'
    build:
      context: ./.config
      args:
        grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
        grafana_version: ${GRAFANA_VERSION:-10.0.3}
    ports:
      - 3000:3000/tcp
    volumes:
      - ./dist:/var/lib/grafana/plugins/test-test-datasource
      - ./provisioning:/etc/grafana/provisioning
    environment:
      - GF_LOG_LEVEL=debug

then start Grafana with this command:

docker compose up | grep logger=plugin

trigger the error and share here the output of the command.

Can you also share the content of your pkg/main.go and pkg/plugin/datasource.go? Maybe something is wrong in the plugin’s code.

Also, please make sure that you are running all commands (npm, mage, docker compose, etc) inside WSL and not in Windows.

Best,
Giuseppe,
Grafana Labs

Hello !

I fix my situation, thank you for your help :grin:
I was running “npm” and “mage” command in Windows, not in WSL.

Mage was not working on WSL. I had to change GO version from 1.13.5 to 1.21.5
Then with a go mod tidy and the mage command I had this error message :

pkg/main.go:21:65: cannot use plugin.NewDatasource (value of type func(_ "context".Context, _ backend.DataSourceInstanceSettings) (instancemgmt.Instance, error)) as datasource.InstanceFactoryFunc value in argument to datasource.Manage

By removing the parameter “context” in the function NewDatasource of the file pkg/plugin/datasource.go and running the mage command it works now :slight_smile:

I can now see and use my datasource in Grafana.

Thank you

Regards,
Maxime

1 Like

Hello!

I’m glad to hear that you were able to solve the issue by just running the commands inside WSL!

However, by the error message you got about the “context” it looks like you are using an outdated version of the Grafana Plugin SDK Go (go package github.com/grafana/grafana-plugin-sdk-go).

The plugin will compile and work fine, but for new plugins we would recommend sticking to the latest version of the Grafana Plugin SDK Go. This is optional but recommended.

You can update to the latest version of the Grafana Plugin SDK Go by running those commands in your plugin’s folder (where go.mod and go.sum are located):

go get -u github.com/grafana/grafana-plugin-sdk-go
go mod tidy

Since there was a breaking change between versions which added the context.Context parameter to datasource.InstanceFactoryFunc, your plugin will not compile and you will have to re-add the ctx context.Context argument to your NewDatasource function:

func NewDatasource(ctx context.Context, settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
    // ...

If you need more code examples, we also have a variety of plugin examples you can take a look at!

Best,
Giuseppe,
Grafana Labs

2 Likes