Advertisement

Understanding the Istio Mixer: Extensibility and Config

阅读量:

作者:禅与计算机程序设计艺术

1.简介

概述

Istio 是一个现代的服务网(service mesh)框架,在分布式环境下实现了安全防护、流量控制和实时监控功能。基于 Envoy 代理的 Sidecar 模式运行于集群中,并采用 CRD(Kubernetes 的资源定义)进行配置。Istio 提供了丰富的管理工具集合,包括 istioctl 命令行工具、仪表板、控制面板、Galley 组件、Mixer 组件以及 Pilot 组件。其中 mixer 组件是我们今天重点学习的内容。

I am a key player in Istio's architecture. As the primary component responsible for request access control and metrics aggregation, I ensure that operator-defined rules are enforced across service communication. This module abstracts configuration management as a critical infrastructure layer, enabling features such as strategy-based authentication, permission control, capacity management, rate limiting, and extensive data collection capabilities. I support multiple service registration centers for integration, including Kubernetes and Consul. Additionally, I offer various adapter extensions to enhance functionality, such as Prometheus monitoring, Stackdriver analytics, AWS App Mesh integration, TCP/UDP proxying capabilities, and MongoDB connection pools.

近年来Mixer的扩展能力引起了人们的广泛关注。具体原因包括以下几点:

Mixer组件为开发者提供了编写自定义插件的能力,并可通过配置文件或API接口的方式将这些插件加载到运行时环境中。这种高度灵活的设计使得运维团队能够根据实际需求动态调整策略和远程测量数据采集的方法。

  1. Mixer 的架构已经具备了很高的可伸缩性。Mixer 的设计支持并行计算,在较大的规模下运行时能够有效地处理复杂的访问控制和遥测数据收集需求。

  2. Mixer 呈现出极高的透明度与易追踪性。其内部组件间的通信基于 gRPC 协议实施,并由此确保运维团队能够实时掌握系统的运行状态。

本文将深入阐述Mixer的核心功能和模块化设计。通过以下几个方面,读者将掌握Mixer的更多知识:

本文将深入阐述Mixer的核心功能和模块化设计。通过以下几个方面,读者将掌握Mixer的更多知识:

  • mixer组件的核心运作机制
  • mixer平台提供的基础配置参数设置方案
  • mixer内置的标准适配器模块功能概述
  • mixer开发环境中的定制化适配器实现步骤解析
  • mixer系统性能优化的关键指标分析方法
  • 基于mixture平台的实际应用案例及最佳实践指导

最后,本文也会给出相应的反馈意见,欢迎大家提出宝贵建议或意见。

作者简介

陈燕萍女士是一位在阿里巴巴集团担任中间件研发工程师的专业人士。其主要职责在于支持阿里巴巴中间件体系化建设及技术创新。她专注于微服务架构的设计与开发。对开源技术、云原生架构以及Service Mesh技术充满热情。现任职于阿里巴巴集团,曾任职期间先后担任公司中间件研发总监和技术专家一职。致力于将Service Mesh 技术在公司内部推广,并支持超过数百万个容器集群的稳定运行。

2.核心概念

什么是 Mixer?

Mixer 是 Istio 系统中的一个独立模块,在服务网格架构的边缘执行数据转换与增强功能。该模块以过滤器的形式插入到 sidecar proxy(如 Envoy)的请求路径中,并为开发者提供了自定义策略决策和遥测数据收集的功能。它通过在发送到和离开Envoy之前对数据进行处理,并因此被称为边缘处理节点(edge node)。

Mixer 组件包括两部分:

该服务器负责收集各种元数据(metadata)。例如,在 RPC 方法中包含方法名、服务名称以及授权信息等关键参数。该系统依据预先设定的策略制定访问控制决策以及遥测相关的数据记录机制。该系统能够利用任何支持的数据存储架构来存储相关联的数据。这些系统组件可以通过 Kubernetes 或 Consul 等分布式容器管理平台进行集成。

  1. 客户端库 :该客户端库提供了一套无需语言区分的接口,支持多种编程语言访问相应的服务.为了优化网络性能,该技术方案要求所有相关组件部署在同一Pod或虚拟机中,从而能够有效规避网络延迟的影响.此外,该客户端库还允许用户根据需求配置缓存策略以优化查询效率.

为什么需要 Mixer?

Mixer组件的集成显著提升了Istio的功能性和定制化能力。在传统的微服务架构下,每个服务都拥有独立的控制流程和协作机制,并未具备统一的管理平台以协调各组件间的交互。相反,在Service Mesh架构下,所有服务共享一个统一的控制平面层面上实现对流量的有效管控与调度维护。这种设计使得各参与方之间的业务流程处理更加便捷高效。

随着业务规模不断扩大和服务数量急剧上升,在传统架构中由于配置项繁多且维护复杂导致管理难度显著提升。例如运维人员需要通过手动配置完成流量开启等操作工作这对于大型企业而言无疑是一项耗时繁琐的任务相比之下采用Service Mesh架构能够有效缓解这一困境运维只需通过Service Registry快速查询所需服务信息即可无需额外操作从而显著提升了效率然而这也带来了新的挑战如何实现对服务流量的精细管理?单纯依靠Service Mesh难以满足各业务间的复杂访问控制需求必须借助Mixer平台进行动态配置以确保安全性和灵活性得到充分保障

Mixer 基于声明式的策略模型设计,在此框架下运维人员能够方便地配置流量管理策略。当采用该模式时,则不再需要关注底层网络堆栈的具体实现细节;相反地,则只需设定需保护的对象及相应的操作权限即可完成流量控制设置。此外,Mixer 还提供了多样化的访问控制功能,其中包括基于属性的访问控制,RBAC 权限方案以及 ABAC 权限方案等技术选择。进一步而言,Mixer 还集成了丰富的性能监控数据采集机制,能够帮助获取诸如日志信息,实时监控指标数据,以及 SLA 服务保障等相关数据信息。最后,Mixer 可被视为基础设施层的关键逻辑架构,从而为应用系统和平台提供的可观察性,弹性和安全防护体系奠定了重要基础

3.核心算法原理及操作步骤

Mixer 的工作原理

Mixer组件的功能流程相对直接易懂。该组件接收gRPC服务接口作为入口(位于数据平面的API),通过解析各种元数据和遥测数据信息(metadata和telemetry data)来计算出相应的访问控制策略以及遥测数据结果。随后,Mixer将这些策略及数据结果传递至远程Mixer服务器,该服务器会利用外部数据源进行配置验证与性能评估,并将评估结果反馈给Envoy sidecar proxy组件,从而完成对请求路径的路由决策。Mixer中的过滤器会按照预先设定好的执行顺序依次处理各项逻辑,最终构建起完整的访问控制逻辑链路

Mixer 配置文件的组成

该配置包含三个特定的文件,具体来说包括mixer.yaml, adapter.yaml以及template.yaml这三个文件

mixer.yaml 文件详细说明了 mixer 的全局配置设置。主要包含 mixer 服务地址、日志级别、最大批处理大小以及轮询间隔等相关参数设定。

adapter.yaml 文件中定义了 mixer 使用的适配器。
每一个适配器都包含一个配置块, 其中包括 mixer 服务器地址, 类型以及相关的参数。
不适配器配置是 mixer 实现遥测数据获取与策略决策执行的关键条件

在 template.yaml 文件中,策略模板被定义为包含每个配置项的名称、参数以及相应的约束条件,并与特定适配器建立关联。通过使用不同的策略模板,相同的资源或操作能够实现更为精细的策略管理。

Mixer 内置的适配器

Istio 提供了丰富的适配器,如下所示:

适配器 描述
Denier 对不合格的请求做出拒绝决定
Fluentd 从日志中收集遥测数据
Graphite 将遥测数据写入 Graphite 后端
Memquota 限制内存消耗
Mixerclient 将遥测数据聚合并发送到 Mixer 服务器
Oauth 身份验证和授权
Prometheous 从 Prometheus 采样器收集遥测数据
Redisquota 限制 Redis 内存消耗
Stackdriver 将遥测数据写入 Stackdriver 后端
Statsd 从 statsd 采样器收集遥测数据

这些主要功能已实现,并且支持根据实际需求进行扩展的适配器可以直接使用。需要注意的是,在开发自定义适配器时,请确保遵循相关技术规范和设计原则。

  1. 适配器的类型应与相应的策略模板对应。
  2. 每个适配器都应负责管理某种类型的元数据和遥测数据。
  3. 在初始化函数中添加相关参数,并在构造阶段注入到适配器对象中。
  4. 自定义适配器必须严格遵循Istio编码规范。

Mixer 自定义适配器的开发过程

自定义适配器的开发过程分为以下几个步骤:

请建立一个新的存储容器,用于整合适配器的代码文件和测试数据。该容器通常遵循以下结构:其子目录将按照功能模块分类,并列出具体的子目录结构。

复制代码
    $ tree mixer_adapter

    ├── cmd             # 适配器的启动入口
    │   └── server     # Go 语言代码
    ├── config          # yaml 配置文件
    │   ├── config.pb.go    # protobuf 文件
    │   ├── config.proto    # protobuffer 文件定义
    │   ├── handler.go      # 适配器的实现
    │   ├── instance        # 策略模板
    │   │   ├── handler.go
    │   │   ├── template.yaml
    │   │   └── params.go
    │   ├── rule           # 策略实例
    │   │   ├── README.md
    │   │   └── sample.yaml
    ├── deployment      # kubernetes 渲染模板
    ├── go.mod         # 模块依赖文件
    ├── go.sum         # 模块 checksum 文件
    ├── Makefile       # makefile 脚本
    ├── main.go        # 适配器的主程序入口
    └── testdata       # 测试数据
    ├──...
    └── instance_handler_test.go
    
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
    代码解读

于配置目录内生成config.proto文件并完成相应的字段设定;与此同时,在handler.go程序模块中开发Handle*Kind()功能模块。举例如下:

复制代码
    syntax = "proto3";

    
    package adapter.sample;
    
      message Params {
      string bla = 1; // example field
      }
    
      message InstanceParam {
      option (istio.mixer.v1.config.common_pb.subject_to_oneof) = true;
    
      oneof adapter_specific_params {
          Params params = 1 [(istio.mixer.v1.template.default_instance_param)="{\n\"bla\": \"example\"\n}"]; // policy parameters for this instance
      }
      }
    
    service Handler {
    rpc HandleMetric(istio.policy.v1beta1.MetricInstance) returns (istio.policy.v1beta1.CheckResult);
    rpc HandleLog(istio.policy.v1beta1.LogEntry) returns (istio.policy.v1beta1.CheckResult);
    rpc HandleTraceSpan(istio.policy.v1beta1.TraceSpan) returns (istio.policy.v1beta1.CheckResult);
    rpc Close() returns (google.protobuf.Empty);
    }
    
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
    代码解读
复制代码
    func HandleMetric(ctx context.Context, inst *pb.InstanceParam, attrs attribute.Bag) (*check.Result, error) {

    cfg := inst.Params
    fmt.Println("received metric:", cfg.Bla)
    return check.OK, nil
    }
    
         
         
         
         
    代码解读

创建 Protobuf 档案及客户端。通过命令行工具按照以下指令进行操作以生产 protobuf 数据结构:

复制代码
    $ mkdir -p gen && protoc -I=$GOPATH/src:. --go_out=plugins=grpc:$GOPATH/src/mixer_adapter/gen config/config.proto

    
    代码解读

生成的客户端包放置于gen文件夹内,并包含有所有由protos文件定义的类型和消息

  1. 添加适配器注册。在 main.go 中添加一个 init() 函数,注册适配器类型:
复制代码
    import _ "istio.io/istio/mixer/adapter/myawesomeadapter" // register my awesome adapter

    
    func init() {
    registry.DefaultRegistry = append(registry.DefaultRegistry, myawesome.NewAwesomeAdapter())
    }
    
         
         
         
         
    代码解读
  1. 创建 docker image。构建 Dockerfile 并打包镜像。

请按照以下步骤进行操作:首先,在 /charts/mixer/templates/adapters 目录下进行Helm Chart的部署;其次,在此目录下执行创建或更新操作。

制定操作流程的具体细节,在配置文件定位至 config/rule 目录后生成一个YAML格式的操作手册文档,并详细说明该适配器的工作流程。参考以下示例以明确具体实现细节:

复制代码
    ---

    apiVersion: "config.istio.io/v1alpha2"
    kind: attributemanifest
    metadata:
      name: istio-proxy
    spec:
      attributes:
    # Fill in the list of attributes here
    attribute_name:
      value_type: STRING
      description: Describes an attribute produced by the mesh owner or operator.
    
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: template
    metadata:
      name: myawesometemplate
    spec:
      workloadSelector:
    labels:
      app: myawesomeapp
      monitored_resources:
      - type: myawesomemetric
      param_sinks:
      - template_variety: TEMPLATE_VARIETY_ATTRIBUTE_GENERATOR
      params:
      - name: foobar
    required: false
    attribute_expression: request.headers["x-foobar"] | ""
    
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: handler
    metadata:
      name: myawesomehandler
    spec:
      compiled_adapter: myawesome-handler
      severity_levels:
    myawesomeseveritylevel: INFO
    default: INFO
      params:
      - name: foobar
    value: "defaultvalue"
      connection:
    address: 127.0.0.1:1234
    
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
    代码解读

配置策略实例。在config/rule目录中新建一个YAML文件,并导入之前所生成的策略模板文件作为基础依据,在其中设定具体的策略应用场景。

复制代码
    ---

    apiVersion: "config.istio.io/v1alpha2"
    kind: instance
    metadata:
      name: myawesomenamespace-myawesomeapp-myawesometemplate
    spec:
      compiledTemplate: myawesometemplate
      params:
    # Override any template parameters here. Note that it is not recommended to do so without strong reason as this could lead to inconsistent enforcement behavior across instances. In this case, we're only overriding the default value for `foobar` parameter from `"defaultvalue"` to `"newvalue"`.
    foobar: newvalue
    # If no override is needed, simply omit `params` section.
    
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: rule
    metadata:
      name: myawesomenamespace-myawesomeapp-myawesomerules
    spec:
      match: source.labels["app"] == "myawesomeapp" && destination.namespace!= "kube-system"
      actions:
      - handler: myawesomehandler
    instances: [myawesomenamespace-myawesomeapp-myawesometemplate]
    
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
    代码解读

Mixer 性能优化方法

Mixer组件的性能受多种因素制约,具体包括系统配置、资源占用和网络带宽等.将介绍几种优化策略.

降低 MixerServer的并发连接数量。通常情况下,默认设置下会为每个 pod 保留两个用于连接到 mixer server的通道以确保高可用性。在大规模集群中,可以通过调整这个值来降低其规模以适应不同的负载需求

  1. 降低 mixer 客户端的连接数量。 mixer 客户端通过持续保持与 mixer server 的长时间网络连接来减少了每次建立或断开连接所需的等待时间。 通过优化批次处理的数量以及将大任务分解为多个小任务分别处理的方式,可以进一步提升整体性能。

  2. 提升连接池性能。对于规模较大的集群环境而言,在保证稳定性的同时提升连接池的性能具有重要意义。推荐使用HikariCP等知名连接池库以达到最佳效果。

  3. 部署缓存机制。该客户端能够执行缓存策略结果的获取与应用。

建议采用该技术而非基于DNS的服务记录(DNS SRV)。通过这种选择方式,在减少客户端对服务列表的频繁请求的同时,能够有效减少网络延迟,并提升整体系统响应速度和稳定性。

4.具体代码实例及解释说明

Mixer 内置适配器的使用场景

本节介绍 Mixer 内置适配器的一些典型场景。

禁止访问的适配器(Denyer Adapter)

Deneyer适配器的功能是在Mixer拒绝接收不合格请求之前执行一项预防性操作。如果某个服务出现故障或表现出异常行为,则避免向其发送流量。从而阻止该服务发送流量。为了防止这种情况发生,在不直接向其发送流量的情况下进行处理较为稳妥:将目标服务纳入Deneyer whitelist设置并设定相应的超时阈值:该适配器会评估所有ingress和egress流量:下面是一个Deneyer配置示例:

复制代码
    apiVersion: "config.istio.io/v1alpha2"
    kind: handler
    metadata:
      name: denyall
    spec:
      # Required: implementation must be "denyall".
      name: denyall
      compiled_adapter: denyall
      severity_levels:
    none: NONE
    default: DEFAULT
      templates:
      - empty:
      status:
        code: 7
        message: Access denied. You don't have permission to access this resource.
        details:
          authorize_url: http://example.com/authorize?svc=$(destination.service.host)
          allowed_domains: ["allowed.domain.net", "*.another.domain.org"]
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: instance
    metadata:
      name: mydenier
      namespace: default
    spec:
      compiledTemplate: empty
      params: {}
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: rule
    metadata:
      name: default-deny
      namespace: default
    spec:
      actions:
      - handler: denyall
    instances: [mydenier]
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    代码解读

當請求的目标地(destination.service.host)不符合允許域名(allowed.domain.net)或其子域名为*.another.domain.org的情況時, server將會返回 HTTP 碼率碼為7並伴有授權連接址

Prometheus 适配器(Prometheus Adapter)

该适配器通过从另一台服务器接收遥测数据,并将其传输至集中管理平台。该适配器可通过设置采集哪些指标以及如何进行指标聚合等参数来实现对遥测数据进行精细级别的收集管理。下面是一个 Prometheus 配置示例:

复制代码
    apiVersion: "config.istio.io/v1alpha2"
    kind: prometheus
    metadata:
      name: handler
      namespace: istio-system
    spec:
      # The name of the Prometheus handler.
      # This should correspond to a unique name given to each handler within a config, however this is not enforced at present.
      handler: handler
    
      # Optional: number of worker threads processing metrics. Default is 1.
      threadPoolSize: 1
    
      # Optional: Interval between calls to metrics collection endpoint. Supports duration format strings. Default is 60 seconds.
      queryInterval: 60s
    
      # Optional: Specify label names and values for grouping collected metrics together.
      # Default is to use all dimensions specified in queries and ignore other dimensions.
      relabelings: []
    
      # Metrics specifies the list of individual metrics to fetch from the associated Prometheus endpoints.
      metrics:
      - name: request_count
    instance_name:'request_count'
    
    # Optional: Metric expiration time window. After this period, the cached result will become invalid and gets refreshed on next scrape. By default, this is disabled (-1).
    expire_after: 1h
    
    # Optional: How to aggregate multiple overloaded samples into one. Can be one of [UNSPECIFIED, AVERAGE, MAX, MIN, SUM]. Unspecified means inherit from original metrics settings. Default is unspecified.
    # aggregation_method: unspecified
    
      - name: request_duration
    instance_name:'request_duration'
    label_names:
      # Label names are defined as part of an output expression using Prometheus querying language.
      # They need to be quoted with backticks when used elsewhere in expressions, such as `metric_labels`.
      # We define these statically to avoid hardcoding them in code.
      verb: '"'"${verb}'"'
      path: '"'"${path}'"'
    
    # Expire after defaults to 1 hour if left unset.
    # aggregation_method inherits from parent metric setting unless explicitly set here.
    
      # Optional: Absolute path to export metrics. Only metrics mentioned in `metrics` configuration block can be exported.
      # Set this to enable scraping support for this handler.
      custom_metrics:
    # Custom metrics are fetched from Prometheus directly via a dedicated endpoint (`prometheus`) which serves the `/api/v1/series` endpoint for direct querying of series data.
    url: http://localhost:9090
    # Comma separated list of supported metric types. Supported values include `counter`, `gauge`, `histogram` and `summary`.
    # All non-matching types will be rejected during validation. If left blank or omitted, all types will be accepted.
    supported_types: counter, gauge, histogram, summary
    # Provide an optional authorization header that the adapter should use while making requests to the Prometheus API.
    authorization: Bearer <your token>
    
      # Optional: RetryPolicy defines retry policy for failed scrapes. Retries occur whenever there's a failure fetching metrics due to network errors or missing metrics etc., up to the maximum retries limit defined below.
      # Defaults to no retries if left unset.
      retry_policy:
    attempts: 1               # Number of times to attempt scraping before giving up. Must be greater than zero.
    initial_interval: 1s      # Initial interval between retries. Supports duration formats like "1m", "10s" etc.
    max_elapsed_time: 1m      # Maximum amount of time spent attempting retries. Once elapsed, the last error encountered will be returned.
    backoff_factor: 2         # Factor multiplied by previous delay duration to obtain the next delay duration. Values <= 1 indicate no backoff.
    
    # Retries are done based on per-metric basis. These configurations apply to all failing metrics together, irrespective of their configured name or group name.
    # To customize retry policies per-metric, you can provide a separate configuration block for each named or grouped metric. Here's an example:
    # 
    # # Configure different retry policies for two particular groups of metrics separately
    # retry_configs:
    # - name: "foo.*"                     # Apply retry configs to metrics matching this regex pattern
    #   attempts: 2
    #   initial_interval: 5s            # Overrides global initial_interval
    #   max_elapsed_time: 2m            # Overrides global max_elapsed_time
    #   
    # - name: "^http_.*$"                 # Another group of metrics to apply specific overrides to
    #   attempts: 1                      # Overrides inherited value of 1
    #   backoff_factor: 1                # Applies exponential backoff instead of linear backoff
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: rule
    metadata:
      name: prom-rule
      namespace: istio-system
    spec:
      match: context.protocol == "http" || context.protocol == "grpc"
      actions:
      - handler: handler
    instances: [promtcp, promhttp]
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: rule
    metadata:
      name: grpc-requests
      namespace: istio-system
    spec:
      match: context.protocol == "grpc" && api.operation == "grpc.health.v1.Health.Check"
      actions:
      - handler: handler
    instances: [promgrpc]
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: rule
    metadata:
      name: tcp-connections
      namespace: istio-system
    spec:
      match: context.protocol == "tcp"
      actions:
      - handler: handler
    instances: [promtcp]
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    代码解读

本节详细描述了系统内四个关键配置项。其中第一条配置项主要处理HTTP/GRPC类型下的遥测数据汇总逻辑;第二条配置项则专注于Grpc Health Check相关的远程监控数据整合机制;第三条配置项实现了对标准TCP协议下的实时监控数据进行高效汇总的能力;最后一条配置项明确了Prometheus适配器对应的输出表达式设定方式。

Prometheus 适配模块能够将集成后的监控数据传输至 Mixer 并应用于对应的策略设置。
该 Prometheus 适配程序可将集成后的监控数据发送至 Mixer 并配置相关策略。
该 Prometheus 适配模块可整合后端监控数据并将其传输至 mixer 系统中以支持策略配置。

Statsd 适配器(Statsd Adapter)

Statsd 组件用于从 Statsd 收集远程监控数据,并将其传递给 mixer 系统。例如以下是一个 Statsd 配置示例:

复制代码
    apiVersion: "config.istio.io/v1alpha2"
    kind: stdio
    metadata:
      name: handler
      namespace: istio-system
    spec:
      # The name of the logger factory to use. If empty, "project" is assumed, where project is the same as the control plane namespace.
      # Use "root" to configure a root logger.
      log_name: statshandler
    
      # Severity levels in order of increasing verbosity. Should be one of "debug", "info", "warn", "error", "critical".
      severity_levels:
    info: INFO
    warning: WARNING
    error: ERROR
    critical: CRITICAL
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: rule
    metadata:
      name: stdio-rule
      namespace: istio-system
    spec:
      match: context.protocol == "tcp"
      actions:
      - handler: handler
    instances: [statssocket]
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: instance
    metadata:
      name: statssocket
      namespace: istio-system
    spec:
      template: metric
      params:
    value: "1"
    dimensions:
      requestsize: "responseSize"
      responsesize: "bytesSent"
      destination: "tcp://{{.Value}}"
      reporter: "{{.Reporter}}"
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: metric
    metadata:
      name: requestsize
      namespace: istio-system
    spec:
      value: request.size | 0
      factor: 1
      dimension_labels:
    requestsize: responseSize
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: metric
    metadata:
      name: responsesize
      namespace: istio-system
    spec:
      value: response.size | 0
      factor: 1
      dimension_labels:
    responsesize: bytesSent
    ---
    apiVersion: "config.istio.io/v1alpha2"
    kind: reportertype
    metadata:
      name: istio-proxy
      namespace: istio-system
    spec:
      builtIn: envoy
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    代码解读

上述配置基于 stdio 适配器并包含两个统计指标。其中第一个统计指标名为 requestsize ,其取自 TCP 请求报文头中的 Content-Length 字段。第二个统计指标名为 responsesize ,其取自 TCP 请求响应包的大小信息。

Statsd适配器通过处理TCP请求中的报文头信息,在其内容长度字段中提取客户端发送的数据长度信息,并将其与服务器响应包的大小数据对应到Mixer平台上传输。

全部评论 (0)

还没有任何评论哟~