Use of label_format

Hi,

I am creating labels using regex and pattern parser and modifying those labels using label_format. Is there anyway I can make use of newly created label in filter or maybe compare/assign value of global variable.

Example:

label_format dst=“{{.t1}}{{.t2}}{{.t3}}”

now I want to use this dst like dst=“$ts” where $ts is DateTime.

So it will show the result only when dst and $ts is matching.

Not clear on what you are looking for. Can you provide some real example, what you have, and what result you are looking for?

@tonyswumac I have created new label using label_format - dst (using t1, t2, t3 labels)
Now I have “dst” label (which is nothing but a time stamp). I am creating variable $search with text box.

Now what I want to do is when I put some time stamp in search box (2023-04-05 11:11:11) it should put this value in “dst” and should only show log line for this time stamp
something like | dst=$search

Are you using Grafana? If so, wouldn’t the top right of the dashboard view generally give you a way to filter by time range already?

If you are looking to do some sort of customized time range with variables I don’t think it’s possible. There is a feature request similar to this: https://github.com/grafana/grafana/issues/2417

You can probably make it work if you restrict the format enough, but without some sort of programmatic approach there are so many ways you can format time, it’s just not going to be very reliable.

@tonyswumac Of course I am using Grafana.
But I am more interested in exact timestamp rather than a time range.
I want to see a log line for the exact timestamp and not for the whole time range.

I see. I personally haven’t had this use case, nor do I personally think it’s useful (we peak with 50,000 lines per second in our cluster, you are just not going to pinpoint anything with a timestamp that way). But I won’t argue for my personal preference because every environment is different. Hopefully someone can provide some insight or workable solution for you.

1 Like