How can I extract ts or tsNs using LogQL?

I want create a query for Loki to find out a timestamp, but I cant extract nsec or msec timestamp from query or dashboard panel.

At the first time, I used following query with Table panel.

{job=“testbed”} |~ “(START|END)”
  | pattern “<_> [ID=<id>,CNAME=<cname>,TASK=<taskid>,TARGET=<targetid>]”

Time field cannot convert to the integer( or float) type data, and Time ns also “NaN”.

So, next step I try to extract timestamp variable into a custom label using LogQL, but only empty string is in that label.

{job=“testbed”} |~ “(START|END)”
  | pattern “<_> [ID=<id>,CNAME=<cname>,TASK=<taskid>,TARGET=<targetid>]”
  | label_format logged_time=“{{ .ts }}”

or 

{job=“testbed”} |~ “(START|END)”
  | pattern “<_> [ID=<id>,CNAME=<cname>,TASK=<taskid>,TARGET=<targetid>]”
  | label_format logged_time=“{{ .tsNs }}”

Is there any way to extract timestamp value of stored log??

Environment:

  • Grafnaa: 7.5.10
  • Loki: 2.3.0
1 Like