Filtering Panels Based on Time Span in Grafana

Hello dear community :sweat_smile:

I have a question that might be straightforward, but I’m struggling to find a solution. I want to achieve the following behavior in Grafana:

When I click on a log entry in Panel 1, the other panels on the same dashboard should dynamically filter their data based on a time span derived from the selected log entry’s timestamp. For example, if I click on a log entry with a timestamp of 12:00:00, the other panels should display logs within a 1-minute range around this timestamp (e.g., from 11:59:00 to 12:00:00).

I’m using Grafana Loki (latest release), Promtail (latest release), and Grafana v11.4.0 (b58701869e). I understand that I’m working with the Open-Source version, but it would be great if you could confirm whether I’m doing something wrong or if this functionality is not supported at all.

I’ve been trying to configure this using data links, but I can’t seem to make it work. Either the time range isn’t applied as expected, or it defaults to a date in 1970. Below are some of the variations of data links I’ve tried, along with the results:

  1. /d/1234567890abcdefg/logsources-frtest?from=${__value.time}&to=${__value.time+60000}
  • This works, but it doesn’t achieve the behavior I need (no 1-minute range applied, but 1-hour range).
  1. /d/1234567890abcdefg/logsources-frtest?from=${__value.time-60000}&to=${__value.time}
  • This doesn’t work and defaults to a 1970 date.
  1. /d/1234567890abcdefg/logsources-frtest?from=${__value.time}-60000&to=${__value.time}
  • Also doesn’t work, resulting in the 1970 date.
  1. /d/1234567890abcdefg/logsources-frtest?from=${__value.time} - 60000&to=${__value.time}
  • Same issue as above (1970 date).
  1. /d/1234567890abcdefg/logsources-frtest?from=(${__value.time} - 60000)&to=${__value.time}
  • This also fails, resulting in the 1970 date.
  1. /d/1234567890abcdefg/logsources-frtest?from=(${__value.time}–60000)&to=${__value.time}
  • Same problem, resulting in the 1970 date.

Once again, I’m unsure if this is a bug, a limitation of Grafana’s data link syntax, or if I’m missing something in my configuration. I’d greatly appreciate your guidance on how to achieve the desired time-based filtering across panels or if there’s another approach I should consider.

Thank you in advance for your help!

Yaaaay I found the solution. Now I feel obligated to share my findings on the topic.
So without further ado. Since you cannot make arethmetic operations on the link itself within grafana and with loki / logQL (if Im wrong, please correct me!), I went into full google search mode and found finally the solution to my problem, drumrolls, the loki API (yeah… please dont say anything at all :sweat_smile:). So I made the following construct:

    1. Ingest the data with promtail (try to avoid many diffrent labels)
    1. Do wahtever you want with the data with the logQl query
    1. At the transformation panel, very important, transform your time stamp to Time and UnixEpoch (so we can use it for the Loki API call time and “calculate” the time range in the data link) For instance:
      Convert field type: TimeAndDate as Time Input format UnixEpoch
    1. Create variable named timestamp so the user can select a timerange. For example a dropdown and some key : value mappings like 1m : 120000, 2m : 120000 (My approach is use mapping for human readability, 1000 is one second)
    1. Make finally the data link (I did choose the +Add Override and then Data Link > Data Links) and created the following URL (just to be sure I added also the UnixEpoch in the data link, this may be unnecessary but hey you never know):
      /d/1234567890abcdefg/first-dashboard?time=${__value.TimeAndDate:UnixEpoch}&time.window=${timeSpan}
      image

And voila, it works like a charm! Hope I can spare others some headache for this topic!

Have fun and a nice time :slight_smile: