crane
crane copied to clipboard
dashboard 当中的 workload insight 图表有缺陷
Describe the bug dashboard 当中的 workload insight 图表有缺陷
Reproduce steps 当有workload的名字存在前缀包含时将无法展示正确数据, 例如有一个 Deployment 名字是 application,另一个Deployment名字是 application-gateway,因为图表当中用了前缀匹配所以数据会有问题
Expected behavior 正常区分不同的 Workload
Screenshots
Environment (please complete the following information):
- K8S Version: 1.20
- Crane Version: 0.10.0
- Browser: firefox
我贴一下我调试好的board,就是利用 kube_state_metrics group 指标,用严格的名字匹配
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__elements": {},
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "9.5.3"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"version": ""
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"description": "Workload Insight",
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": null,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "Workload optimize model dashboard, calculate all pods metric",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"graph": false,
"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
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 4,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on (replicaset) group_right() label_replace(max(kube_pod_info{namespace=\"$Namespace\", created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on (pod) group_right() sum(irate(container_cpu_usage_seconds_total{namespace=\"$Namespace\", container!=\"sandbox\", container!=\"\"}[3m])) by (pod))",
"legendFormat": "usage",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on (replicaset) group_right() label_replace(max(kube_pod_info{namespace=\"$Namespace\", created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on (pod) group_right() sum(kube_pod_container_resource_requests{namespace=\"$Namespace\",unit=\"core\",resource=\"cpu\"}) by (pod))",
"hide": false,
"legendFormat": "request",
"range": true,
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(crane_analysis_resource_recommendation{namespace=\"$Namespace\",owner_kind=\"$WorkloadType\",resource=\"cpu\",owner_name=\"$Workload\"}) *\ncount(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on(replicaset) group_right() label_replace(max(kube_pod_info{created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on(pod) group_right() count(kube_pod_info{namespace=\"$Namespace\"}) by (pod))",
"hide": false,
"legendFormat": "recommend",
"range": true,
"refId": "C"
}
],
"title": "Workload Pods Insight - CPU",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "Workload optimize model dashboard, calculate all pods metric",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"graph": false,
"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
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 7,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on(replicaset) group_right() label_replace(max(kube_pod_info{namespace=\"$Namespace\", created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on(pod) group_right() sum(container_memory_working_set_bytes{namespace=\"$Namespace\", container!=\"sandbox\", container!=\"\"}/1024/1024/1024) by (pod))",
"legendFormat": "usage",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on(replicaset) group_right() label_replace(max(kube_pod_info{namespace=\"$Namespace\", created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on(pod) group_right() sum(kube_pod_container_resource_requests{namespace=\"$Namespace\", unit=\"byte\",resource=\"memory\"}/1024/1024/1024) by (pod))",
"hide": false,
"legendFormat": "request",
"range": true,
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(crane_analysis_resource_recommendation{namespace=\"$Namespace\",owner_kind=\"$WorkloadType\",resource=\"memory\",owner_name=\"$Workload\"}) *\ncount(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on(replicaset) group_right() label_replace(max(kube_pod_info{created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on(pod) group_right() count(kube_pod_info{namespace=\"$Namespace\"}) by (pod)) /1024/1024/1024\n",
"hide": false,
"legendFormat": "recommend",
"range": true,
"refId": "C"
}
],
"title": "Workload Pods Insight - Memory",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "Workload insight for CPU, Spec level",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"graph": false,
"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
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8
},
"id": 6,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "avg(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on (replicaset) group_right() label_replace(max(kube_pod_info{namespace=\"$Namespace\", created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on (pod) group_right() sum(irate(container_cpu_usage_seconds_total{namespace=\"$Namespace\", container!=\"sandbox\", container!=\"\"}[3m])) by (pod))",
"legendFormat": "usage",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "avg(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on (replicaset) group_right() label_replace(max(kube_pod_info{namespace=\"$Namespace\", created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on (pod) group_right() sum(kube_pod_container_resource_requests{namespace=\"$Namespace\",unit=\"core\",resource=\"cpu\"}) by (pod))",
"hide": false,
"legendFormat": "request",
"range": true,
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(crane_analysis_resource_recommendation{namespace=\"$Namespace\",owner_kind=\"$WorkloadType\",resource=\"cpu\",owner_name=~\"$Workload\"})\n",
"hide": false,
"legendFormat": "recommend",
"range": true,
"refId": "C"
}
],
"title": "Workload Spec Insight - CPU",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "Workload Insight, Spec level.",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"graph": false,
"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
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8
},
"id": 5,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "avg(max(kube_replicaset_owner{owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on(replicaset) group_right() label_replace(max(kube_pod_info{created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on(pod) group_right() sum(container_memory_working_set_bytes{container!=\"sandbox\", container!=\"\"}/1024/1024/1024) by (pod))",
"legendFormat": "usage",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "avg(max(kube_replicaset_owner{namespace=\"$Namespace\", owner_kind=\"$WorkloadType\", owner_name=\"$Workload\"}) by (replicaset) * on(replicaset) group_right() label_replace(max(kube_pod_info{created_by_kind=\"ReplicaSet\"}) by (pod, created_by_name), \"replicaset\", \"$1\", \"created_by_name\", \"(.+)\") * on(pod) group_right() sum(kube_pod_container_resource_requests{unit=\"byte\",resource=\"memory\"}/1024/1024/1024) by (pod))",
"hide": false,
"legendFormat": "request",
"range": true,
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(crane_analysis_resource_recommendation{namespace=\"$Namespace\",owner_kind=\"$WorkloadType\",resource=\"memory\",owner_name=~\"$Workload\"})\n/1024/1024/1024 ",
"hide": false,
"legendFormat": "recommend",
"range": true,
"refId": "C"
}
],
"title": "Workload Spec Insight - Memory(GB)",
"type": "timeseries"
}
],
"refresh": "",
"revision": 1,
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"definition": "label_values(namespace)",
"hide": 0,
"includeAll": false,
"label": "Namespace",
"multi": false,
"name": "Namespace",
"options": [],
"query": {
"query": "label_values(namespace)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"definition": "label_values(crane_analysis_resource_recommendation{namespace=~\"$Namespace\"},owner_kind)",
"hide": 0,
"includeAll": false,
"label": "WorkloadType",
"multi": false,
"name": "WorkloadType",
"options": [],
"query": {
"query": "label_values(crane_analysis_resource_recommendation{namespace=~\"$Namespace\"},owner_kind)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"current": {},
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"definition": "label_values(crane_analysis_resource_recommendation{namespace=~\"$Namespace\",owner_kind=\"$WorkloadType\"},owner_name)",
"hide": 0,
"includeAll": false,
"label": "Workload",
"multi": false,
"name": "Workload",
"options": [],
"query": {
"query": "label_values(crane_analysis_resource_recommendation{namespace=~\"$Namespace\",owner_kind=\"$WorkloadType\"},owner_name)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Workload Insight",
"uid": "workload-insight",
"version": 18,
"weekStart": ""
}