使用 Telemetry 自定义资源自定义 Istio 指标

问题描述 投票:0回答:1

在 istio 的早期版本中,我们使用

EnvoyFilter
自定义资源向指标添加自定义标签。作为其中的一部分,我们可以添加几个匹配条件以将值映射到输出属性。

例如下面的

EnvoyFilter
输出属性
istio_operationId
值将根据几个条件进行映射。

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: "vault-ef"
  labels:
    app: vault
spec:
  workloadSelector:
    labels:
      app: "vault"
  configPatches:
  - applyTo: HTTP_FILTER
    match:
      context: SIDECAR_INBOUND
      proxy:
        proxyVersion: '1\.15.*'
      listener:
        filterChain:
          filter:
            name: "envoy.filters.network.http_connection_manager"
            subFilter:
              name: "istio.stats"
    patch:
      operation: INSERT_BEFORE
      value:
        name: istio.attributegen
        typed_config:
          "@type": type.googleapis.com/udpa.type.v1.TypedStruct
          type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
          value:
            config:
              configuration:
                "@type": type.googleapis.com/google.protobuf.StringValue
                value: |
                  {
                    "attributes": [
                      {
                        "output_attribute": "istio_operationId",
                        "match": [
                            {
                                "value": "/api/v1/{cusID}/decode",
                                "condition": "request.url_path.matches('/api/v1/[[:alnum:]]*/decode')"
                            },
                            {
                                "value": "/api/v1/{cusID}/encode",
                                "condition": "request.url_path.matches('/api/v1/[[:alnum:]]*/encode')"
                            },
                            {
                                "value": "/api/v1/{cusID}/tokens/{keyName}/import",
                                "condition": "request.url_path.matches('/api/v1/[[:alnum:]]*/tokens/[[:alnum:]]*/import')"
                            },
                            {
                                "value": "/api/v1/{cusID}/tokens/{keyName}/revolve",
                                "condition": "request.url_path.matches('/api/v1/[[:alnum:]]*/tokens/[[:alnum:]]*/revolve')"
                            },
                            {
                                "value": "probes",
                                "condition": "request.url_path == '/ready'"
                            },
                            {
                                "value": "probes",
                                "condition": "request.url_path == '/live'"
                            },
                        ]
                      },
                    ]
                  }
              vm_config:
                runtime: envoy.wasm.runtime.null
                code:
                  local: { inline_string: "envoy.wasm.attributegen" }

如何使用最新版本中 istio 建议的最新

Telemetry
资源来实现同样的效果。

下面的示例是实现相同目标的正确方法吗?这会对性能产生影响吗?

请推荐。

apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
  name: vault-telemetry
spec:
  metrics:
    - overrides:
      - match:
          metric: ALL_METRICS
          mode: SERVER
        tagOverrides:
          method:
            value: request.method
          istio_operationId:
            value: | 
              request.url_path.matches("/api/v1/[[:alnum:]]*/keys/[[:alnum:]]*/import") ? "/api/v1/{cusID}/keys/{keyName}/import" :
              request.url_path.matches("/api/v1/[[:alnum:]]*/keys/[[:alnum:]]*/revolve") ? "/api/v1/{cusID}/keys/{keyName}/revolve" :
              request.url_path.matches("/api/v1/[[:alnum:]]*/encode") ? "/api/v1/{cusID}/encode" :
              request.url_path.matches("/api/v1/[[:alnum:]]*/decode") ? "/api/v1/{cusID}/decode" :
              request.url_path.matches("/ready") ? "probes" :
              request.url_path.matches("/live") ? "probes" :
              "unknown"
      providers:
        - name: prometheus
  selector:
    matchLabels:
      app: vault
kubernetes istio servicemesh custom-tag istio-prometheus
1个回答
0
投票

您正朝着正确的方向前进。建议使用带有标签覆盖的 Telemetry 资源来更改较新版本中的 Istio 指标,而不是 Envoy Filter 方法。

是的,使用您的遥测资源示例来实现相同的功能。它根据 URL 路径与 istio_operationID 标签的标签操作匹配来定义指标覆盖。

由于每个标签覆盖的值表达式都需要针对每个覆盖进行评估,因此与 Envoy Filter 相比,可能会产生一些性能开销。但如果匹配足够多的情况,这通常可以忽略不计。

对于没有 URL 路径匹配的情况,请考虑添加默认值。如果引入新路径,这可以防止出现意外的未知标签。

在大多数现实场景中,您可以使用遥测资源和标签覆盖来灵活调整 Istio 指标,从而提供更高的可维护性,而不会对性能产生重大影响。

请参阅有关 Telemetry 的 Istio 官方文档,了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.