要了解政策和遙測,首先要了解 Mixer 的架構;
[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-sUuojjzC-1664190859192)(https://istio.io/docs/concepts/policies-and-telemetry/topology-with-cache.svg)]
[外鍊圖檔轉存失敗,源站可能有防盜鍊機制,建議将圖檔儲存下來直接上傳(img-NghRMvEl-1664190859194)(https://istio.io/docs/concepts/policies-and-telemetry/machine.svg)]
擴充卡和模闆(Template)
擴充卡 封裝了 Mixer 和特定基礎設施後端之間的接口,把 Mixer 和基礎設施後端連接配接起來。Istio已經實作了多個擴充卡。各種擴充卡都需要參數配置才能工作。例如日志擴充卡可能需要 IP 位址和端口來進行日志的輸出。Istio使用處理器(Handler)來給擴充卡配置參數來生成一個擴充卡執行個體;。
模闆 定義了從特定請求的屬性到擴充卡輸入的映射關系。一個擴充卡可以支援任意數量的模闆。一個模闆代表了一條check或者report的data item;
TEMPLATE_VARIETY_CHECK
TEMPLATE_VARIETY_REPORT
TEMPLATE_VARIETY_QUOTA
TEMPLATE_VARIETY_ATTRIBUTE_GENERATOR
政策和遙控功能的控制能力包含了三種類型資源的配置:
配置一組處理器(Handler),用于确定正在使用的擴充卡組及其操作方式。處理器配置的一個例子如:為 Statsd 後端提供帶有 IP 位址的 statsd 擴充卡。
配置一組執行個體(Instance),描述如何将請求屬性映射到擴充卡輸入。執行個體表示一個或多個擴充卡将操作的各種資料。例如,運維人員可能決定從諸如 destination.service 和 response.code 之類的屬性中生成 requestcount 名額的執行個體。
配置一組規則(Rule),這些規則描述了何時調用特定擴充卡及哪些執行個體。規則包含 match 表達式和 action。match 表達式控制何時調用擴充卡,而 action 決定了要提供給擴充卡的一組執行個體。例如,規則可能會将生成的 requestcount 執行個體發送到 statsd 擴充卡。
apiVersion: config.istio.io/v1alpha2
kind: handler
metadata:
name: quotahandler
namespace: istio-system
spec:
compiledAdapter: memquota
params:
quotas:
- name: requestcountquota.instance.istio-system
maxAmount: 500
validDuration: 1s
# The first matching override is applied.
# A requestcount instance is checked against override dimensions.
overrides:
# The following override applies to 'reviews' regardless
# of the source.
- dimensions:
destination: reviews
maxAmount: 1
validDuration: 5s
# The following override applies to 'productpage' when
# the source is a specific ip address.
- dimensions:
destination: productpage
source: "10.28.11.20"
maxAmount: 500
validDuration: 1s
# The following override applies to 'productpage' regardless
# of the source.
- dimensions:
destination: productpage
maxAmount: 2
validDuration: 5s
---
apiVersion: config.istio.io/v1alpha2
kind: instance
metadata:
name: requestcountquota
namespace: istio-system
spec:
compiledTemplate: quota
params:
dimensions:
source: request.headers["x-forwarded-for"] | "unknown"
destination: destination.labels["app"] | destination.service.name | "unknown"
destinationVersion: destination.labels["version"] | "unknown"