Skip to content

Commit

Permalink
Adjust the promql query to support all the K8s versions
Browse files Browse the repository at this point in the history
The promql expression:

    sum by (group, version, kind) (apiserver_registered_watchers)
  + on () group_left ()
    absent(apiserver_longrunning_requests) * 0
or
  sum by (group, version, resource) (apiserver_longrunning_requests)

returns the result of the newer metric `apiserver_longrunning_requests` (>=1.23)
if present, otherwise it will return the `apiserver_registered_watchers` (<1.23).

Note that the "total" query used the "count" aggregation which was semantically
not meaningful. This aspect is also fixed in this commit: the registered
watchers / long running requests need to be added up to get the total value.

Co-authored-by: Istvan Zoltan Ballok <[email protected]>
Co-authored-by: Jeremy Rickards <[email protected]>
  • Loading branch information
istvanballok and rickardsjp committed Mar 17, 2023
1 parent 237a55c commit 23918d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2748,9 +2748,11 @@
"steppedLine": true,
"targets": [
{
"expr": "sum(apiserver_registered_watchers{pod=~\"$apiserver\"})by(kind)",
"exemplar": true,
"expr": " sum by (kind) (apiserver_registered_watchers{pod=~\"$apiserver\",kind!=\"\"})\n + on () group_left ()\n absent(apiserver_longrunning_requests) * 0\nor\n sum by (resource) (apiserver_longrunning_requests{pod=~\"$apiserver\",verb=\"WATCH\"})",
"hide": false,
"interval": "",
"legendFormat": "{{kind}}",
"legendFormat": "{{resource}}{{kind}}",
"refId": "A"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1319,17 +1319,21 @@
"steppedLine": false,
"targets": [
{
"expr": "apiserver_registered_watchers",
"exemplar": true,
"expr": " sum by (group, version, kind) (apiserver_registered_watchers)\n + on () group_left ()\n absent(apiserver_longrunning_requests) * 0\nor\n sum by (group, version, resource) (apiserver_longrunning_requests)",
"format": "time_series",
"hide": false,
"interval": "",
"intervalFactor": 1,
"legendFormat": "{{group}}/{{version}}/{{kind}}",
"legendFormat": "{{group}}/{{version}}/{{resource}}{{kind}}",
"refId": "A"
},
{
"expr": "count(apiserver_registered_watchers)\n",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "total",
"exemplar": true,
"expr": "sum(\n sum by (group, version, kind) (apiserver_registered_watchers)\n + on () group_left ()\n absent(apiserver_longrunning_requests) * 0\n or\n sum by (group, version, resource) (apiserver_longrunning_requests)\n)",
"hide": false,
"interval": "",
"legendFormat": "Total",
"refId": "B"
}
],
Expand All @@ -1353,15 +1357,17 @@
},
"yaxes": [
{
"$$hashKey": "object:244",
"decimals": 0,
"format": "short",
"label": "Count Watches",
"logBase": 10,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:245",
"format": "short",
"label": null,
"logBase": 1,
Expand Down

0 comments on commit 23918d1

Please sign in to comment.