遥测

遥测定义了如何在网格内为工作负载生成遥测。

对于网格级配置,请将资源放在 Istio 安装的根配置命名空间中,*无需* 工作负载选择器。

对于任何命名空间,包括根配置命名空间,只能有一个没有工作负载选择器的 Telemetry 资源。

对于具有工作负载选择器的资源,只能有一个资源选择任何给定的工作负载。

Telemetry 配置的层次结构如下

  1. 特定于工作负载的配置
  2. 特定于命名空间的配置
  3. 根命名空间配置

示例

启用 10% 流量的随机采样的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: mesh-default
  namespace: istio-system
spec:
  # no selector specified, applies to all workloads
  tracing:
  - randomSamplingPercentage: 10.00

foo 工作负载禁用跟踪报告的策略(注意:跟踪上下文仍将传播)

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: foo-tracing
  namespace: bar
spec:
  selector:
    matchLabels:
      service.istio.io/canonical-name: foo
  tracing:
  - disableSpanReporting: true

选择备用 Zipkin 提供程序用于跟踪报告的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: foo-tracing-alternate
  namespace: baz
spec:
  selector:
    matchLabels:
      service.istio.io/canonical-name: foo
  tracing:
  - providers:
    - name: "zipkin-alternate"
    randomSamplingPercentage: 10.00

仅从客户端工作负载采样跟踪的 Zipkin 提供程序定制策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: mesh-default
  namespace: istio-system
spec:
  # no selector specified, applies to all workloads
  tracing:
  - match: CLIENT
  - providers:
    - name: "zipkin"

从字面值添加自定义标签的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: mesh-default
  namespace: istio-system
spec:
  # no selector specified, applies to all workloads
  tracing:
  - randomSamplingPercentage: 10.00
    customTags:
      my_new_foo_tag:
        literal:
          value: "foo"

禁用整个网格的 Prometheus 服务器端指标的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: mesh-default
  namespace: istio-system
spec:
  # no selector specified, applies to all workloads
  metrics:
  - providers:
    - name: prometheus
    overrides:
    - match:
        metric: ALL_METRICS
        mode: SERVER
      disabled: true

foo命名空间的所有 Prometheus 指标添加维度的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: namespace-metrics
  namespace: foo
spec:
  # no selector specified, applies to all workloads in the namespace
  metrics:
  - providers:
    - name: prometheus
    overrides:
    # match clause left off matches all istio metrics, client and server
    - tagOverrides:
        request_method:
          value: "request.method"
        request_host:
          value: "request.host"

bar.foo工作负载的一些 Prometheus 指标中删除response_code维度的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: remove-response-code
  namespace: foo
spec:
  selector:
    matchLabels:
      service.istio.io/canonical-name: bar
  metrics:
  - providers:
    - name: prometheus
    overrides:
    - match:
        metric: REQUEST_COUNT
      tagOverrides:
        response_code:
          operation: REMOVE
    - match:
        metric: REQUEST_DURATION
      tagOverrides:
        response_code:
          operation: REMOVE
    - match:
        metric: REQUEST_SIZE
      tagOverrides:
        response_code:
          operation: REMOVE
    - match:
        metric: RESPONSE_SIZE
      tagOverrides:
        response_code:
          operation: REMOVE

为整个网格启用访问日志记录的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: mesh-default
  namespace: istio-system
spec:
  # no selector specified, applies to all workloads
  accessLogging:
  - providers:
    - name: envoy
    # By default, this turns on access logging (no need to set `disabled: false`).
    # Unspecified `disabled` will be treated as `disabled: false`, except in
    # cases where a parent configuration has marked as `disabled: true`. In
    # those cases, `disabled: false` must be set explicitly to override.

禁用foo命名空间的访问日志记录的策略

apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: namespace-no-log
  namespace: foo
spec:
  # no selector specified, applies to all workloads in the namespace
  accessLogging:
  - disabled: true

遥测

字段类型描述必需
selectorWorkloadSelector

可选。选择器决定将策略应用于何处。如果未设置,则策略将应用于与策略位于同一命名空间中的所有工作负载。

对于给定的策略,最多只能设置selectortargetRefs中的一个。

targetRefsPolicyTargetReference[]

可选。targetRefs 指定应将策略应用于的一系列资源。指定的目标资源将确定策略应用于哪些工作负载。

目前,支持以下资源附加类型

  • kind: Gateway 以及同一命名空间中的group: gateway.networking.k8s.io
  • kind: Service 以及同一命名空间中的group: ""group: "core"。此类型仅支持用于路标。

如果未设置,则策略将根据选择器定义进行应用。最多只能设置选择器和 targetRefs 中的一个。

注意:如果您在 Istio 版本低于 1.22 的多版本环境中使用targetRefs字段,则强烈建议您通过istio.io/rev标签将策略固定到运行 1.22+ 的版本。这是为了防止连接到旧控制平面(不知道targetRefs字段)的代理在升级过程中将策略误解为命名空间范围。

注意:路标代理需要使用此字段才能应用策略;将忽略selector策略。

tracingTracing[]

可选。Tracing 配置所有选定工作负载的跟踪行为。

metricsMetrics[]

可选。Metrics 配置所有选定工作负载的指标行为。

accessLoggingAccessLogging[]

可选。Access logging 配置所有选定工作负载的访问日志记录行为。

跟踪

Tracing 配置网格内工作负载的跟踪行为。它可用于启用/禁用跟踪,以及设置采样率和自定义标签提取。

Tracing 配置支持在配置层次结构中的每个级别覆盖providersrandom_sampling_percentagedisable_span_reportingcustom_tags字段,并从父资源中填充缺失的值。但是,如果指定了custom_tags,它将完全替换父配置提供的任何值。

字段类型描述必需
matchTracingSelector

允许将行为定制到特定条件。

providersProviderRef[]

可选。要用于跨度报告的提供程序的名称。如果未指定提供程序,则将使用默认跟踪提供程序。注意:目前,在给定的 Tracing 规则中只能指定一个提供程序。

randomSamplingPercentageDoubleValue

控制如果尚未做出先前的采样决策,则选择用于跟踪的流量的速率。如果已做出先前的采样决策,则将尊重该决策。但是,如果尚未做出任何采样决策(例如:请求中不存在x-b3-sampled跟踪标头),则将根据指定的百分比选择流量以进行遥测生成。

默认为 0%。有效值 [0.00-100.00]。可以以 0.01% 的增量指定。

disableSpanReportingBoolValue

控制跨度报告。如果设置为 true,则不会为受影响的工作负载报告任何跨度。这不会影响上下文传播或跟踪采样行为。

customTagsmap<string, CustomTag>

可选。为生成的跟踪跨度配置其他自定义标签。

ProviderRef

用于将遥测配置绑定到特定提供程序以进行目标定制。

字段类型描述必需
namestring

必需。MeshConfig中遥测提供程序的名称。

指标

Metrics 定义网格内指标生成行为的工作负载级覆盖。它可用于启用/禁用指标生成,以及自定义生成的指标的维度。

字段类型描述必需
providersProviderRef[]

可选。应将此配置应用于的提供程序的名称。如果未指定提供程序,则将使用默认指标提供程序

overridesMetricsOverrides[]

可选。指标生成行为的覆盖列表(按顺序排列)。

指定的覆盖将按顺序应用。它们将应用于从层次结构中其他资源继承的覆盖之上,顺序如下

  1. 网格范围覆盖
  2. 命名空间范围覆盖
  3. 工作负载范围覆盖

由于覆盖按顺序应用,因此建议用户将其覆盖从最不具体的匹配项排序到最具体的匹配项。也就是说,最佳实践是首先列出任何通用覆盖,然后列出定制覆盖。

reportingIntervalDuration

可选。Reporting interval 允许配置对指标报告进行调用的时间间隔。目前,这仅支持 TCP 指标,但我们将来可能会将其用于长时间运行的 HTTP 流。默认持续时间为5s

MetricSelector

提供了一种机制来匹配指标以应用覆盖行为。

字段类型描述必需
metricIstioMetric (oneof)

众所周知的Istio 标准指标之一。

customMetricstring (oneof)

允许自由格式指定指标。不提供自定义指标的验证。

modeWorkloadMode

控制选择哪种指标生成模式:CLIENTSERVERCLIENT_AND_SERVER

MetricsOverrides

MetricsOverrides 定义单个指标或所有标准指标集的自定义指标生成行为。

字段类型描述必需
matchMetricSelector

Match 允许提供覆盖范围。它可用于选择单个指标,以及生成指标的工作负载模式(服务器、客户端或两者)。

如果未指定 match,则覆盖将应用于所有指标的两种操作模式(客户端和服务器)。

disabledBoolValue

可选。必须将其显式设置为true才能关闭列出指标的指标报告。如果在父配置中已将 disabled 设置为true,则必须将其显式设置为false才能在遥测资源选择的工作负载中打开指标报告。

tagOverridesmap<string, TagOverride>

可选。要覆盖选定指标中的标签名称和标签表达式的集合。映射中的键是标签的名称。映射中的值是对标签执行的操作。警告:某些提供程序可能不支持添加/删除标签。另请参阅:https://istio.ac.cn/latest/docs/reference/config/metrics/#labels

访问日志记录

访问日志记录定义访问日志生成的作业负载级覆盖。它可用于选择提供程序或启用/禁用工作负载的访问日志生成。

字段类型描述必需
matchLogSelector

允许将日志记录行为定制到特定条件。

providersProviderRef[]

可选。应将此配置应用于的提供程序的名称。如果未指定提供程序,则将使用默认日志记录提供程序

disabledBoolValue

控制日志记录。如果设置为 true,则不会为受影响的工作负载(对于指定的提供程序)生成任何访问日志。注意:目前,默认行为将由上面选择的服务提供商控制。自定义控件将在将来的版本中添加到此 API。

filterFilter

可选。如果指定,则此过滤器将用于选择要记录的特定请求/连接。

Tracing.TracingSelector

TracingSelector 提供了一种粗粒度的方式,可以根据某些流量元数据(例如流量方向)配置跟踪行为。

字段类型描述必需
modeWorkloadMode

这决定了是否根据相对于代理工作负载的流量方向应用跟踪配置。

Tracing.CustomTag

CustomTag 定义一个要添加到跟踪跨度的标签,该标签基于操作员提供的值。此值可以是硬编码值、从侧车代理已知的环境变量中获取的值或来自请求标头的值。

注意:如果指定了custom_tags,它将完全替换父配置提供的任何值。

字段类型描述必需
literalLiteral (oneof)

Literal 为每个跨度添加相同硬编码的值。

environmentEnvironment (oneof)

Environment 为每个跨度添加环境变量的值。

headerRequestHeader (oneof)

RequestHeader 为每个跨度添加请求中标头的值。

Tracing.Literal

字段类型描述必需
valuestring

要使用的标签值。

Tracing.Environment

字段类型描述必需
namestring

从中提取标签值的环境变量的名称。

defaultValuestring

可选。如果找不到环境变量,则将使用此值。

Tracing.RequestHeader

字段类型描述必需
namestring

从中提取标签值的头部的名称。

defaultValuestring

可选。如果找不到标头,则将使用此值。

MetricsOverrides.TagOverride

TagOverride 指定对指标维度(也称为label)执行的操作。可以添加、删除标签或覆盖其默认值。

字段类型描述必需
operationOperation

Operation 控制是否更新/添加标签或删除标签。

valuestring

仅当操作为UPSERT时才考虑 Value。值是在属性上运行的CEL 表达式。例如:string(destination.port)request.host。Istio 公开了所有标准的Envoy 属性。此外,Istio 将节点元数据作为属性公开。在自定义文档中提供了更多信息。

AccessLogging.LogSelector

LogSelector 提供了一种粗粒度的方式,可以根据某些流量元数据(例如流量方向)配置日志记录行为。LogSelector 应用于当前不受过滤器支持的属性集表示的流量元数据。它允许控制平面限制发送到各个工作负载的配置。可以通过filter进一步配置更细粒度的日志记录行为。

字段类型描述必需
modeWorkloadMode

这决定了是否根据相对于代理工作负载的流量方向应用访问日志记录配置。

AccessLogging.Filter

允许指定访问日志过滤器。

字段类型描述必需
expressionstring

用于选择何时应记录请求/连接的 CEL 表达式。

示例

  • response.code >= 400
  • connection.mtls && request.url_path.contains('v1beta3')
  • !has(request.useragent) || !(request.useragent.startsWith("Amazon-Route53-Health-Check-Service"))

MetricSelector.IstioMetric

Istio 指标提供程序支持的已知指标类型的精选列表。另请参阅:https://istio.ac.cn/latest/docs/reference/config/metrics/#metrics

名称描述
ALL_METRICS

使用此枚举表示覆盖应该应用于所有 Istio 默认指标。

REQUEST_COUNT

对应用请求/响应的计数器,针对 HTTP、HTTP/2 和 GRPC 流量生成。

Prometheus 提供程序将此指标导出为:istio_requests_total

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/request_count(服务器模式)
  • istio.io/service/client/request_count(客户端模式)
REQUEST_DURATION

请求持续时间的直方图,针对 HTTP、HTTP/2 和 GRPC 流量生成。

Prometheus 提供程序将此指标导出为:istio_request_duration_milliseconds

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/response_latencies(服务器模式)
  • istio.io/service/client/roundtrip_latencies(客户端模式)
REQUEST_SIZE

请求正文大小的直方图,针对 HTTP、HTTP/2 和 GRPC 流量生成。

Prometheus 提供程序将此指标导出为:istio_request_bytes

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/request_bytes(服务器模式)
  • istio.io/service/client/request_bytes(客户端模式)
RESPONSE_SIZE

响应正文大小的直方图,针对 HTTP、HTTP/2 和 GRPC 流量生成。

Prometheus 提供程序将此指标导出为:istio_response_bytes

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/response_bytes(服务器模式)
  • istio.io/service/client/response_bytes(客户端模式)
TCP_OPENED_CONNECTIONS

工作负载生命周期内打开的 TCP 连接计数器。

Prometheus 提供程序将此指标导出为:istio_tcp_connections_opened_total

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/connection_open_count(服务器模式)
  • istio.io/service/client/connection_open_count(客户端模式)
TCP_CLOSED_CONNECTIONS

工作负载生命周期内关闭的 TCP 连接计数器。

Prometheus 提供程序将此指标导出为:istio_tcp_connections_closed_total

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/connection_close_count(服务器模式)
  • istio.io/service/client/connection_close_count(客户端模式)
TCP_SENT_BYTES

通过 TCP 连接在响应期间发送的字节计数器。

Prometheus 提供程序将此指标导出为:istio_tcp_sent_bytes_total

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/sent_bytes_count(服务器模式)
  • istio.io/service/client/sent_bytes_count(客户端模式)
TCP_RECEIVED_BYTES

通过 TCP 连接在请求期间接收的字节计数器。

Prometheus 提供程序将此指标导出为:istio_tcp_received_bytes_total

Stackdriver 提供程序将此指标导出为

  • istio.io/service/server/received_bytes_count(服务器模式)
  • istio.io/service/client/received_bytes_count(客户端模式)
GRPC_REQUEST_MESSAGES

客户端发送的每个 gRPC 消息都会递增此计数器。

Prometheus 提供程序将此指标导出为:istio_request_messages_total

GRPC_RESPONSE_MESSAGES

服务器发送的每个 gRPC 消息都会递增此计数器。

Prometheus 提供程序将此指标导出为:istio_response_messages_total

MetricsOverrides.TagOverride.Operation

名称描述
UPSERT

插入或更新带有提供的表达式值的标签。如果使用 UPSERT 作为操作,则 必须 指定 value 字段。

REMOVE

指定在生成指标时不应包含该标签。

WorkloadMode

WorkloadMode 允许选择网络流量中底层工作负载的角色。如果工作负载是流量的目标(即,从工作负载的角度来看,流量方向是入站),则认为该工作负载充当SERVER。如果工作负载是网络流量的源,则认为它处于CLIENT 模式(流量从工作负载出站)。

名称描述
CLIENT_AND_SERVER

选择工作负载是网络流量的源或目标的情况。

CLIENT

选择工作负载是网络流量的源的情况。

SERVER

选择工作负载是网络流量的目标的情况。

这些信息是否有用?
您有什么改进建议?

感谢您的反馈!