concept metric in category istio

This is an excerpt from Manning's book Istio in Action.
Basic resilience and metric collection are horizontal concerns and are not application specific. Moreover, these are not differentiating business concerns. Developers are critical resources in a large IT systems and their time is best spent writing capabilities that deliver business value in a differentiating way. Application networking and metrics are a necessary practice, but they aren’t differentiating. What we’d like is a way to implement these capabilities in a language and framework agnostic way and expose them as "application infrastructure services" that can be consumed without any special application considerations. Any application with any developers should be able to properly build cloud-native applications without worrying about what nasty bugs they may have introduced because of the network. Application resilience, observability, traffic control, security, and policy all fall into the category of "horizontal concerns" that should be implemented in supporting infrastructure not the application itself.
Prometheus is a metrics-collection engine and set of related monitoring and alerting tools that originated at SoundCloud and was loosely based on Google’s internal monitoring system Borgmon (in a similar way that Kubernetes was based on Borg). Prometheus is slighly different from other telemetry or metrics collection systems in that it "pulls" metrics from its targets rather than listens for the targets to send their metrics to it. For example, in the previous section, we set up the Istio service proxy to push metrics to statsd. With Prometheus, we expect our applications or the Istio service proxy to expose an endpoint with the latest metrics from which Prometheus can the pull or scrape the metrics. In this book we won’t get into the discussion about whether pull or push metric collection is better but we’ll acknowledge both exist and an organization may choose one over the other or both. Please see this podcast with Brian Brazil to hear more about Pormetheus' approach to pull-based metrics and how it differs from "push" based systems.
Figure 7.3. Prometheus scraping Istio service proxy for metrics
![]()
So far we’ve seen how to collect and visualize metrics from the service proxies running in a mesh. The metrics we’re able to collect are from a pre-defined set of metrics that the Istio service proxy collects and makes available. In a real production environment, you may find that you will want to fine-tune which metrics you capture from both the set of pre-defined metrics as well as possibly introducing new ones.
The metrics that we collected in the previous section originate from the Istio service proxy and get sent to or pulled into a metrics-collection engine or time-series database. Although there are a lot of metrics, they are a fixed set that are not easily extendable. If we want to introduce a new metric to our observability tools, we’ll need to explore a different path.
Creating a new metric to capture in Istio Telemetry requires a few different configuration objects. The first thing we want to do is define what attributes will comprise our new metric. Istio refers to these as
dimensionsin it’s configuration. Next, we want to tell Istio where should these new metrics go. We’ll discuss more about Istio Telemetry and Policy, but just know that these components are extendable with adapters and when we specify where to send a metric for this example, we need to specify and configure a specific adapter to handle the metric. Lastly, we need to define what matching criteria are required to trigger creating the metric. In the following example, we’re going to define a specific new metric calledapigatewayrequestcountthat will count the number of requests going to the api gateway component and will only match if a request is sent to the api-gateway component. For those metrics, we will send them to the Prometheus adapter.Let’s start by creating a new
metricin Istio. To do that, take a look at the following:apiVersion: "config.istio.io/v1alpha2" kind: metric metadata: name: apigatewayrequestcount namespace: istio-system spec: value: "1" #1 dimensions: source: source.workload.name | "unknown" #2 destination: destination.workload.name | "unknown" destination_ip: destination.ip monitored_resource_type: '"UNSPECIFIED"'This
metricspecifies what request attributes we are interested in and what dimensions of the metric we want to report. For this simple example, let’s say we want to create a metric which specifically counts how many requests are made to our apigateway service. In the above, we set thevalueof the metric to1and we track thedimensionslikesource,destinationanddestination_ip. We are using the value of1for this metric because we want to count each request once. Thevaluefield can also contain expressions that evaluate to numbers, strings, IP addresses, and others. Please see the Istio reference documentation on metrics for more.