fr-ser / grafana-sqlite-datasource

Grafana Plugin to enable SQLite as a Datasource
Apache License 2.0
124 stars 17 forks source link

Plugin health check failed #38

Closed gmosx closed 3 years ago

gmosx commented 3 years ago

Hello!

First of all, thank you for this useful plugin.

I installed it for the first time and tried to create an Sqlite3 Data Source. But, when clicking on the Save & Test button, I got:

Plugin health check failed

My environment is Linux Fedora 33, installed Grafana from yum repositories.

Here is the corresponding log:

t=2021-03-27T12:05:33+0200 lvl=info msg="Starting Grafana" logger=server version=7.5.1 commit=4dffb875cf branch=HEAD compiled=2021-03-26T15:12:21+0200
t=2021-03-27T12:05:33+0200 lvl=info msg="Config loaded from" logger=settings file=/usr/share/grafana/conf/defaults.ini
t=2021-03-27T12:05:33+0200 lvl=info msg="Config loaded from" logger=settings file=/etc/grafana/grafana.ini
t=2021-03-27T12:05:33+0200 lvl=info msg="Config overridden from command line" logger=settings arg="default.paths.data=/var/lib/grafana"
t=2021-03-27T12:05:33+0200 lvl=info msg="Config overridden from command line" logger=settings arg="default.paths.logs=/var/log/grafana"
t=2021-03-27T12:05:33+0200 lvl=info msg="Config overridden from command line" logger=settings arg="default.paths.plugins=/var/lib/grafana/plugins"
t=2021-03-27T12:05:33+0200 lvl=info msg="Config overridden from command line" logger=settings arg="default.paths.provisioning=/etc/grafana/provisioning"
t=2021-03-27T12:05:33+0200 lvl=info msg="Path Home" logger=settings path=/usr/share/grafana
t=2021-03-27T12:05:33+0200 lvl=info msg="Path Data" logger=settings path=/var/lib/grafana
t=2021-03-27T12:05:33+0200 lvl=info msg="Path Logs" logger=settings path=/var/log/grafana
t=2021-03-27T12:05:33+0200 lvl=info msg="Path Plugins" logger=settings path=/var/lib/grafana/plugins
t=2021-03-27T12:05:33+0200 lvl=info msg="Path Provisioning" logger=settings path=/etc/grafana/provisioning
t=2021-03-27T12:05:33+0200 lvl=info msg="App mode production" logger=settings
t=2021-03-27T12:05:33+0200 lvl=info msg="Writing PID file" logger=server path=/var/run/grafana/grafana-server.pid pid=1810736
t=2021-03-27T12:05:33+0200 lvl=info msg="Connecting to DB" logger=sqlstore dbtype=sqlite3
t=2021-03-27T12:05:33+0200 lvl=info msg="Starting DB migrations" logger=migrator
t=2021-03-27T12:05:33+0200 lvl=info msg="migrations completed" logger=migrator performed=0 skipped=279 duration=480.857µs
t=2021-03-27T12:05:33+0200 lvl=info msg="Starting plugin search" logger=plugins
t=2021-03-27T12:05:33+0200 lvl=info msg="Registering plugin" logger=plugins id=input
t=2021-03-27T12:05:33+0200 lvl=info msg="Registering plugin" logger=plugins id=frser-sqlite-datasource
t=2021-03-27T12:05:33+0200 lvl=info msg="HTTP Server Listen" logger=http.server address=[::]:3000 protocol=http subUrl= socket=
t=2021-03-27T12:05:55+0200 lvl=eror msg="Plugin health check failed" logger=context userId=1 orgId=1 uname=admin error="failed to check plugin health: health check failed" remote_addr=[::1]
t=2021-03-27T12:05:55+0200 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=GET path=/api/datasources/2/health status=500 remote_addr=[::1] time_ms=2 size=40 referer=http://localhost:3000/datasources/edit/2/

Thanks in advance for any help.

fr-ser commented 3 years ago

Are you sure the grafana user has access to the database file?

If you are sure about the file permissions, then please download v1.0.3 of the plugin (manual installation necessary) and check that. This provides better error messages.

gmosx commented 3 years ago

I installed v1.0.3 Indeed it doesn't have access to the database file.

I gave 777 permission to the file but I still get the same error.

What kind of permissions should I give to the database file? Should the parent directory also have specific permissions? Should I move the database file into a specific directory?

gmosx commented 3 years ago

OK, I got this to work by giving very liberal permissions.

I am wondering what are the best practices here? Where should the database files be placed? What are the exact permissions required?

fr-ser commented 3 years ago

There are two main considerations:

  1. What user is grafana using? If you give permission to the file for your own user then that does not mean Grafana can check it (e.g. why 700 does not work sometimes)
  2. Grafana needs to access the file and possibly the folder

I am not sure about read vs write permission actually. I would assume read permissions for the grafana user to the whole path and file itself should be enough.

gmosx commented 3 years ago

Hm, for some reason the containing folder needs to have the write permission.

fr-ser commented 3 years ago

Not on my machine at least. With the following permissions, it worked fine for me

bash-5.0# ls -lah .
total 8K
drwxr-xr-x    2 non-graf non-graf    4.0K Mar 28 07:45 .
drwxr-xr-x    1 root     root        4.0K Mar 28 07:44 ..
-rw-r--r--    1 non-graf non-graf       0 Mar 28 07:45 empty.db

Maybe the issue is rather with the (often misunderstood/unknown) effect of the execute bit on folders? https://superuser.com/questions/168578/why-must-a-folder-be-executable/169418