How to look up lables from another table?

  • What Grafana version and what operating system are you using?
    10.3.4 on Docker and Firefox

  • What are you trying to achieve?
    I have a graphite wildcard query “device.*.metric” and I can use aliasByNode to extract the values that matched the wildcards as my series labels. All good. However the labels are just short device ID’s. I’d like to display the full device name but this data is not stored in graphite, it would need to be queried from MySQL datasource.

  • How are you trying to achieve it?

I have added a second MySQL query to my panel “SELECT id,name FROM device;” which brings back the device names. I thought I could use transform to lookup the label from the other data set or a regexp replace to relabel them.

  • What happened?

Couldn’t find a way to achieve it.

  • What did you expect to happen?

Success!

Use join transformation.

Hi thanks for suggestion, as I said I’ve tried transforms and couldnt find a way to achieve it. Since you suggest join transform I taken a deeper look into them but still cant seem to figure out how to specify the join fields, or I’m doing something wrong. Could you give more specifics? Here is some sample data:

This is from mysql for simplicity but demonstrates how my timeseries data comes out of graphite:

select now() as time, 1 as a, 2 as b, 3 as c;
+---------------------+---+---+---+
| time                | a | b | c |
+---------------------+---+---+---+
| 2024-03-12 15:18:27 | 1 | 2 | 3 |
+---------------------+---+---+---+

This is how i can get my device id to name mapping from mysql:

select "a" as id, "Long name for a" as name UNION ALL SELECT "b","Long name for b" UNION ALL SELECT "c","Long name for c" UNION ALL SELECT "d","Long name for d";
+----+-----------------+
| id | name            |
+----+-----------------+
| a  | Long name for a |
| b  | Long name for b |
| c  | Long name for c |
| d  | Long name for d |
+----+-----------------+

and this is how I want to transform the data to be:

+---------------------+-----------------+-----------------+-----------------+
| time                | Long name for a | Long name for b | Long name for c |
+---------------------+-----------------+-----------------+-----------------+
| 2024-03-12 15:18:27 |               1 |               2 |               3 |
+---------------------+-----------------+-----------------+-----------------+

No matter if I use “join by field” or “join by label” transform and what field i select my data does not come back like what i need!

group by matrix is what might solve your issue which is trying to pivot the data

OK, you should to show data format first. You don’t have right format for join. Join needs:

+---------------------+----+-------+
| time                | id | value |
+---------------------+----+-------+
| 2024-03-12 15:18:27 | a  | 1     |
| 2024-03-12 15:18:27 | b  | 1     |
| 2024-03-12 15:18:27 | c  | 1     |
+---------------------+----+-------+


+----+-----------------+
| id | name            |
+----+-----------------+
| a  | Long name for a |
| b  | Long name for b |
| c  | Long name for c |
| d  | Long name for d |
+----+-----------------+

Also your case is not join, but it is “rename” timeseries from the Grafana perspective. I don’t believe you can do it with transformation. But nothing stopping you to create overrides and rename each field manually. But I would create suitable data for join transformation.

I see. Unfortunately the data from graphite wildcard query “device.*.metric” comes back in the format I’ve show. I dont think I can change that and we don’t know what metrics will be returned ahead of time to create manual overrides, and there would be a lot!

I guess I could use a transform to get it into the required format for join then a rename!

We area actually experimenting with updating the dashboard programmatically through api and adding an override for each possible result, it will be hundreds of overrides but first prototype seems fairly responsive.

I think I will stop pursuing the transform/join route. Thanks anyway :slight_smile:

Yes, maybe you can use another transformation, just to prepare data for join transformation first.
I would say it is not unusual to have more transformations.
I have a case where I have 3 different datasource types and I need ~30 transformations just to be able to join them into one single table. That needs a lot of try/check iterations.