mullerpeter / databricks-grafana

Grafana Databricks integration allowing direct connection to Databricks to query and visualize Databricks data in Grafana.
Apache License 2.0
55 stars 4 forks source link

Status 500. Databricks: execution error: failed to execute query: Invalid SessionHandle: SessionHandle [{jdbc-session-id}] #27

Closed lgurnik closed 1 year ago

lgurnik commented 1 year ago

Hello @mullerpeter,

After the last one issue, i think maxIdleTime should be added during connection refreshing with DB.

Reproduction of the issue:

I have refreshed dashboard (or on query level as well) and closed browser tab afterwards. After some time of inactivity (6 hours) and refreshing the dashboard, connector try to establish connection using the idled session. Status 500 databricks: execution error: failed to execute query: Invalid SessionHandle: SessionHandle [{jdbc-session-id}].

In release 1.1.5. this issue did not occur.

My opinion, the error occurs under rows, err := d.ExecuteQuery(queryString) in pkg/plugin/plugin.go based on the output logs.

Do you have the same idea that maxIdleTime should fix the issue on the pkg/plugin/plugin.go RefreshDBConnection?

Thank you in advance!

mullerpeter commented 1 year ago

Hi @lgurnik

The issue already appeared before #6 and should in theory be handled correctly by this part.

I'm not sure why the changes from the latest release break this logic, but I'll try to look into this. Setting maxIdleTime could potentially work and maybe also allows to remove the manual refresh logic of the connection 👍

I'll get back to you soon

lgurnik commented 1 year ago

Thanks @mullerpeter . Based on the logs it seems that this place: rows, err := d.ExecuteQuery(queryString) in pkg/plugin/plugin.go produces an error and it can be as well one solution after execution to close the connection.

lgurnik commented 1 year ago

Ah yes, you have mentioned this one. Correct.

mullerpeter commented 1 year ago

Looking at this issue https://github.com/databricks/databricks-sql-go/issues/77 the people from Databricks also suggest to use maxIdleTime.

lgurnik commented 1 year ago

I think it would be better as well to have instead of strings.HasPrefix(err.Error(), "Invalid SessionHandle") something like strings.Contains(err.Error(), "Invalid SessionHandle") In case the error message wrapping from sql go plugin will be not prefixed anymore, but will contain the error message substring. Because by debugging the issue, log message: Refreshing Databricks SQL DB Connection was not occurred. As well maybe after rows, err := d.databricksDB.Query(queryString) call to use defer rows.Close(). What do you think?

lgurnik commented 1 year ago

I have changed the implementation in that way, as I have written and created executables and it seems to be working solution (as for now). If not I will let know.

mullerpeter commented 1 year ago

Hi @lgurnik

SetConnMaxIdleTime fixed the issue on my side. I opted for this solution, since it allowed the removal of the error catching & manual connection refresh.

filipzeta commented 8 months ago

hey @mullerpeter, im getting this issue in 1.2.2. unfortunately grafana logs aren't very helpful, just says the error:

logger=plugin.mullerpeter-databricks-datasource t=2024-01-29T04:09:52.343502638Z level=info msg=Error err="databricks: execution error: failed to execute 
query: Invalid SessionHandle: SessionHandle [c7a0e9c8-38a2-4863-8ac7-cadb6f4dfae6]"

are there any other logs i can provide to help debugging? ive resorted to a scheduled restart via crontab which isn't ideal 😝