Skip to content

Commit 0e4465d

Browse files
weltekialexellis
authored andcommitted
Support custom recordingRules for Prometheus
Custom recordingRules can be added to the installation via Helm for custom autoscaling rules. See the README for more information. Closes: #1225 Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com> Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent eff7a82 commit 0e4465d

16 files changed

+584
-533
lines changed

chart/openfaas/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
type: application
33
description: OpenFaaS - Serverless Functions Made Simple
44
name: openfaas
5-
version: 14.2.72
5+
version: 14.2.73
66
sources:
77
- https://github.com/openfaas/faas
88
- https://github.com/openfaas/faas-netes

chart/openfaas/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,28 @@ OpenFaaS Pro will only scale down functions which have marked themselves as elig
409409

410410
See also: [Scale to Zero docs](https://docs.openfaas.com/openfaas-pro/scale-to-zero/).
411411

412-
## Removing the OpenFaaS
412+
## Custom autoscaling rules
413+
414+
In order to build custom autoscaling rules, an additional recording rule is required for Prometheus for each type of scaling you want to add.
415+
416+
To add latency-based scaling with the metrics recorded at the gateway, you could add the following to values.yaml:
417+
418+
```yaml
419+
prometheus:
420+
recordingRules:
421+
- record: job:function_current_load:sum
422+
expr: |
423+
sum by (function_name) (rate(gateway_functions_seconds_sum{}[30s])) / sum by (function_name) (rate( gateway_functions_seconds_count{}[30s]))
424+
and on (function_name) avg by(function_name) (gateway_service_target_load{scaling_type="latency"}) > bool 1
425+
labels:
426+
scaling_type: latency
427+
```
428+
429+
To check the configuration of current recording rules use the Prometheus UI or run `kubectl edit -n openfaas configmap/prometheus-config`.
430+
431+
See also: [How to scale OpenFaaS Functions with Custom Metrics](https://www.openfaas.com/blog/custom-metrics-scaling/).
432+
433+
## Removing OpenFaaS
413434

414435
All control plane components can be cleaned up with helm:
415436

@@ -671,3 +692,4 @@ For legacy scaling in OpenFaaS Community Edition.
671692
| `prometheus.retention.time` | When to remove old data from the prometheus db. | `15d` |
672693
| `prometheus.retention.size` | The maximum number of bytes of storage blocks to retain. Units supported: B, KB, MB, GB, TB, PB, EB. 0 meaning disabled. See: [Prometheus storage](https://prometheus.io/docs/prometheus/latest/storage/#operational-aspects)| `0` |
673694
| `prometheus.resources` | Resource limits and requests for prometheus containers | See [values.yaml](./values.yaml) |
695+
| `prometheus.recordingRules` | Custom recording rules for autoscaling. | `[]` |

chart/openfaas/templates/prometheus-pro-cfg.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ data:
207207
expr: ceil(sum(irate ( pod_cpu_usage_seconds_total{}[1m])*1000) by (function_name) * on (function_name) avg by (function_name) (gateway_service_target_load{scaling_type="cpu"} > bool 1 ))
208208
labels:
209209
scaling_type: cpu
210+
211+
{{- with .Values.prometheus.recordingRules }}
212+
{{ toYaml . | nindent 6 }}
213+
{{- end }}
210214
211215
- name: recently_started_1m
212216
interval: 10s

chart/openfaas/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ prometheus:
360360
memory: "512Mi"
361361
cpu: "100m"
362362
annotations: {}
363+
recordingRules: []
363364

364365
alertmanager:
365366
image: prom/alertmanager:v0.27.0

docs/cron-connector-0.6.11.tgz

1 Byte
Binary file not shown.

docs/federated-gateway-0.1.0.tgz

-1 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)