Metrics

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

Setting metrics per revision

For per-revision 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.

  • 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 supported on revisions that use the HPA class.
  • Default: "concurrency"

ConcurrencyRequests per secondCPUMemoryCustom metric

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

Note

The autoscaling.knative.dev/target-utilization-percentage annotation for “Concurrency” specifies a percentage value. See Configuring targets for more details.

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

Note

The autoscaling.knative.dev/target annotation for “Requests per second” specifies an integer value. See Configuring targets for more details.

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

Note

The autoscaling.knative.dev/target annotation for “CPU” specifies the integer value in millicore. See Configuring targets for more details.

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

Note

The autoscaling.knative.dev/target annotation for “Memory” specifies the integer value in Mi. See Configuring targets for more details.

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. apiVersion: serving.knative.dev/v1
  2. kind: Service
  3. metadata:
  4. name: helloworld-go
  5. namespace: default
  6. spec:
  7. template:
  8. metadata:
  9. annotations:
  10. autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
  11. autoscaling.knative.dev/metric: "<metric-name>"
  12. autoscaling.knative.dev/target: "<target>"

Where <metric-name> is your custom metric.

Next steps