Skip to content

Commit

Permalink
Support custom recordingRules for Prometheus
Browse files Browse the repository at this point in the history
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) <[email protected]>
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
welteki authored and alexellis committed Aug 27, 2024
1 parent eff7a82 commit 0e4465d
Show file tree
Hide file tree
Showing 16 changed files with 584 additions and 533 deletions.
2 changes: 1 addition & 1 deletion chart/openfaas/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
type: application
description: OpenFaaS - Serverless Functions Made Simple
name: openfaas
version: 14.2.72
version: 14.2.73
sources:
- https://github.com/openfaas/faas
- https://github.com/openfaas/faas-netes
Expand Down
24 changes: 23 additions & 1 deletion chart/openfaas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,28 @@ OpenFaaS Pro will only scale down functions which have marked themselves as elig

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

## Removing the OpenFaaS
## Custom autoscaling rules

In order to build custom autoscaling rules, an additional recording rule is required for Prometheus for each type of scaling you want to add.

To add latency-based scaling with the metrics recorded at the gateway, you could add the following to values.yaml:

```yaml
prometheus:
recordingRules:
- record: job:function_current_load:sum
expr: |
sum by (function_name) (rate(gateway_functions_seconds_sum{}[30s])) / sum by (function_name) (rate( gateway_functions_seconds_count{}[30s]))
and on (function_name) avg by(function_name) (gateway_service_target_load{scaling_type="latency"}) > bool 1
labels:
scaling_type: latency
```

To check the configuration of current recording rules use the Prometheus UI or run `kubectl edit -n openfaas configmap/prometheus-config`.

See also: [How to scale OpenFaaS Functions with Custom Metrics](https://www.openfaas.com/blog/custom-metrics-scaling/).

## Removing OpenFaaS

All control plane components can be cleaned up with helm:

Expand Down Expand Up @@ -671,3 +692,4 @@ For legacy scaling in OpenFaaS Community Edition.
| `prometheus.retention.time` | When to remove old data from the prometheus db. | `15d` |
| `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` |
| `prometheus.resources` | Resource limits and requests for prometheus containers | See [values.yaml](./values.yaml) |
| `prometheus.recordingRules` | Custom recording rules for autoscaling. | `[]` |
4 changes: 4 additions & 0 deletions chart/openfaas/templates/prometheus-pro-cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ data:
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 ))
labels:
scaling_type: cpu
{{- with .Values.prometheus.recordingRules }}
{{ toYaml . | nindent 6 }}
{{- end }}
- name: recently_started_1m
interval: 10s
Expand Down
1 change: 1 addition & 0 deletions chart/openfaas/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ prometheus:
memory: "512Mi"
cpu: "100m"
annotations: {}
recordingRules: []

alertmanager:
image: prom/alertmanager:v0.27.0
Expand Down
Binary file modified docs/cron-connector-0.6.11.tgz
Binary file not shown.
Binary file modified docs/federated-gateway-0.1.0.tgz
Binary file not shown.
Loading

0 comments on commit 0e4465d

Please sign in to comment.