chore(metrics): Add the ability to filter searched metrics by attributes
Related #2559 (closed), #2653
This MR adds support for filtering searched metrics by their attributes. The implementation ensures filtering is done via a subquery before the necessary tables are queried, allowing for filtering bits to be pluggable without changing the main query a lot. This also paves path to improving our filtering via the use of a metadata side-table as & when that becomes available, more details around it in #2653 (comment 1820981293).
Tested on a dev-cluster with:
single filter
➜ ~ curl --silent "http://localhost:8082/v3/query/51792562/metrics/search?mname=system.cpu.time&mtype=Sum&attrs=state,eq,idle" | jq -r '.results[].attributes'
{
"cpu": "4",
"state": "idle"
}
{
"cpu": "2",
"state": "idle"
}
{
"cpu": "1",
"state": "idle"
}
{
"cpu": "3",
"state": "idle"
}
{
"cpu": "5",
"state": "idle"
}
multiple filters(1)
➜ ~ curl --silent "http://localhost:8082/v3/query/51792562/metrics/search?mname=system.cpu.time&mtype=Sum&attrs=state,eq,idle&attrs=cpu,eq,2" | jq -r '.results[].attributes'
{
"cpu": "2",
"state": "idle"
}
multiple filters(2)
➜ ~ curl --silent "http://localhost:8082/v3/query/51792562/metrics/search?mname=system.cpu.time&mtype=Sum&attrs=state,eq,idle&attrs=cpu,neq,2" | jq -r '.results[].attributes'
{
"cpu": "4",
"state": "idle"
}
{
"cpu": "1",
"state": "idle"
}
{
"cpu": "3",
"state": "idle"
}
{
"cpu": "5",
"state": "idle"
}
multiple filters, like/not like ops
➜ ~ curl --silent "http://localhost:8082/v3/query/51792562/metrics/search?mname=system.cpu.time&mtype=Sum&attrs=cpu,eq,5&attrs=state,re,i%25" | jq -r '.results[].attributes'
{
"cpu": "5",
"state": "irq"
}
{
"cpu": "5",
"state": "idle"
}
➜ ~ curl --silent "http://localhost:8082/v3/query/51792562/metrics/search?mname=system.cpu.time&mtype=Sum&attrs=cpu,eq,5&attrs=state,nre,i%25" | jq -r '.results[].attributes'
{
"cpu": "5",
"state": "system"
}
{
"cpu": "5",
"state": "user"
}
no filters, default search
➜ ~ curl --silent "http://localhost:8082/v3/query/51792562/metrics/search?mname=system.cpu.time&mtype=Sum" | jq -r '.results[].attributes'
{
"cpu": "3",
"state": "user"
}
{
"cpu": "5",
"state": "system"
}
{
"cpu": "4",
"state": "idle"
}
{
"cpu": "2",
"state": "idle"
}
{
"cpu": "1",
"state": "idle"
}
{
"cpu": "1",
"state": "user"
}
{
"cpu": "5",
"state": "irq"
}
{
"cpu": "3",
"state": "system"
}
{
"cpu": "4",
"state": "system"
}
{
"cpu": "2",
"state": "system"
}
{
"cpu": "2",
"state": "irq"
}
{
"cpu": "1",
"state": "irq"
}
{
"cpu": "3",
"state": "irq"
}
{
"cpu": "5",
"state": "user"
}
{
"cpu": "4",
"state": "user"
}
{
"cpu": "3",
"state": "idle"
}
{
"cpu": "5",
"state": "idle"
}
{
"cpu": "2",
"state": "user"
}
{
"cpu": "1",
"state": "system"
}
{
"cpu": "4",
"state": "irq"
}
query output, default state
➜ ~ curl --silent "http://localhost:8082/v3/query/51792562/metrics/search?mname=system.cpu.time&mtype=Sum&attrs=state,eq,idle&attrs=cpu,eq,2" | jq .
{
"start_ts": 1711370702237179000,
"end_ts": 1711374302237179000,
"results": [
{
"name": "system.cpu.time",
"description": "System CPU time",
"unit": "seconds",
"type": "Sum",
"attributes": {
"cpu": "2",
"state": "idle"
},
"values": [
[
1711370700000000000,
5050.25
],
[
1711370760000000000,
5102.91
],
(REDACTED)
Edited by Ankit Bhatnagar