适配器封装了将Mixer与特定外部后端基础设施(如Prometheus)连接所需的逻辑。各个适配器通常需要配置特定的参数才能完成工作。例如,日志记录适配器可能需要日志收集服务器后端的IP地址和端口。
下面的例子配置了一个类型为listchecker的适配器。listchecker适配器使用一个列表来检查输入。如果配置的是白名单模式且输入值存在于列表之中,就会返回成功的结果。配量如下所示:
apiVersion: config.istio.io/v1alpha2 kind: listchecker metadata: name: staticversion namespace: istio-system spec: providerUrl: http://white_list_registry/ blacklist: false
其中,{metadata.name}.{kind}.{metadata.namespace}是处理程序的完全限定名。上面定义的对象的FQDN就是staticversion.listchecker.istio-system,且必须是唯一的。spec中的数据结构则依赖于对应的适配器的要求。
有些适配器实现的功能就不仅仅是把Mixer和后端连接起来。例如prometheus适配器采集指标并以可配置的方式将它们聚合成计数器或分布值,如下所示:
apiVersion: config.istio.io/v1alpha2
kind: prometheus
metadata:
name: handler
namespace: istio-system
spec:
metrics:
- name: request_count
instance_name: requestcount.metric.istio-system
kind: COUNTER
label_names:
- destination_service
- destination_version
- response_code
- name: request_duration
instance_name: requestduration.metric.istio-system
kind: DISTRIBUTION
label_names:
- destination_service
- destination_version
- response_code
buckets:
explicit_buckets:
bounds: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]