EndlessSpace
EndlessSpace

Reputation: 1370

How to access the Grafana time interval range for DrillDown links to an ElasticSearch page

I'm trying to add a drilldown link to an Elastic search link in a Grafana chart. I'm able to use the variables that are already defined in my panel, but I also want to make use of the current time interval when creating the URL for elastic search.

I have tried using the following variables in the URL based on different online posts, hoping that they would be replaced by Grafana when the URL is clicked.

but, nonw have been converted to the time range value that is currently selected.

e.g.: Url in Grafana:

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(from:now-$__interval,mode:quick,to:now))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:$environment'),sort:!('@timestamp',desc))

Expected Url when user clicks the chart:

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(from:now-1h,mode:quick,to:now))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:Development'),sort:!('@timestamp',desc))

Actual Url when user clicks the chart:

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(from:now-$__interval,mode:quick,to:now))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:Development'),sort:!('@timestamp',desc))

The $environment variable is being replaced as expected but the $__interval variable is not being replaced which causes the URL to not be parsed correctly by Elastic Search when trying to display the page.

Drilldown link for SingleStat Chart

Upvotes: 7

Views: 2865

Answers (2)

Jake Toronto
Jake Toronto

Reputation: 3584

I solved this using the absolute from and to, rather than the relative now-based time range, as follows (using your example URL):

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(**from:'${__from:date:iso}',mode:quick,to:'${__to:date:iso}'**))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:$environment'),sort:!('@timestamp',desc))

This results in a URL like this:

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(**from:'2023-07-12T14:38:09.298Z',mode:quick,to:'2023-07-12T17:38:09.298Z'**))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:Development'),sort:!('@timestamp',desc))

Note two important points:

  1. We wrap the variables in quotes, since we're formatting them as time strings rather than numeric epoch-seconds or epoch-millis
  2. We use the :iso modifier to force the format.

Can Elasticsearch accept epoch-seconds or millis in its link? Maybe. I'm not sure... but that would be another way to go.

See https://grafana.com/docs/grafana/latest/panels-visualizations/configure-data-links/#time-range-panel-variables for more info

Upvotes: 0

user2650367
user2650367

Reputation: 443

Possible starting from Grafana 6.0, use this snippet:

Url: "/dashboard-id/dashboard-name?var-variable1=${__cell}&from=$__from&to=$__to

Upvotes: 1

Related Questions