prometheus-sql icon indicating copy to clipboard operation
prometheus-sql copied to clipboard

Support to add statically defined Prometheus labels to queries

Open yosefy opened this issue 7 years ago • 9 comments

without injecting columns to query? like

labels: x: y a: b

yosefy avatar Jul 04 '17 10:07 yosefy

Hi @yosefy

Can you please give us a more complete example of what kind of feature you want to see in prometheus-sql.

Cheers!

haxorof avatar Jul 07 '17 16:07 haxorof

say we have a query that will give us amount of cars of type ford and they all green but query doesn"t have color column and type is called "__Type" (and i want "type" but i don"t want to touch the query as i have 50 of them in different shapes) so i dont want to use the column name (may be i do and may be i don"t) so i want to just manually add labels:

labels: type: ford color: green

just another yaml part for adding more labels to result then columns it has i hope i explained better :)

thanks

yosefy avatar Jul 08 '17 07:07 yosefy

If I understood you correctly here then the end result in the metric endpoint would have to additional labels "type" and "color" which does not actually come from the SQL query itself, just added on afterwards.

@yosefy: Is this correctly understood?

haxorof avatar Jul 08 '17 08:07 haxorof

yes exactly. thanks

yosefy avatar Jul 08 '17 08:07 yosefy

FYI We do it like this:

SELECT "ford" as type, "green" as color, foobar FROM foobar

roidelapluie avatar Nov 30 '17 14:11 roidelapluie

Depending on the DB you might need single quotes instead of double quotes

roidelapluie avatar Nov 30 '17 14:11 roidelapluie

Would be great to have this fixed because even when fetching would fail we would have labels (metric_name{type="ford"} -1)

roidelapluie avatar Nov 30 '17 21:11 roidelapluie

I am willing to work on this once #37 is merged.

roidelapluie avatar Nov 30 '17 21:11 roidelapluie

I've added documentation on how to do this in pull request #66

pschou avatar Nov 01 '20 01:11 pschou