Workload-specific request-related metrics

Hello!

I’d like to have my application/workload -specific metrics in Istio. The custom metrics that the app generates regarding the requests it processes.

I’m thinking about utilizing the Stats extension, while the app would put its metrics to the HTTP response headers. Like that

"definitions": [
  {
    "name": "my_custom_metric",
    "value": "response.headers['my-metric-value']",
    "type": "COUNTER"
  }
],
"metrics": [
  {
    "name": "my_custom_metric",
    "dimensions": {
      "my_custom_tag_1": "response.headers['my-metric-tag-1']",
      "my_custom_tag_2": "response.headers['my-metric-tag-2']"
    }
  }
]

I have 2 questions regarding that.

1) The docs only cover the case of adding the Stats config that would be applied to all the workloads in the mesh, how can I add a per-workload config?

I mean I can add the above config to the Istio’s stats-filter-1.6.yaml but that would be applied to all the apps in the mesh.

I tried adding per-app Stats filters - while not overriding the system’s stats-filter-1.6.yaml - creating new EnvoyFilter resource with Stats configs, and having there

workloadSelector:
  labels:
    app: myapp

but it doesn’t work - the metrics are either double-counting the requests (if I use operation: INSERT_BEFORE) or the metrics disappear (if I use operation: MERGE).

2) And the 2nd question - I’d like the custom metrics to have all the request/response dimensions that the default Istio metrics are having, i.e. source_workload, source_version, response_code, destination_service_name, and others.

Is there a way to do that, or I’d need manually adding those?