ASM流量调度套件支持请求优先级调度策略。当系统发生过载时,优先级高的请求能够更快地被处理。本文介绍如何使用流量调度套件提供的AverageLatencySchedulingPolicy来实现请求优先级调度。
背景信息
请求优先级调度策略通过将实时延迟和历史平均值进行比较来检测流量过载,并通过令牌桶和优先级机制来对请求进行调度。大致工作流程如下:
过载检测:该策略会将过去一段时间内的平均延迟和当前延迟进行比较,判断系统是否发生过载。
调整令牌发放速率:如果发生过载,上一步得到的监测数据会被发送给一个专用的控制器,这个控制器会控制令牌桶的填充速率。
请求调度:不同的请求可以拥有不同的优先级,发生过载时,高优先级的请求会有更大的机会获得令牌。
当遇到高并发造成服务阻塞,响应延迟持续上升的情况时,使用此策略可以对请求进行排队。和常用的限流策略不同,此时请求不会被直接拒绝,而是进入一个优先级队列。最终,通过令牌桶机制对请求进行限速,并且根据优先级调整请求处理顺序。
前提条件
已添加Kubernetes托管版集群到ASM实例,且ASM实例为v1.21.6.44及以上。具体操作,请参见添加集群到ASM实例。
已为Kubernetes集群中的default命名空间开启自动注入。具体操作,请参见管理全局命名空间。
已通过kubectl连接至ACK集群。 具体操作,请参见获取集群KubeConfig并通过kubectl工具连接集群。
已开启ASM流量调度套件。具体操作,请参见开启ASM流量调度套件。
已经部署httpbin应用,并且可以通过网关访问,具体操作,请参见部署httpbin应用
(可选)已经开启ASM网关访问日志,请参见生成和采集ASM网关访问日志
步骤一:创建AverageLatencySchedulingPolicy
使用kubectl连接到ASM实例,具体操作,请参见通过控制面kubectl访问Istio资源。
使用以下内容,创建AverageLatencySchedulingPolicy.yaml文件。
apiVersion: istio.alibabacloud.com/v1 kind: AverageLatencySchedulingPolicy metadata: name: workload-prioritization namespace: istio-system spec: load_scheduling_core: aimd_load_scheduler: load_scheduler: workload_latency_based_tokens: true selectors: - service: httpbin.default.svc.cluster.local scheduler: workloads: - label_matcher: match_labels: http.request.header.user_type: "guest" parameters: priority: 50.0 name: "guest" - label_matcher: match_labels: http.request.header.user_type: "subscriber" parameters: priority: 200.0 name: "subscriber"
部分配置项说明如下:
字段
说明
workload_latency_based_tokens
基于workload的平均延迟来动态调整token数量。平均延迟的估算时间窗口是最近30min。
service
该调度策略在这个service上生效。
workloads
根据请求header中的user_type定义了两类请求,分别是guest和subscriber。guest类型的请求优先级是50,subscriber的请求优先级是200。
AverageLatencySchedulingPolicy支持的字段请参考对应的CRD说明文档AverageLatencySchedulingPolicy CRD说明。
步骤二:测试
这里我们使用压测工具fortio,安装方式请参见安装fortio。
首先,我们模拟一些平时的业务请求,此时主要是为了产生请求延迟的平均值:
fortio load -c 20 -qps 100000 -t 60m http://${ASM网关IP}/status/200
等待上述命令运行3分钟后,重新打开两个终端,发送正式的测试请求。整个测试期间,请确保上面的fortio进程一直在运行中,不要关闭对应的终端。
在新打开的两个终端中,分别运行下面两个压测命令(尽可能同时开始运行这两个测试):
fortio load -c 40 -qps 100000 -H "user_type:guest" -t 3m http://${ASM网关IP}/status/201
fortio load -c 40 -qps 100000 -H "user_type:subscriber" -t 3m http://${ASM网关IP}/status/202
此处我们使用了不同的请求路径,主要是为了方便从访问日志中观察测试结果。
步骤三:分析测试结果
首先等待上述的两个测试命令执行结束,当前测试环境下两个命令的输出的最后几行分别是:
Code 201 : 26852 (97.8 %)
Code 503 : 601 (2.2 %)
Response Header Sizes : count 27453 avg 242.91564 +/- 36.35 min 0 max 249 sum 6668763
Response Body/Total Sizes : count 27453 avg 246.17754 +/- 14.56 min 149 max 249 sum 6758312
All done 27453 calls (plus 40 warmup) 262.318 ms avg, 152.4 qps
Code 202 : 52765 (100.0 %)
Response Header Sizes : count 52765 avg 248.86358 +/- 0.5951 min 248 max 250 sum 13131287
Response Body/Total Sizes : count 52765 avg 248.86358 +/- 0.5951 min 248 max 250 sum 13131287
All done 52765 calls (plus 40 warmup) 136.472 ms avg, 292.9 qps
可以看出:
subscriber用户的请求都成功了,没有503的响应;guest用户的请求有2.2%返回了503。
subscriber用户的请求平均延迟大致为136ms;guest用户平均延迟大约为262ms。并且两个用户的QPS也存在显著差异。
由此可以证明,在请求延迟突增时AverageLatencySchedulingPolicy会优先处理subscriber的请求。
本文中的验证结果仅为理论值,实际数据以您的操作环境为准。不同测试环境的压力测试结果存在差异,此处仅分析数据的相对关系。
(可选)步骤四:通过网关访问日志分析测试结果
登录ASM控制台,在左侧导航栏,选择服务网格 > 网格管理。
在网格管理页面,单击目标实例名称,然后在左侧导航栏,选择ASM网关 > 入口网关。
点击对应ASM网关名称,进入网关概览,点击网关日志,查看网关访问日志。
guest和subscriber的访问路径不同,可以通过这点分别检索两者的访问结果:
相关操作
您可以通过Grafana大盘来观测AverageLatencySchedulingPolicy策略的执行效果。请确保Grafana使用的数据源Prometheus实例已经完成配置采集ASM流量调度套件相关指标。
将以下内容导入到Grafana,创建AverageLatencySchedulingPolicy策略的大盘。
展开查看JSON内容
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 40,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Decisions",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 0
},
"id": 1,
"interval": "10s",
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by(decision_type, policy_name) (rate(workload_requests_total{component_id=\"root.0.4\"}[$__rate_interval]))",
"intervalFactor": 1,
"range": true,
"refId": "A"
}
],
"title": "Workload Decisions",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Decisions",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 10
},
"id": 2,
"interval": "10s",
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by(workload_index, decision_type, policy_name) (rate(workload_requests_total{component_id=\"root.0.4\",decision_type=\"DECISION_TYPE_ACCEPTED\"}[$__rate_interval]))",
"intervalFactor": 1,
"range": true,
"refId": "A"
}
],
"title": "Workload Decisions (accepted)",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Decisions",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 20
},
"id": 3,
"interval": "10s",
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by(workload_index, decision_type, policy_name) (rate(workload_requests_total{component_id=\"root.0.4\",decision_type=\"DECISION_TYPE_REJECTED\"}[$__rate_interval]))",
"intervalFactor": 1,
"range": true,
"refId": "A"
}
],
"title": "Workload Decisions (rejected)",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"noValue": "No data",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 8,
"x": 0,
"y": 30
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.9",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name) (increase(workload_requests_total{component_id=\"root.0.4\"}[$__range]))",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ instance }} - {{ policy_name }}",
"range": true,
"refId": "A"
}
],
"title": "Total Requests",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"noValue": "No data",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 8,
"x": 8,
"y": 30
},
"id": 5,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.9",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name)(increase(workload_requests_total{component_id=\"root.0.4\", decision_type=\"DECISION_TYPE_ACCEPTED\"}[$__range]))",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ instance }} - {{ policy_name }}",
"range": true,
"refId": "A"
}
],
"title": "Total Accepted Requests",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"noValue": "No rejected requests",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 8,
"x": 16,
"y": 30
},
"id": 6,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.9",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name) (increase(workload_requests_total{component_id=\"root.0.4\", decision_type=\"DECISION_TYPE_REJECTED\"}[$__range]))",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ instance }} - {{ policy_name }}",
"range": true,
"refId": "A"
}
],
"title": "Total Rejected Requests",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Latency",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "ms"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 40
},
"id": 7,
"interval": "10s",
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "(sum by (workload_index, policy_name) (increase(workload_latency_ms_sum{component_id=\"root.0.4\"}[$__rate_interval])))/(sum by (workload_index, policy_name) (increase(workload_latency_ms_count{component_id=\"root.0.4\"}[$__rate_interval])))",
"intervalFactor": 1,
"range": true,
"refId": "A"
}
],
"title": "Workload Latency",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Wait Time",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "ms"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 12,
"x": 0,
"y": 50
},
"id": 8,
"interval": "10s",
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "(sum by (workload_index, policy_name) (increase(request_in_queue_duration_ms_sum{component_id=\"root.0.4\"}[$__rate_interval])))/ ((sum by (workload_index, policy_name) (increase(request_in_queue_duration_ms_count{component_id=\"root.0.4\"}[$__rate_interval]))) != 0)",
"intervalFactor": 1,
"range": true,
"refId": "A"
}
],
"title": "Request in Queue Duration",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisGridShow": true,
"axisLabel": "",
"axisPlacement": "hidden",
"fillOpacity": 80,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineWidth": 1,
"scaleDistribution": {
"type": "linear"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "ms"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 12,
"x": 12,
"y": 50
},
"id": 9,
"options": {
"barRadius": 0,
"barWidth": 0.97,
"colorByField": "",
"fullHighlight": false,
"groupWidth": 0.7,
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"orientation": "horizontal",
"showValue": "auto",
"stacking": "none",
"tooltip": {
"mode": "single",
"sort": "sort"
},
"xTickLabelRotation": 0,
"xTickLabelSpacing": 0
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "topk(10, (sum by(workload_index, policy_name) (increase(request_in_queue_duration_ms_sum{component_id=\"root.0.4\"}[$__range])) ) / ((sum by(workload_index, policy_name) (increase(request_in_queue_duration_ms_count{component_id=\"root.0.4\"}[$__range])) )) != 0)",
"format": "time_series",
"instant": true,
"intervalFactor": 1,
"legendFormat": "",
"range": false,
"refId": "A"
}
],
"title": "Request in Queue Duration",
"type": "barchart"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Token Rate",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": ""
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 60
},
"id": 12,
"interval": "10s",
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name) (rate(incoming_tokens_total{component_id=\"root.0.4\"}[$__rate_interval]))",
"intervalFactor": 1,
"range": true,
"refId": "A"
}
],
"title": "Incoming Token Rate",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "Token Rate",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": ""
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 60
},
"id": 13,
"interval": "10s",
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "v10.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name) (rate(accepted_tokens_total{component_id=\"root.0.4\"}[$__rate_interval]))",
"intervalFactor": 1,
"legendFormat": "Accepted Token Rate",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"expr": "sum(rate(rejected_tokens_total{component_id=\"root.0.4\",policy_name=\"workload-prioritization\"}[$__rate_interval]))",
"intervalFactor": 1,
"legendFormat": "Rejected Token Rate",
"refId": "B"
}
],
"title": "Accepted Token Rate vs Rejected Token Rate",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"noValue": "No data",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 8,
"x": 0,
"y": 68
},
"id": 14,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.9",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name) (increase(incoming_tokens_total{component_id=\"root.0.4\"}[$__range]))",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ instance }} - {{ policy_name }}",
"range": true,
"refId": "A"
}
],
"title": "Total Incoming Tokens",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"noValue": "No data",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 8,
"x": 8,
"y": 68
},
"id": 15,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.9",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name) (increase(accepted_tokens_total{component_id=\"root.0.4\"}[$__range]))",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ instance }} - {{ policy_name }}",
"range": true,
"refId": "A"
}
],
"title": "Total Accepted Tokens",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"noValue": "No data",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 8,
"x": 16,
"y": 68
},
"id": 16,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.9",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"editorMode": "code",
"expr": "sum by (policy_name) (increase(rejected_tokens_total{component_id=\"root.0.4\"}[$__range]))",
"instant": false,
"intervalFactor": 1,
"legendFormat": "{{ instance }} - {{ policy_name }}",
"range": true,
"refId": "A"
}
],
"title": "Total Rejected Tokens",
"type": "stat"
}
],
"refresh": "5s",
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"hide": 0,
"includeAll": false,
"label": "Data Source",
"multi": false,
"name": "datasource",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"type": "datasource"
}
]
},
"time": {
"from": "now-15m",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "Policy Summary - workload-prioritization",
"version": 1,
"weekStart": ""
}
大盘效果如下。