How to slice the string using logql?

4.6k views Asked by At

I have values in my logs in grafana loki something like this

data 1234-02-01,12:30,1 data 1234-03-02,11:30,12

I am able to slice these values and separate date and time from this using trunc but I don't seem to do for the last value because it could be either single digit or double digit.

I used this:-

date= {{.data | trunc 10 }} time= {{.data | trunc -10 | trunc 8}} val= {{.data | trunc -1}}

this gives me

date 1234-03-02 , 1234-02-01

time 12:30 , 11:30

val 1 , 2

last val always give the last digit, so if I want to fetch 12 it will only give me 2 . What can I do to fetch the entire digit after time and comma. So I want 1 if its a single digit and 12 if its a double digit and 123 if its a three digit and so on. I hope this makes sense. Can someone please help me ?

1

There are 1 answers

0
Vladyslav Diachenko On

try to use patter parser

for this line: data 1234-02-01,12:30,1 , the query might look like:

{*some labels selector} | pattern "data <date>,<time>,<value>"