At the beginning of every successful data exploration journey, a query is constructed. So, with this latest Grafana release, we are proud to introduce several new features aimed at improving the Grafana Loki querying experience. From query expression validation to seeing the query history in code editor and more, these updates are sure to make querying in Grafana even more efficient and intuitive, saving you time and frustration.
Query expression validation
To speed up the process of writing a correct LogQL query, we’ve added a new feature: query expression validation. Or as our team likes to call it, a new “red squiggly line” feature, since it uses the same wavy lines you’re accustomed to seeing underscore text when you enter a typo in a word processor 🙂. With query validation, you don’t have to run a query to see if it is correct. Instead, you get real time feedback if the query is not valid. When that happens, the red squiggly line will show you the exact location of the error, and which characters are incorrect. Query expression validation also supports multi-line queries.
In the last couple of releases we’ve added a lot of improvements to the Loki code editor and its autocomplete feature. In the current release, we have improved autocomplete suggestions even more and it now detects scenarios better and provides higher quality suggestions.
One of the biggest improvements is the ability to see the suggested type of parser (e.g., logfmt, JSON) based on your query. This is a similar feature to the suggested parser in query builder’s hints, and both of them help you write more suitable queries for your data. Moreover, if you use the parser in your query, all labels, including extracted labels by the parser, are suggested in range aggregations with grouping (e.g.,
sum by()). Previously, extracted labels were not suggested.
Query history in code mode
Loki’s code editor now has the query history directly integrated into it. Queries you ran previously are displayed as soon as you start writing your new query. This feature is especially useful in Explore, where you often don’t start from scratch but want to make use of your previous work. If you prefer writing queries with the query builder or you simply can’t find your last query in the code editor, you can still use the query history, which keeps track of queries by saving them in Grafana’s internal database.
Estimated query size
Understanding the impact of queries can be difficult, so we have introduced a new feature that allows users to get an estimate for the amount of data their input query will process. This will display an estimate to the user, providing valuable information on the potential impact of the query on performance and resources. This feature not only helps users make informed decisions, but also optimizes their query writing experience by providing insight into the data processing involved. This is made possible by Loki’s new TSDB index.
The label browser, previously known as the log browser, has undergone some changes in Grafana 9.4. This feature has been moved to a more neutral position in the user interface, making it accessible in both the query builder and the code editor. Additionally, the label browser has been converted to a modal. This increases efficiency when composing queries in dashboards, providing more space to display all of the relevant data.
We know that a lot of users who are composing metric queries in Explore would like to see sample log lines that contributed to that metric. So that’s exactly what we are bringing to you in Grafana 9.4! We believe this can assist with the debugging process, mainly by helping you narrow down your metric query by including line filters based on content of the log lines, or label filters. To see log samples, click on the collapsed Logs sample panel below your metrics result.
Moreover, if you want to interact with your log lines or modify the log query, click on the Open logs in split view button and the log query will be executed in the split view.
New log details
In Grafana 9.4 we introduced the “Filter for this field instead of the message” button, which looks like an eye, to all fields in log details. By using this button, you don’t have to mess around with
line_format operations in your LogQL query. Instead, use the icon to select the labels you are interested in, and Grafana will display just the information associated with that label. Additionally, you can use the “Filter for value” buttons, which look like magnifying glalsses with plus and minus symbols, to adjust your LogQL stream selector or label filter operations.
Furthermore, we cleaned up log details so only indexed or extracted labels are visible. Previously, Grafana tried detecting more labels than Loki returned, and we understood that the differences in previous “labels” and “detected fields” were difficult to understand. Luckily, the Loki data source will suggest the right parser in the editor, in order for you to still see all of the extracted labels.
Line limit display
Last but not least, Loki’s data source in Grafana 9.4 comes with a small improvement in your query options, which will now always display the configured line limit. This allows you to better understand the maximum amount of log lines you would see in the results.