istio.io/archive/v1.1/zh/blog/2017/adapter-model/index.html

22 lines
30 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html><html lang=zh itemscope itemtype=https://schema.org/WebPage><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=theme-color content=#466BB0><meta name=title content="Mixer 适配器模型"><meta name=description content="概要说明 Mixer 的插件架构。"><meta name=author content="Martin Taillefer"><meta name=keywords content=microservices,services,mesh,adapters,mixer,policies,telemetry><meta property=og:title content="Mixer 适配器模型"><meta property=og:type content=website><meta property=og:description content="概要说明 Mixer 的插件架构。"><meta property=og:url content=/v1.1/zh/blog/2017/adapter-model/><meta property=og:image content=/v1.1/img/istio-whitelogo-bluebackground-framed.svg><meta property=og:image:alt content="Istio Logo"><meta property=og:image:width content=112><meta property=og:image:height content=150><meta property=og:site_name content=Istio><meta name=twitter:card content=summary><meta name=twitter:site content=@IstioMesh><title>Istioldie 1.1 / Mixer 适配器模型</title><script async src="https://www.googletagmanager.com/gtag/js?id=UA-98480406-2"></script><script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}
gtag('js',new Date());gtag('config','UA-98480406-2');</script><link rel=alternate type=application/rss+xml title="Istio Blog" href=/v1.1/feed.xml><link rel="shortcut icon" href=/v1.1/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.1/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.1/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.1/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.1/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.1/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.1/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.1/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.1/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.1/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.1/manifest.json><meta name=apple-mobile-web-app-title content=Istio><meta name=application-name content=Istio><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Work+Sans:400|Chivo:400|Work+Sans:500,300,600,300italic,400italic,500italic,600italic|Chivo:500,300,600,300italic,400italic,500italic,600italic"><link rel=stylesheet href=/v1.1/css/all.css></head><body class="language-unknown archive-site"><script src=/v1.1/js/themes_init.min.js></script><script>const branchName="release-1.1";const docTitle="Mixer 适配器模型";const iconFile="\/v1.1/img/icons.svg";const buttonCopy='复制到剪切板';const buttonPrint='打印';const buttonDownload='下载';</script><script src="https://www.google.com/cse/brand?form=search-form" defer></script><script src=/v1.1/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.1/zh/><span class=logo><svg viewBox="0 0 300 300"><circle cx="150" cy="150" r="146" stroke-width="2" /><path d="M65 240H225L125 270z"/><path d="M65 230l60-10V110z"/><path d="M135 220l90 10L135 30z"/></svg></span><span class=name>Istioldie 1.1</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#hamburger"/></svg></div><div id=header-links><a title="了解如何部署、使用和运维 Istio。" href=/v1.1/zh/docs/>文档</a>
<span title="关于使用 Istio 的博客文章。">博客</span>
<a title="一堆帮助您部署、配置和使用 Istio 的资源。" href=/v1.1/zh/help/>帮助</a>
<a title=关于Istio的说明。 href=/v1.1/zh/about/>关于</a><div class=menu><button id=gearDropdownButton class=menu-trigger title=选项和设置 aria-label="Options and Settings" aria-controls=gearDropdownContent><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#gear"/></svg></button><div id=gearDropdownContent class=menu-content aria-labelledby=gearDropdownButton role=menu><a tabindex=-1 role=menuitem lang=en id=switch-lang-en>English</a>
<a tabindex=-1 role=menuitem lang=zh id=switch-lang-zh class=active>中文</a><div role=separator></div><a tabindex=-1 role=menuitem class=active id=light-theme-item>亮主题</a>
<a tabindex=-1 role=menuitem id=dark-theme-item>暗主题</a><div role=separator></div><a tabindex=-1 role=menuitem id=syntax-coloring-item>代码高亮</a><div role=separator></div><h6>本站的其它版本</h6><a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://istio.io/blog\/2017\/adapter-model\/');return false;">当前版本</a>
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/blog\/2017\/adapter-model\/');return false;">下个版本</a>
<a tabindex=-1 role=menuitem href=https://archive.istio.io>旧版本</a></div></div><button id=search-show title=搜索istio.io aria-label=Search><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#magnifier"/></svg></button></div><form id=search-form name=cse role=search><input type=hidden name=cx value=013699703217164175118:iwwf17ikgf4>
<input type=hidden name=ie value=utf-8>
<input type=hidden name=hl value=en>
<input type=hidden id=search-page-url value=/v1.1/search.html>
<input id=search-textbox class=form-control name=q type=search aria-label=搜索istio.io>
<button id=search-close title="Cancel search" type=reset aria-label="Cancel search"><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#cancel-x"/></svg></button></form></nav></header><main class=primary><div id=sidebar-container class="sidebar-container sidebar-offcanvas"><nav id=sidebar aria-label="Section Navigation"><div class=directory><div class=card><button class="header dynamic" id=card0 title="2019 年的博客文章。" aria-controls=card0-body><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#blog"/></svg>2019 年的博客文章</button><div class=body aria-labelledby=card0 role=region id=card0-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card0><li role=none><a role=treeitem title="Istio 1.0.8 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.0.8/>发布 Istio 1.0.8</a></li><li role=none><a role=treeitem title="学习延长 Istio 自签发根证书的有效期的方法。" href=/v1.1/zh/blog/2019/root-transition/>延长 Istio 自签发根证书的有效期</a></li><li role=none><a role=treeitem title="发布 Istio 1.1.8 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.1.8/>发布 Istio 1.1.8</a></li><li role=none><a role=treeitem title="应对 CVE-2019-12243 带来的安全威胁。" href=/v1.1/zh/blog/2019/cve-2019-12243/>安全更新 - CVE-2019-12243</a></li><li role=none><a role=treeitem title="Istio 1.0 即将宣告终结。" href=/v1.1/zh/blog/2019/announcing-1.0-eol/>Istio 1.0 将在 2019 年 6 月 19 日停止支持</a></li><li role=none><a role=treeitem title="发布 Istio 1.1.7 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.1.7/>发布 Istio 1.1.7</a></li><li role=none><a role=treeitem title="Istio 1.1.6 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.1.6/>发布 Istio 1.1.6</a></li><li role=none><a role=treeitem title="发布 Istio 1.1.5 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.1.5/>发布 Istio 1.1.5</a></li><li role=none><a role=treeitem title="发布 Istio 1.1.4 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.1.4/>发布 Istio 1.1.4</a></li><li role=none><a role=treeitem title="Istio 1.1.3。" href=/v1.1/zh/blog/2019/announcing-1.1.3/>安全更新:发布 Istio 1.1.3</a></li><li role=none><a role=treeitem title="Istio 1.0.7 的补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.0.7/>安全更新:发布 Istio 1.0.7</a></li><li role=none><a role=treeitem title="Istio 1.1.2 的补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.1.2/>安全更新:发布 Istio 1.1.2</a></li><li role=none><a role=treeitem title="发布 Istio 1.1.1 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.1.1/>发布 Istio 1.1.1</a></li><li role=none><a role=treeitem title="Istio 1.1 发布声明。" href=/v1.1/zh/blog/2019/announcing-1.1/>宣布 Istio 1.1 发布</a></li><li role=none><a role=treeitem title="Istio 1.1 性能概览." href=/v1.1/zh/blog/2019/istio1.1_perf/>面向性能而架构的 Istio 1.1</a></li><li role=none><a role=treeitem title="发布 Istio 1.0.6 补丁版本。" href=/v1.1/zh/blog/2019/announcing-1.0.6/>Istio 1.0.6 发布</a></li><li role=none><a role=treeitem title="在多集群服务网格环境中配置 Istio 的路由规则。" href=/v1.1/zh/blog/2019/multicluster-version-routing/>多集群服务网格中的分版本路由</a></li><li role=none><a role=treeitem title=宣布新的博客策略。 href=/v1.1/zh/blog/2019/sail-the-blog/>博客策略更新</a></li><li role=none><a role=treeitem title="评估加入 Egress gateway 对性能造成的影响。" href=/v1.1/zh/blog/2019/egress-performance/>Egress gateway 性能测试</a></li><li role=none><a role=treeitem title="Istio 将数据面组件注入到现存部署之中的过程。" href=/v1.1/zh/blog/2019/data-plane-setup/>Istio Sidecar 注入过程解密</a></li><li role=none><a role=treeitem title="使用 AppSwitch 解决应用程序启动顺序和启动延迟。" href=/v1.1/zh/blog/2019/appswitch/>使用 AppSwitch 进行 Sidestepping 依赖性排序</a></li><li role=none><a role=treeitem title="如何使用 cert-manager 手工部署一个自定义 Ingress 网关。" href=/v1.1/zh/blog/2019/custom-ingress-gateway/>使用 Cert-Manager 部署一个自定义 Ingress 网关</a></li><li role=none><a role=treeitem title="Istio 推出新的讨论板。" href=/v1.1/zh/blog/2019/announcing-discuss.istio.io/>宣布 discuss.istio.io</a></li></ul></div></div><div class=card><button class="header dynamic" id=card1 title="2017 年的博客文章。" aria-controls=card1-body><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#blog"/></svg>2017 年的博客文章</button><div class="body default" aria-labelledby=card1 role=region id=card1-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card1><li role=none><a role=treeitem title=提高可用,降低延迟。 href=/v1.1/zh/blog/2017/mixer-spof-myth/>Mixer 和 SPOF 神话</a></li><li role=none><span role=treeitem class=current title="概要说明 Mixer 的插件架构。">Mixer 适配器模型</span></li><li role=none><a role=treeitem title="Istio 0.2 公告。" href=/v1.1/zh/blog/2017/0.2-announcement/>宣布 Istio 0.2</a></li><li role=none><a role=treeitem title="Istio 的策略如何关联 Kubernetes 的网络策略 。" href=/v1.1/zh/blog/2017/0.1-using-network-policy/>Istio 使用网络策略</a></li><li role=none><a role=treeitem title="使用 Istio 创建自动缩放的金丝雀部署。" href=/v1.1/zh/blog/2017/0.1-canary/>使用 Istio 进行金丝雀部署</a></li><li role=none><a role=treeitem title="Istio Auth 0.1 公告。" href=/v1.1/zh/blog/2017/0.1-auth/>使用 Istio 增强端到端安全</a></li><li role=none><a role=treeitem title="Istio 0.1 宣布。" href=/v1.1/zh/blog/2017/0.1-announcement/>初次了解 Istio</a></li></ul></div></div><div class=card><button class="header dynamic" id=card2 title="2018 年的博客文章。" aria-controls=card2-body><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#blog"/></svg>2018 年的博客文章</button><div class=body aria-labelledby=card2 role=region id=card2-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card2><li role=none><a role=treeitem title="发布 Istio 1.0.5 补丁版本。" href=/v1.1/zh/blog/2018/announcing-1.0.5/>Istio 1.0.5 发布</a></li><li role=none><a role=treeitem title="发布 Istio 1.0.4 补丁版本。" href=/v1.1/zh/blog/2018/announcing-1.0.4/>Istio 1.0.4 发布</a></li><li role=none><a role=treeitem title="如何在不部署 Sidecar 代理的情况下使用 Istio 进行流量管理。" href=/v1.1/zh/blog/2018/incremental-traffic-management/>增量式应用 Istio 第一部分,流量管理</a></li><li role=none><a role=treeitem title="描述了一个基于 Istio 的 Bookinfo 示例的简单场景。" href=/v1.1/zh/blog/2018/egress-mongo/>使用外部 MongoDB 服务</a></li><li role=none><a role=treeitem title="发布 Istio 1.0.3 补丁版本。" href=/v1.1/zh/blog/2018/announcing-1.0.3/>Istio 1.0.3 发布</a></li><li role=none><a role=treeitem title="发布 Istio 1.0.2 补丁版本." href=/v1.1/zh/blog/2018/announcing-1.0.2/>Istio 1.0.2 发布</a></li><li role=none><a role=treeitem title="发布 Istio 1.0.1 补丁版本。" href=/v1.1/zh/blog/2018/announcing-1.0.1/>Istio 1.0.1 发布</a></li><li role=none><a role=treeitem title="Istio 在 Twitch 举办了为期一天的直播庆祝 1.0 的发布。" href=/v1.1/zh/blog/2018/istio-twitch-stream/>Istio 在 Twitch 上全天直播</a></li><li role=none><a role=treeitem title="惠普如何在 Istio 上构建其下一代鞋类个性化平台。" href=/v1.1/zh/blog/2018/hp/>Istio 是惠普 FitStation 平台的改变者</a></li><li role=none><a role=treeitem title="Istio 1.0 已生产就绪。" href=/v1.1/zh/blog/2018/announcing-1.0/>宣布 Istio 1.0</a></li><li role=none><a role=treeitem title="使用 AppSwitch 自动接入应用并降低延迟。" href=/v1.1/zh/blog/2018/delayering-istio/>使用 AppSwitch 精简 Istio 层次</a></li><li role=none><a role=treeitem title="描述 Istio 的授权功能以及如何在各种用例中使用它。" href=/v1.1/zh/blog/2018/istio-authorization/>基于 Istio 的 Micro-Segmentation 授权</a></li><li role=none><a role=treeitem title="如何通过 Stackdriver 将 Istio 访问日志导出到 BigQuery、GCS、Pub/Sub 等不同的接收器。" href=/v1.1/zh/blog/2018/export-logs-through-stackdriver/>通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</a></li><li role=none><a role=treeitem title="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。" href=/v1.1/zh/blog/2018/egress-monitoring-access-control/>HTTP Egress 流量监控和访问策略</a></li><li role=none><a role=treeitem title="Istio v1alpha3 路由 API 介绍,动机及其设计原则。" href=/v1.1/zh/blog/2018/v1alpha3-routing/>Istio v1aplha3 路由 API 介绍</a></li><li role=none><a role=treeitem title="描述如何在AWS上使用网络负载均衡器配置 Istio Ingress。" href=/v1.1/zh/blog/2018/aws-nlb/>使用AWS NLB 配置 Istio Ingress</a></li><li role=none><a role=treeitem title="使用 Kubernetes 命名空间和 RBAC 为 Istio 构建软性多租户环境。" href=/v1.1/zh/blog/2018/soft-multitenancy/>Istio 的软性多租户支持</a></li><li role=none><a role=treeitem title=介绍更安全,低风险的部署和发布到生产。 href=/v1.1/zh/blog/2018/traffic-mirroring/>用于在生产环境进行测试的 Istio 流量镜像功能</a></li><li role=none><a role=treeitem title="描述基于 Istio 的 Bookinfo 示例的简单场景。" href=/v1.1/zh/blog/2018/egress-tcp/>使用外部 TCP 服务</a></li><li role=none><a role=treeitem title="描述基于 Istio Bookinfo 示例的简单场景。" href=/v1.1/zh/blog/2018/egress-https/>使用外部 Web 服务</a></li></ul></div></div></div></nav></div><div class=article-container><button tabindex=-1 id=sidebar-toggler title=折叠导航栏><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#pull"/></svg></button><nav aria-label=Breadcrumb><ol><li><a href=/v1.1/zh/>Istio</a></li><li><a href=/v1.1/zh/blog/ title="关于使用 Istio 的博客文章。">博客</a></li><li><a href=/v1.1/zh/blog/2017/ title="2017 年的博客文章。">2017 年的博客文章</a></li><li>Mixer 适配器模型</li></ol></nav><article aria-labelledby=title><div class=title-area><div><h1 id=title>Mixer 适配器模型</h1><p class=subtitle>将 Istio 与后端基础设施整合</p><p class=byline><span>作者</span>
<span class=attribution>Martin Taillefer</span><span> | </span><span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#calendar"/></svg><span>&nbsp;</span>2017年11月3日</span></p></div></div><nav class=toc-inlined aria-label="Table of Contents"><div><hr><ol><li role=none aria-label=为什么是适配器模型?><a href=#%e4%b8%ba%e4%bb%80%e4%b9%88%e6%98%af%e9%80%82%e9%85%8d%e5%99%a8%e6%a8%a1%e5%9e%8b>为什么是适配器模型?</a><li role=none aria-label=设计哲学><a href=#%e8%ae%be%e8%ae%a1%e5%93%b2%e5%ad%a6>设计哲学</a><li role=none aria-label="Handlers: 适配器的配置"><a href=#handlers-%e9%80%82%e9%85%8d%e5%99%a8%e7%9a%84%e9%85%8d%e7%bd%ae>Handlers: 适配器的配置</a><li role=none aria-label="Templates: 适配输入结构"><a href=#templates-%e9%80%82%e9%85%8d%e8%be%93%e5%85%a5%e7%bb%93%e6%9e%84>Templates: 适配输入结构</a><li role=none aria-label="Instances: 属性映射"><a href=#instances-%e5%b1%9e%e6%80%a7%e6%98%a0%e5%b0%84>Instances: 属性映射</a><li role=none aria-label="Rules: 将数据交付给适配器"><a href=#rules-%e5%b0%86%e6%95%b0%e6%8d%ae%e4%ba%a4%e4%bb%98%e7%bb%99%e9%80%82%e9%85%8d%e5%99%a8>Rules: 将数据交付给适配器</a><li role=none aria-label=未来的工作><a href=#%e6%9c%aa%e6%9d%a5%e7%9a%84%e5%b7%a5%e4%bd%9c>未来的工作</a><li role=none aria-label=结论><a href=#%e7%bb%93%e8%ae%ba>结论</a><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol><hr></div></nav><p>Istio 0.2 引入了一种新的 Mixer 适配器模型,这种模型使接入后端基础设施具有更多的灵活性 。本文将解释这种模型是如何工作的。</p><h2 id=为什么是适配器模型>为什么是适配器模型?</h2><p>后端基础设施提供了支持服务构建的功能。他们包括访问控制、遥测、配额控制、计费系统等等。传统服务会直接与这些后端系统集成,并与后端紧密耦合,并集成到其中的个性化语义和操作。</p><p>Mixer 服务作为 Istio 和一套开放式基础设施之间的抽象层。Istio 组件和运行在 Service Mesh 中的服务,通过 Mixer 就可以在不直接访问后端接口的情况下和这些后端进行交互。</p><p>除了作为应用层与基础设施隔离外Mixer 提供了一种中介模型,这种模型允许注入和控制应用和后端的策略。操作人员可以控制哪些数据汇报给哪个后端,哪个后端提供授权等等。</p><p>考虑到每个基础服务都有不同的接口和操作模型Mixer 需要用户通过代码来解决这些差异,我们可以称这些用户自己封装的代码为<a href=https://github.com/istio/istio/wiki/Mixer-Compiled-In-Adapter-Dev-Guide><em>适配器</em></a></p><p>适配器以 Go 包的形式直接链接到 Mixer 二进制中。如果默认的适配器不能满足特定的使用需求,自定义适配器也是很简单的。</p><h2 id=设计哲学>设计哲学</h2><p>Mixer 本质上就是一个处理属性和路由的机器。代理将<a href=/v1.1/zh/docs/concepts/policies-and-telemetry/#属性>属性</a>作为预检和遥测报告的一部分发送出来,并且转换为一系列对适配器的调用。运维人员提供了用于描述如何将传入的属性映射为适配器的配置。</p><figure style=width:60%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:42.60859894197215%><a data-skipendnotes=true href=/v1.1/docs/concepts/policies-and-telemetry/machine.svg title="Attribute Machine"><img class=element-to-stretch src=/v1.1/docs/concepts/policies-and-telemetry/machine.svg alt="Attribute Machine"></a></div><figcaption>Attribute Machine</figcaption></figure><p>配置是一个复杂的任务。有证据表明绝大多数服务中断是由配置错误造成的。为了帮助解决这一问题Mixer 的配置模型通过做限制来避免错误。例如,在配置中使用强类型,以此来确保在上下文环境中使用了有意义的属性或者属性表达式。</p><h2 id=handlers-适配器的配置>Handlers: 适配器的配置</h2><p>Mixer 使用的每个适配器都需要一些配置才能运行。一般来说,适配器需要一些信息。例如,到后端的 URL 、证书、缓存选项等等。每个适配器使用一个 <a href=https://developers.google.com/protocol-buffers/>protobuf</a> 消息来定义所需要的配置数据。</p><p>你可以通过创建 <a href=/v1.1/zh/docs/concepts/policies-and-telemetry/#处理器-handler><em>handler</em></a> 为适配器提供配置。Handler 就是一套能让一个适配器就绪的完整配置。对同一个适配器可以有任意数量的 Handler这样就可以在不同的场景下复用了。</p><h2 id=templates-适配输入结构>Templates: 适配输入结构</h2><p>通常对于进入到 Mesh 服务中的请求Mixer 会发生两次调用一次是预检一次是遥测报告。每一次调用Mixer 都会调用一个或更多的适配器。不同的适配器需要不同的数据作为输入来处理。例如日志适配器需要日志输入metric 适配器需要 metric 数据作为输入认证的适配器需要证书等等。Mixer <a href=/v1.1/zh/docs/reference/config/policy-and-telemetry/templates/><em>templates</em></a> 用来描述每次请求适配器消费的数据。</p><p>每个 Template 被指定为 <a href=https://developers.google.com/protocol-buffers/>protobuf</a> 消息。一个模板描述了一组数据,这些数据在运行时被传递给一个或多个适配器。一个适配器可以支持任意数量的模板,开发者还可以设计支持特定模板的是适配器。</p><p><a href=/v1.1/zh/docs/reference/config/policy-and-telemetry/templates/metric/><code>metric</code></a><a href=/v1.1/zh/docs/reference/config/policy-and-telemetry/templates/logentry/><code>logentry</code></a> 是两个最重要的模板,分别表示负载的单一指标,和到适当后端的单一日志条目。</p><h2 id=instances-属性映射>Instances: 属性映射</h2><p>你可以通过创建 <a href=/v1.1/zh/docs/concepts/policies-and-telemetry/#实例-instance><em>instances</em></a> 来决定哪些数据被传递给特定的适配器。Instances 决定了 Mixer 如何通过 <a href=/v1.1/zh/docs/concepts/policies-and-telemetry/#属性>attributes</a> 把来自代理的属性拆分为各种数据然后分发给不同的适配器。</p><p>创建实例通常需要使用 <a href=/v1.1/zh/docs/concepts/policies-and-telemetry/#属性表达式>attribute expressions</a> 。这些表达式的功能是使用属性和常量来生成结果数据用于给instance字段进行赋值。</p><p>在模板中定义的每个 instance 字段、每个属性、每个表达式都有一个 <a href=https://github.com/istio/api/blob/master/policy/v1beta1/value_type.proto>type</a>,只有兼容的数据类型才能进行赋值。例如不能把整型的表达式赋值给字符串类型。强类型设计的目的就是为了降低配置出错引发的风险。</p><h2 id=rules-将数据交付给适配器>Rules: 将数据交付给适配器</h2><p>最后一个问题就是告诉 Mixer 哪个 instance 在什么时候发送给哪个 handler。这个通过创建 <a href=/v1.1/zh/docs/concepts/policies-and-telemetry/#规则-rule><em>rules</em></a> 实现。每个规则都会指定一个特定的处理程序和要发送给该处理程序的示例。当 Mixer 处理一个调用时,它会调用指定的处理程序,并给他一组特定的处理实例。</p><p>Rule 中包含有匹配断言,这个断言是一个返回布尔值的属性表达式。只有属性表达式断言成功的 Rule 才会生效,否则这条规则就形同虚设,当然其中的 Handler 也不会被调用。</p><h2 id=未来的工作>未来的工作</h2><p>我们正在努力改进和提升适配器的使用及开发。例如,计划中包含很多新特性使用户更加方便地使用 Templates。另外表达式语言也正在不断的发展和成熟。</p><p>长远来看,我们正在寻找不直接将适配器直接连接到 Mixer 二进制的方法。这将简化部署和开发使用。</p><h2 id=结论>结论</h2><p>新的 Mixer 适配器模型的设计是为了提供一个灵活的框架用来支持一个开放基础设施。</p><p>Handler 为各个适配器提供了配置数据Template 用于在运行时确定不同的适配器所需的数据类型Instance 让运维人员准备这些数据Rule 将这些数据提交给一个或多个 Handler 进行处理。</p><p>更多信息可以关注<a href=/v1.1/zh/docs/concepts/policies-and-telemetry/>这里</a>。更多关于 templates, handlers,和 rules 的内容可以关注<a href=/v1.1/zh/docs/reference/config/policy-and-telemetry/>这里</a>。你也可以在<a href=https://github.com/istio/istio/tree/release-1.1/samples/bookinfo>这里</a>找到对应的示例。</p><nav id=see-also><h2>相关内容</h2><div class=see-also><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/examples/advanced-gateways/egress_sni_monitoring_and_policies/>Egress TLS 流量中的 SNI 监控及策略</a></p><p class=desc>如何为 Egress TLS 流量配置 SNI 监控并应用策略。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/concepts/policies-and-telemetry/>策略与遥测</a></p><p class=desc>描述策略实施和遥测机制。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/policy-enforcement/denial-and-list/>Denier 适配器以及黑白名单</a></p><p class=desc>展示使用简单的 Denier 适配器或黑白名单对服务进行访问控制的方法。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/telemetry/distributed-tracing/jaeger/>Jaeger</a></p><p class=desc>了解如何配置代理以向 Jaeger 发送追踪请求。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/telemetry/distributed-tracing/zipkin/>Zipkin</a></p><p class=desc>了解如何配置代理以向 Zipkin 发送追踪请求。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/telemetry/logs/fluentd/>使用 Fluentd 记录日志</a></p><p class=desc>此任务说明如何配置 Istio 以将日志输出到 Fluentd 守护程序。</p></div></div></nav></article><nav class=pagenav><div class=left><a title=提高可用,降低延迟。 href=/v1.1/zh/blog/2017/mixer-spof-myth/><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#left-arrow"/></svg>Mixer 和 SPOF 神话</a></div><div class=right><a title="Istio 0.2 公告。" href=/v1.1/zh/blog/2017/0.2-announcement/>宣布 Istio 0.2<svg class="icon"><use xlink:href="/v1.1/img/icons.svg#right-arrow"/></svg></a></div></nav><div id=endnotes-container aria-hidden=true><h2>链接</h2><ol id=endnotes></ol></div></div><div class=toc-container><nav class=toc aria-label="Table of Contents"><div id=toc><ol><li role=none aria-label=为什么是适配器模型?><a href=#%e4%b8%ba%e4%bb%80%e4%b9%88%e6%98%af%e9%80%82%e9%85%8d%e5%99%a8%e6%a8%a1%e5%9e%8b>为什么是适配器模型?</a><li role=none aria-label=设计哲学><a href=#%e8%ae%be%e8%ae%a1%e5%93%b2%e5%ad%a6>设计哲学</a><li role=none aria-label="Handlers: 适配器的配置"><a href=#handlers-%e9%80%82%e9%85%8d%e5%99%a8%e7%9a%84%e9%85%8d%e7%bd%ae>Handlers: 适配器的配置</a><li role=none aria-label="Templates: 适配输入结构"><a href=#templates-%e9%80%82%e9%85%8d%e8%be%93%e5%85%a5%e7%bb%93%e6%9e%84>Templates: 适配输入结构</a><li role=none aria-label="Instances: 属性映射"><a href=#instances-%e5%b1%9e%e6%80%a7%e6%98%a0%e5%b0%84>Instances: 属性映射</a><li role=none aria-label="Rules: 将数据交付给适配器"><a href=#rules-%e5%b0%86%e6%95%b0%e6%8d%ae%e4%ba%a4%e4%bb%98%e7%bb%99%e9%80%82%e9%85%8d%e5%99%a8>Rules: 将数据交付给适配器</a><li role=none aria-label=未来的工作><a href=#%e6%9c%aa%e6%9d%a5%e7%9a%84%e5%b7%a5%e4%bd%9c>未来的工作</a><li role=none aria-label=结论><a href=#%e7%bb%93%e8%ae%ba>结论</a><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol></div></nav></div></main><footer><div class=user-links><a class=channel title="Go download Istio 1.1.9 now" href=https://github.com/istio/istio/releases/tag/1.1.9 aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#download"/></svg>
</a><a class=channel title="加入 Istio discussion board 参与讨论获取帮助" href=https://discuss.istio.io aria-label="Istio discussion board"><span>discuss</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#discourse"/></svg></a>
<a class=channel title="Stack Overflow 中列举了针对实际问题以及部署、配置和使用 Istio 的各项回答" href=https://stackoverflow.com/questions/tagged/istio aria-label="Stack Overflow"><span>stack overflow</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#stackoverflow"/></svg></a>
<a class=channel title="关注我们的 Twitter 来获取最新信息" href=https://twitter.com/IstioMesh aria-label=Twitter><span>twitter</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
1.1.9<br>&copy; 2019 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2019年6月18日</p></div><div class=dev-links><a class=channel title="Istio 的代码在 GitHub 上开发" href=https://github.com/istio/community aria-label=GitHub><span>github</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#github"/></svg></a>
<a class=channel title="在 Slack 上与 Istio 社区交互讨论开发问题(仅限邀请)" href=https://istio.slack.com aria-label=slack><span>slack</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#slack"/></svg></a>
<a class=channel title="如果您想深入了解 Istio 的技术细节,请查看我们日益完善的设计文档" href=https://groups.google.com/forum/#!forum/istio-team-drive-access aria-label="team drive"><span>drive</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#drive"/></svg></a>
<a class=channel title="如果您想为 Istio 项目做出贡献,请考虑加入我们的工作组" href=https://github.com/istio/community/blob/master/WORKING-GROUPS.md aria-label="working groups"><span>working groups</span><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#working-groups"/></svg></a><div class=tag>对于开发者</div></div></footer><div id=scroll-to-top-container aria-hidden=true><button id=scroll-to-top title=回到顶部><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#top"/></svg></button></div></body></html>