[Serverless Knative] Knative Docs - Configuring metrics

Metrics

The metric configuration defines which metric type is watched by the Autoscaler.

Setting metrics per revision

For per-revision - https://knative.dev/docs/serving/autoscaling/autoscaler-types/#global-versus-per-revision-settings configuration, this is determined using the autoscaling.knative.dev/metric annotation. The possible metric types that can be configured per revision depend on the type of Autoscaler implementation you are using:

  • The default KPA Autoscaler supports the concurrency and rps metrics.

  • The HPA Autoscaler supports the cpu metric.

For more information about KPA and HPA, see the documentation on Supported Autoscaler types - https://knative.dev/docs/serving/autoscaling/autoscaler-types/.

  • Per-revision annotation key: autoscaling.knative.dev/metric

  • Possible values: "concurrency", "rps", "cpu", "memory" or any custom metric name, depending on your Autoscaler type. The "cpu", "memory", and "custom" metrics are only supported on revisions that use the HPA class.

  • Default: "concurrency"

Per-revision concurrency configuration

1
2
3
4
5
6
7
8
9
10
11

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
namespace: default
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/metric: "concurrency"

Per-revision rps configuration

1
2
3
4
5
6
7
8
9
10
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
namespace: default
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/metric: "rps"

Per-revision cpu configuration

1
2
3
4
5
6
7
8
9
10
11
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
namespace: default
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
autoscaling.knative.dev/metric: "cpu"

Per-revision memory configuration

1
2
3
4
5
6
7
8
9
10
11
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
namespace: default
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
autoscaling.knative.dev/metric: "memory"

Per-revision custom metric configuration

You can create an HPA to scale the revision by a metric that you specify. The HPA will be configured to use the average value of your metric over all the Pods of the revision.

1
2
3
4
5
6
7
8
9
10
11
12

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
namespace: default
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
autoscaling.knative.dev/metric: "<metric-name>"

Where <metric-name> is your custom metric.

Next steps

References

[1] Configuring metrics - Knative - https://knative.dev/docs/serving/autoscaling/autoscaling-metrics/

[2] Home - Knative - https://knative.dev/docs/

[2] About autoscaling - Knative - https://knative.dev/docs/serving/autoscaling/

[3] concurrency - https://knative.dev/docs/serving/autoscaling/concurrency/

[4] requests per second targets - https://knative.dev/docs/serving/autoscaling/rps-target/