Customizing Istio Metrics with Telemetry API
Telemetry API has been in Istio as a first-class API for quite sometime now. Previously, users had to configure metrics in the telemetry section of the Istio configuration.
This task shows you how to customize the metrics that Istio generates with Telemetry API.
Before you begin
Install Istio in your cluster and deploy an application.
Telemetry API can not work together with EnvoyFilter. For more details please checkout this issue.
Starting with Istio version
1.18, the PrometheusEnvoyFilterwill not be installed by default, and insteadmeshConfig.defaultProvidersis used to enable it. Telemetry API should be used to further customize the telemetry pipeline.For versions of Istio before
1.18, you should install with the followingIstioOperatorconfiguration:apiVersion: install.istio.io/v1alpha1kind: IstioOperatorspec:values:telemetry:enabled: truev2:enabled: false
Override metrics
The metrics section provides values for the metric dimensions as expressions, and allows you to remove or override the existing metric dimensions. You can modify the standard metric definitions using tags_to_remove or by re-defining a dimension.
Remove
grpc_response_statustags fromREQUEST_COUNTmetricapiVersion: telemetry.istio.io/v1alpha1kind: Telemetrymetadata:name: remove-tagsnamespace: istio-systemspec:metrics:- providers:- name: prometheusoverrides:- match:mode: CLIENT_AND_SERVERmetric: REQUEST_COUNTtagOverrides:grpc_response_status:operation: REMOVE
Add custom tags for
REQUEST_COUNTmetricapiVersion: telemetry.istio.io/v1alpha1kind: Telemetrymetadata:name: custom-tagsnamespace: istio-systemspec:metrics:- overrides:- match:metric: ALL_METRICSmode: CLIENTtagOverrides:destination_x:value: upstream_peer.labels['app'].value- match:metric: ALL_METRICSmode: SERVERtagOverrides:source_x:value: downstream_peer.labels['app'].valueproviders:- name: prometheus
Disable metrics
Disable all metrics by following configuration:
apiVersion: telemetry.istio.io/v1alpha1kind: Telemetrymetadata:name: remove-all-metricsnamespace: istio-systemspec:metrics:- providers:- name: prometheusoverrides:- disabled: truematch:mode: CLIENT_AND_SERVERmetric: ALL_METRICS
Disable
REQUEST_COUNTmetrics by following configuration:apiVersion: telemetry.istio.io/v1alpha1kind: Telemetrymetadata:name: remove-request-countnamespace: istio-systemspec:metrics:- providers:- name: prometheusoverrides:- disabled: truematch:mode: CLIENT_AND_SERVERmetric: REQUEST_COUNT
Disable
REQUEST_COUNTmetrics for client by following configuration:apiVersion: telemetry.istio.io/v1alpha1kind: Telemetrymetadata:name: remove-clientnamespace: istio-systemspec:metrics:- providers:- name: prometheusoverrides:- disabled: truematch:mode: CLIENTmetric: REQUEST_COUNT
Disable
REQUEST_COUNTmetrics for server by following configuration:apiVersion: telemetry.istio.io/v1alpha1kind: Telemetrymetadata:name: remove-servernamespace: istio-systemspec:metrics:- providers:- name: prometheusoverrides:- disabled: truematch:mode: SERVERmetric: REQUEST_COUNT
Verify the results
Send traffic to the mesh. For the Bookinfo sample, visit http://$GATEWAY_URL/productpage in your web browser or issue the following command:
$ curl "http://$GATEWAY_URL/productpage"
$GATEWAY_URL is the value set in the Bookinfo example.
Use the following command to verify that Istio generates the data for your new or modified dimensions:
$ istioctl x es "$(kubectl get pod -l app=productpage -o jsonpath='{.items[0].metadata.name}')" -oprom | grep istio_requests_total | grep -v TYPE |grep -v 'reporter="destination"'
$ istioctl x es "$(kubectl get pod -l app=details -o jsonpath='{.items[0].metadata.name}')" -oprom | grep istio_requests_total
For example, in the output, locate the metric istio_requests_total and verify it contains your new dimension.
It might take a short period of time for the proxies to start applying the config. If the metric is not received, you may retry sending requests after a short wait, and look for the metric again.