Only show metric from specific destination

Hi,

I’m struggeling defining new metrics. After reading through the docs and googling I still don’t get how the metrics are working.

# Configuration for metric instances
apiVersion: "config.istio.io/v1alpha2"
kind: metric
metadata:
  name: doublerequestcount
  namespace: istio-system
spec:
  value: "2" # count each request twice
  dimensions:
    reporter: conditional((context.reporter.kind | "inbound") == "outbound", "client", "server")
    source: source.workload.name | "unknown"
    destination: destination.service.name == "mongo"
    message: '"twice the fun13"'
  monitored_resource_type: '"UNSPECIFIED"'
---
# Configuration for a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: prometheus
metadata:
  name: doublehandler
  namespace: istio-system
spec:
  metrics:
  - name: double_request_count # Prometheus metric name
    instance_name: doublerequestcount.metric.istio-system # Mixer instance name (fully-qualified)
    kind: COUNTER
    label_names:
    - reporter
    - source
    - destination
    - message
---
# Rule to send metric instances to a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
  name: doubleprom
  namespace: istio-system
spec:
  #match: destination.service.name == "admiralsrv"
  actions:
  - handler: doublehandler.prometheus
    instances:
    - doublerequestcount.metric

I want to achieve that this metric only shows traffic between anything going to mongo. Using this config I’m still getting destination: false results like this:
istio_double_request_count{destination="false",instance="172.17.0.11:42422",job="istio-mesh",message="twice the fun13",reporter="server",source="testsrv"}

Any advise on how to proceed here to accomplish this?

Thanks a lot

You need to remove the expression in your instance config.

You have:

destination: destination.service.name == "mongo".

Instead, you want something like:

destination: destination.service.name

Then, you want to use the match clause in the rule to check for mongo. Uncomment the match line and try:

match: destination.service.name == "mongo"

The match bit will control when the instances are generated and passed to the handler.

Does that make sense?

1 Like

Starring too long at it gets me confused.

Works like a charm.

Thanks