How Select multiple labels in single query?

I have labels “label_app”, “label_id”, “label_key”. i wanna select label values of each labels in single query ?
label_values(kube_pod_labels{namespace="$namespace", pod=~"$pod"}, label_key) so by doing this i can get value only for label_key.

It is a bit tricky, but it is possible.

1st, you need to create a query that returns everything you need as one label. You can use the “label_join” query function for this:

query_result(label_join( max by (hostname,nodeid) (node_clients.total[1y]) , "result", " - ", "nodeid", "hostname"))

This finds a max for each hostname/nodeid combination in node_clients.total from the last year (so not exactly ‘all’ labels, but good enough for me).

A resulting line in my case would look like

{hostname="104-3-server",nodeid="000000002664",result="000000002664 - 104-3-server"} 0 1637414285000

That’s perfect to be processed by the regexp below. In my case I use:

/result="(?<text>[^"]+)|nodeid="(?<value>[^"]+)/g

Which gives me “result” as label and the nodeid as value for my dropdown.

No, I’m not looking … and ONE request is enough .:wink:

This topic was automatically closed after 365 days. New replies are no longer allowed.