Hello and welcome.
My name is Daria Volkova, and today I break down another Grafana concept. Transformations!
You can find them here, in any panel Edit mode, second tab, next to the 'Query' tab.
There is a long list of available transformations. What do they transform, and how can they make
your life easier? Let's find out in this video! Let's go! Any data source returns data in a particular
format. I have the results of query A on my schema for that. A visualization panel,
in its turn, expects the data to be in a specific format as well, a format that
this panel is designed to work with. If those two formats align
or, in other words, match, meaning they are the same formats,
then no transformation is needed. If a data source format differs from
a visualization panel's expectations, apply transformations. Let's take a look at some examples. I will
use the Website analytics dashboard we have on our LIVE project. It is not
a publicly available dashboard yet, but we might consider changing that in the future. I go into the Edit mode for the map visualization.
In this example, we use the Apache ECharts panel. The trick is somehow knowing what data
format your visualization panel requires. For this visualization, based on
what I found in the documentation and try-and-error approach, I know
that the map visualization expects a two-dimensional array of
data - country, and value. As you can see, we use the Loki data source
since we collect our website analytics in Loki. I will switch to the transformation tab and click
this eye icon to disable each transformation. The visualization now obviously
can not work. I will switch to the table view here to observe the
data coming from the data source. Alright, see this drop-down here. It means that the data comes from the data
source in multiple frames. On the diagram, it looks like this. The
data source returns every country in a separate table with two columns - Time and Value.
I add the first transformation, "Series to rows". In my case, I just click the crossed-eye icon.
The transformation converts multiple frames into one. No parameters are needed.
See here. Instead of a drop-down, I have a new column containing the country
code. And all data is in one data frame. Then I add another transformation, ' Group by'.
In the parameters section, I must specify which columns to group by. In my case, it is the
column 'Metric' which contains the country code. And for every country, I would like to
summarize all values, meaning I need the total. This transformation has an identical
concept to the SQL GROUP BY clause. With both transformations turned
ON, here in the Table View, I have two columns of data -
country and a value - exactly what my visualization panel requires.
Switch back to the visualization view, and now I can see how many requests arrived
on our website during the last 6 hours. Next, I will open this Bar Chart
visualization in edit mode. To build it, I utilized four transformations.
Let me switch to the Table View here. And make the two last transformations
invisible by clicking the eye icon. The first and second transformations
are similar to what I just reviewed. 'Series to rows' and the 'group by'.
So, on top of those two, to have my bars in descending order, I added 'sort by'. Then I
added the 'Limit' to keep only the first 15 rows. This Status visualization
uses transformations as well. If I open it in Edit mode, here I have two transformations.
To demonstrate how they work, I am switching to table view and making
transformations invisible one by one. Here, I have multiple data frames, one
for each status. On every data frame, I have time and the number of requests
with the corresponding status. This 'Join by field' transformation JOINs
all data frames by the specified column. I choose the OUTER mode to keep all rows from
all data frames. And join by the 'Time' field. After applying the 'Join by field' transformation, I have the 'time' column and separate columns
for every status. If there was no request for a particular status at the given time when
other requests occurred, I see this NULL value. "Organize fields" transformation
helps with aliases. For example, here, status 200 sounds cryptic. When I turn
the transformation ON, the titles change to the English words I entered. And the data
look more readable with meaningful titles. This format is suitable for the
stacked bars in the Time series. How do I know that? Patience and luck,
or maybe I found it in a far corner of Internet. Now it is hard to tell. There is one transformation that stands out
from all others. If I go back to the schema I showed at the beginning of this video, I
can depict that one special transformation as extra for both scenarios. You can use
it either when no other transformation is required or as an additional one to
any number of other transformations. It is called 'Config from the query
result'. It differs from all others because it sends the retrieved value directly into the panel configuration.
With that transformation, the configuration of the panel is dynamic. For example, on this time series
visualization, I have two queries. Query A fetches the data point to display
on the graph. I have values for time points. And then, query B fetches the min and max values.
In the Table view, I can see them if I select the 'min, max' data frame from the drop-down
here. It is displayed as a second data frame. Then on the transformation tab, I added Config
from query results. I want to use the query B, apply to 'Fields with type'.
Apply to options 'Number'. And I want min and max values. The moment I turn this transformation ON, I loose
the drop-down. And here, on the right-hand side, under the Standard option for min
and max, two yellow circles appear. Yellow circles mark the configuration fields
that could come directly from the data source. Also, when the transformation
is ON, there is nowhere where you can look at what has been extracted.
But you can always turn the transformation OFF, select that query in the drop-down and here
you go, review the current fetched data. I hope I have broken down the
transformations for you. There are many more you can choose from. If
anything, in particular, is confusing, feel free to post a question in
a comment section down below. Remember to subscribe. Every notification about a new subscriber transforms our focused
faces into faces with big smiles. Thank you for watching, and see you next time.