Traffic Metrics

Kuma facilitates consistent traffic metrics across all data plane proxies in your mesh.

You can add metrics to a mesh configuration, or to an individual data plane proxy configuration. For example, you might need metrics for individual data plane proxies to override the default metrics port if it’s already in use on the specified machine.

Kuma provides full integration with Prometheus:

  • Each proxy can expose its metrics in Prometheus format.
  • Because metrics are part of the mesh configuration, Kuma exposes an API called the monitoring assignment service (MADS) which exposes every proxy in the mesh.

To collect metrics from Kuma, you need to expose metrics from proxies and applications.

In the rest of this page we assume you have already configured your observability tools to work with Kuma. If you haven’t already read the observability docs.

Expose metrics from data plane proxies

To expose metrics from every proxy in the mesh, configure the Mesh resource:

  1. apiVersion: kuma.io/v1alpha1
  2. kind: Mesh
  3. metadata:
  4. name: default
  5. spec:
  6. metrics:
  7. enabledBackend: prometheus-1
  8. backends:
  9. - name: prometheus-1
  10. type: prometheus

which is a shortcut for:

  1. apiVersion: kuma.io/v1alpha1
  2. kind: Mesh
  3. metadata:
  4. name: default
  5. spec:
  6. metrics:
  7. enabledBackend: prometheus-1
  8. backends:
  9. - name: prometheus-1
  10. type: prometheus
  11. conf:
  12. tls:
  13. mode: activeMTLSBackend
  14. port: 5670
  15. path: /metrics
  16. tags: # tags that can be referred in Traffic Permission when metrics are secured by mTLS
  17. kuma.io/service: dataplane-metrics
  1. type: Mesh
  2. name: default
  3. metrics:
  4. enabledBackend: prometheus-1
  5. backends:
  6. - name: prometheus-1
  7. type: prometheus
  8. conf:
  9. tls:
  10. mode: disabled

which is a shortcut for:

  1. type: Mesh
  2. name: default
  3. metrics:
  4. enabledBackend: prometheus-1
  5. backends:
  6. - name: prometheus-1
  7. type: prometheus
  8. conf:
  9. port: 5670
  10. path: /metrics
  11. tags: # tags that can be referred in Traffic Permission when metrics are secured by mTLS
  12. kuma.io/service: dataplane-metrics
  13. tls:
  14. mode: disabled

This tells Kuma to configure every proxy in the default mesh to expose an HTTP endpoint with Prometheus metrics on port 5670 and URI path /metrics.

The metrics endpoint is forwarded to the standard Envoy Prometheus metrics endpoint and supports the same query parameters. You can pass the filter query parameter to limit the results to metrics whose names match a given regular expression. By default all available metrics are returned.

Secure metrics with TLS

Kuma allows configuring metrics endpoint with TLS. You can use it when the Prometheus deployment is outside of the mesh and requires secure communication.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: Mesh
  3. metadata:
  4. name: default
  5. spec:
  6. metrics:
  7. enabledBackend: prometheus-1
  8. backends:
  9. - name: prometheus-1
  10. type: prometheus
  11. conf:
  12. port: 5670
  13. path: /metrics
  14. tls:
  15. mode: providedTLS

In addition to the Mesh configuration, kuma-sidecar requires a provided certificate and key for its operation. When the certificate and key are available within the container, kuma-sidecar needs the paths to provided files as the following environment variables:

  • KUMA_DATAPLANE_RUNTIME_METRICS_CERT_PATH
  • KUMA_DATAPLANE_RUNTIME_METRICS_KEY_PATH

It’s possible to use a ContainerPatch to add variables to kuma-sidecar:

  1. apiVersion: kuma.io/v1alpha1
  2. kind: ContainerPatch
  3. metadata:
  4. name: container-patch-1
  5. namespace: kuma-system
  6. spec:
  7. sidecarPatch:
  8. - op: add
  9. path: /env/-
  10. value: '{
  11. "name": "KUMA_DATAPLANE_RUNTIME_METRICS_CERT_PATH",
  12. "value": "/kuma/server.crt"
  13. }'
  14. - op: add
  15. path: /env/-
  16. value: '{
  17. "name": "KUMA_DATAPLANE_RUNTIME_METRICS_KEY_PATH",
  18. "value": "/kuma/server.key"
  19. }'
  1. type: Mesh
  2. name: default
  3. metrics:
  4. enabledBackend: prometheus-1
  5. backends:
  6. - name: prometheus-1
  7. type: prometheus
  8. conf:
  9. port: 5670
  10. path: /metrics
  11. tls:
  12. mode: providedTLS

In addition to the Mesh configuration, kuma-dp requires a provided certificate and key for its operation. Please upload the certificate and the key to the machine, and then define the following environment variables with the correct paths:

  1. * KUMA_DATAPLANE_RUNTIME_METRICS_CERT_PATH
  2. * KUMA_DATAPLANE_RUNTIME_METRICS_KEY_PATH

Expose metrics from applications

In addition to exposing metrics from the data plane proxies, you might want to expose metrics from applications running next to the proxies. Kuma allows scraping Prometheus metrics from the applications endpoint running in the same Pod or VM. Later those metrics are aggregated and exposed at the same port/path as data plane proxy metrics. It is possible to configure it at the Mesh level, for all the applications in the Mesh, or just for specific applications.

Here are reasons where you’d want to use this feature:

  • Application metrics are labelled with your mesh parameters (tags, mesh, data plane name…), this means that in mixed Universal and Kubernetes mode metrics are reported with the same types of labels.
  • Both application and sidecar metrics are scraped at the same time. This makes sure they are coherent (with 2 different scrapers they can end up scraping at different intervals and make metrics harder to correlate).
  • If you disable passthrough and your mesh uses mTLS but Prometheus is outside the mesh (tls.mode: disabled) this is the only way to retrieve these metrics as the app is completely hidden behind the sidecar.

Any configuration change requires redeployment of the data plane.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: Mesh
  3. metadata:
  4. name: default
  5. spec:
  6. metrics:
  7. enabledBackend: prometheus-1
  8. backends:
  9. - name: prometheus-1
  10. type: prometheus
  11. conf:
  12. port: 5670
  13. path: /metrics
  14. tags: # tags that can be referred in Traffic Permission when metrics are secured by mTLS
  15. kuma.io/service: dataplane-metrics
  16. tls:
  17. mode: activeMTLSBackend
  18. aggregate:
  19. - name: my-service # name of the metric, required to later disable/override with pod annotations
  20. path: "/metrics/prometheus"
  21. port: 8888
  22. - name: other-sidecar
  23. # default path is going to be used, default: /metrics
  24. port: 8000
  1. type: Mesh
  2. name: default
  3. metrics:
  4. enabledBackend: prometheus-1
  5. backends:
  6. - name: prometheus-1
  7. type: prometheus
  8. conf:
  9. port: 5670
  10. path: /metrics
  11. tls:
  12. mode: disabled
  13. aggregate:
  14. - name: my-service # name of the metric, required to later disable/override in the Dataplane resource
  15. path: "/metrics/prometheus"
  16. port: 8888
  17. - name: other-sidecar
  18. # default path is going to be used, default: /metrics
  19. port: 8000

This configuration will cause every application in the mesh to be scrapped for metrics by the data plane proxy. If you need to expose metrics only for the specific application it is possible through annotation for Kubernetes or Dataplane resource for Universal deployment.

Kubernetes allows to configure it through annotations. In case to configure you can use prometheus.metrics.kuma.io/aggregate-<name>-(path/port/enabled), where name is used to match the Mesh configuration and override or disable it.

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. namespace: kuma-example
  5. name: kuma-tcp-echo
  6. spec:
  7. ...
  8. template:
  9. metadata:
  10. ...
  11. annotations:
  12. prometheus.metrics.kuma.io/aggregate-my-service-enabled: "false" # causes that configuration from Mesh to be disabled and result in this endpoint's metrics to not be exposed
  13. prometheus.metrics.kuma.io/aggregate-other-sidecar-port: "1234" # override port from Mesh
  14. prometheus.metrics.kuma.io/aggregate-application-port: "80"
  15. prometheus.metrics.kuma.io/aggregate-application-path: "/stats"
  16. spec:
  17. containers:
  18. ...
  1. type: Dataplane
  2. mesh: default
  3. name: example
  4. metrics:
  5. type: prometheus
  6. conf:
  7. path: /metrics/overridden
  8. aggregate:
  9. - name: my-service # causes that configuration from Mesh to be disabled and result in this endpoint's metrics to not be exposed
  10. enabled: false
  11. - name: other-sidecar
  12. port: 1234 # override port from Mesh
  13. address: "127.0.0.1"
  14. - name: application
  15. path: "/stats"
  16. port: 80`

By default, sidecar scrapes metrics on dataplane.networking.address. If you set dataplane.networking.inbound[].address.serviceAddress, and you want to scrape metrics from the application, you also need to set dataplane.metrics.conf.aggregate[].address.

Override Prometheus settings per data plane proxy

To override mesh-wide defaults for a particular Pod, use the following annotations:

  • prometheus.metrics.kuma.io/port - to override mesh-wide default port
  • prometheus.metrics.kuma.io/path - to override mesh-wide default path

For example:

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. namespace: kuma-example
  5. name: kuma-tcp-echo
  6. spec:
  7. ...
  8. template:
  9. metadata:
  10. ...
  11. annotations:
  12. prometheus.metrics.kuma.io/port: "1234" # override Mesh-wide default port
  13. prometheus.metrics.kuma.io/path: "/non-standard-path" # override Mesh-wide default path
  14. spec:
  15. containers:
  16. ...

Proxies for this Pod expose an HTTP endpoint with Prometheus metrics on port 1234 and URI path /non-standard-path.

To override mesh-wide defaults on a particular machine, configure the Dataplane resource:

  1. type: Dataplane
  2. mesh: default
  3. name: example
  4. metrics:
  5. type: prometheus
  6. conf:
  7. tls:
  8. mode: activeMTLSBackend
  9. port: 1234
  10. path: /non-standard-path

This proxy exposes an HTTP endpoint with Prometheus metrics on port 1234 and URI path /non-standard-path.

Filter Envoy metrics

In case you don’t want to retrieve all Envoy’s metrics, it’s possible to filter them. Configuration is dynamic and doesn’t require a restart of a sidecar. You are able to specify regex which causes that metric’s endpoint returns only matching metrics. Also, you can set flag usedOnly that returns only metrics updated by Envoy.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: Mesh
  3. metadata:
  4. name: default
  5. spec:
  6. metrics:
  7. enabledBackend: prometheus-1
  8. backends:
  9. - name: prometheus-1
  10. type: prometheus
  11. conf:
  12. tls:
  13. mode: activeMTLSBackend
  14. port: 5670
  15. path: /metrics
  16. envoy:
  17. filterRegex: http2_act.*
  18. usedOnly: true
  1. type: Mesh
  2. name: default
  3. metrics:
  4. enabledBackend: prometheus-1
  5. backends:
  6. - name: prometheus-1
  7. type: prometheus
  8. conf:
  9. port: 5670
  10. path: /metrics
  11. envoy:
  12. filterRegex: http2_act.*
  13. usedOnly: true

Secure data plane proxy metrics

Kuma lets you expose proxy metrics in a secure way by leveraging mTLS. Prometheus needs to be a part of the mesh for this feature to work, which is the default deployment mode on Kubernetes when using kumactl install observability.

Make sure that mTLS is enabled in the mesh.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: Mesh
  3. metadata:
  4. name: default
  5. spec:
  6. mtls:
  7. enabledBackend: ca-1
  8. backends:
  9. - name: ca-1
  10. type: builtin
  11. metrics:
  12. enabledBackend: prometheus-1
  13. backends:
  14. - name: prometheus-1
  15. type: prometheus
  16. conf:
  17. port: 5670
  18. path: /metrics
  19. tls:
  20. mode: activeMTLSBackend
  21. tags: # tags that can be referred in a TrafficPermission resource
  22. kuma.io/service: dataplane-metrics

If you have strict traffic permissions you will want to allow the traffic from Grafana to Prometheus and from Prometheus to data plane proxy metrics:

  1. apiVersion: kuma.io/v1alpha1
  2. kind: TrafficPermission
  3. mesh: default
  4. metadata:
  5. name: metrics-permissions
  6. spec:
  7. sources:
  8. - match:
  9. kuma.io/service: prometheus-server_mesh-observability_svc_80
  10. destinations:
  11. - match:
  12. kuma.io/service: dataplane-metrics
  13. ---
  14. apiVersion: kuma.io/v1alpha1
  15. kind: TrafficPermission
  16. mesh: default
  17. metadata:
  18. name: grafana-to-prometheus
  19. spec:
  20. sources:
  21. - match:
  22. kuma.io/service: "grafana_mesh-observability_svc_80"
  23. destinations:
  24. - match:
  25. kuma.io/service: "prometheus-server_mesh-observability_svc_80"

Make sure that mTLS is enabled in the mesh.

  1. type: Mesh
  2. name: default
  3. spec:
  4. mtls:
  5. enabledBackend: ca-1
  6. backends:
  7. - name: ca-1
  8. type: builtin
  9. metrics:
  10. enabledBackend: prometheus-1
  11. backends:
  12. - name: prometheus-1
  13. type: prometheus
  14. conf:
  15. port: 5670
  16. path: /metrics
  17. tls:
  18. mode: activeMTLSBackend
  19. tags: # tags that can be referred in a TrafficPermission resource
  20. kuma.io/service: dataplane-metrics

If you have strict traffic permissions you will want to allow the traffic from Grafana to Prometheus and from Prometheus to data plane proxy metrics:

  1. type: TrafficPermission
  2. mesh: default
  3. name: metrics-permissions
  4. spec:
  5. sources:
  6. - match:
  7. kuma.io/service: prometheus-server
  8. destinations:
  9. - match:
  10. kuma.io/service: dataplane-metrics
  11. ---
  12. type: TrafficPermission
  13. mesh: default
  14. name: grafana-to-prometheus
  15. spec:
  16. sources:
  17. - match:
  18. kuma.io/service: "grafana"
  19. destinations:
  20. - match:
  21. kuma.io/service: "prometheus-server"