feat: initialize parent-bff service with full core features

add complete parent-bff implementation including:
- GraphQL endpoint with depth/cost validation
- ChildGuard越权校验 with redis cache and singleflight
- parallel orchestration with partial failure fallback
- three-level cache fallback strategy (Redis + LRU + downstream)
- Kafka consumer for cache invalidation and notification push
- opossum circuit breaker for downstream services
- Prometheus metrics and SLO alerts
- Helm chart for k8s deployment with multi-environment configs
- Grafana dashboard for observability
- complete unit and integration tests
This commit is contained in:
SpecialX
2026-07-10 18:49:06 +08:00
parent a7d8f92227
commit 2229309a1e
88 changed files with 11221 additions and 0 deletions

View File

@@ -0,0 +1,967 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "Edu 平台 parent-bff BFF 层 - SLO 监控 / 下游 gRPC / 缓存 / Kafka / 熔断器",
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"id": null,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "line"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 0.2
}
]
},
"unit": "s"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"calcs": ["mean", "max", "lastNotNull"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "histogram_quantile(0.95, sum(rate(parent_bff_graphql_duration_seconds_bucket[5m])) by (le, operation))",
"legendFormat": "{{operation}} P95",
"refId": "A"
}
],
"title": "GraphQL P95 延迟SLO < 200ms",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "line"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 0.001
}
]
},
"unit": "percentunit"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(parent_bff_graphql_requests_total{status=\"error\"}[5m])) by (operation) / sum(rate(parent_bff_graphql_requests_total[5m])) by (operation)",
"legendFormat": "{{operation}} 错误率",
"refId": "A"
}
],
"title": "GraphQL 错误率SLO < 0.1%",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 0.999
}
]
},
"unit": "percentunit"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 0,
"y": 8
},
"id": 3,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "1 - (sum(rate(parent_bff_graphql_requests_total{status=\"error\"}[5m])) / sum(rate(parent_bff_graphql_requests_total[5m])))",
"legendFormat": "可用性",
"refId": "A"
}
],
"title": "整体可用性SLO > 99.9%",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [
{
"options": {
"0": {
"color": "green",
"index": 0,
"text": "CLOSED"
},
"1": {
"color": "red",
"index": 1,
"text": "OPEN"
}
},
"type": "value"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 1
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 6,
"y": 8
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "max(parent_bff_circuit_state{state=\"open\"}) by (service)",
"legendFormat": "{{service}}",
"refId": "A"
}
],
"title": "熔断器状态0=CLOSED, 1=OPEN",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "yellow",
"value": 0.5
},
{
"color": "green",
"value": 0.8
}
]
},
"unit": "percentunit"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 12,
"y": 8
},
"id": 5,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(parent_bff_cache_hits_total[5m])) / (sum(rate(parent_bff_cache_hits_total[5m])) + sum(rate(parent_bff_cache_misses_total[5m])))",
"legendFormat": "命中率",
"refId": "A"
}
],
"title": "缓存命中率",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 100
}
]
},
"unit": "cps"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 18,
"y": 8
},
"id": 6,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "auto"
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(parent_bff_child_guard_blocks_total[5m]))",
"legendFormat": "越权拦截",
"refId": "A"
}
],
"title": "ChildGuard 越权拦截",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 12
},
"id": 7,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(parent_bff_downstream_calls_total[5m])) by (service, rpc)",
"legendFormat": "{{service}}.{{rpc}}",
"refId": "A"
}
],
"title": "下游 gRPC 调用 QPS按 service.rpc",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "s"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 12
},
"id": 8,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "histogram_quantile(0.95, sum(rate(parent_bff_downstream_duration_seconds_bucket[5m])) by (le, service, rpc))",
"legendFormat": "{{service}}.{{rpc}} P95",
"refId": "A"
}
],
"title": "下游 gRPC P95 延迟(按 service.rpc",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "bars",
"fillOpacity": 50,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "normal"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 20
},
"id": 9,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(parent_bff_event_consumed_total[5m])) by (topic, event_type)",
"legendFormat": "{{topic}} / {{event_type}}",
"refId": "A"
}
],
"title": "Kafka 事件消费速率(按 topic / event_type",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": [
{
"matcher": {
"id": "byRegexp",
"options": "/failure.*/"
},
"properties": [
{
"id": "color",
"value": {
"mode": "fixed",
"fixedColor": "red"
}
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": "/success.*/"
},
"properties": [
{
"id": "color",
"value": {
"mode": "fixed",
"fixedColor": "green"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 20
},
"id": 10,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(parent_bff_event_pushed_total[5m])) by (push_status)",
"legendFormat": "push-{{push_status}}",
"refId": "A"
}
],
"title": "push-gateway 推送速率(按状态)",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 28
},
"id": 11,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"expr": "sum(rate(parent_bff_graphql_requests_total[5m])) by (operation, status)",
"legendFormat": "{{operation}} / {{status}}",
"refId": "A"
}
],
"title": "GraphQL 请求 QPS按 operation / status",
"type": "timeseries"
}
],
"refresh": "30s",
"schemaVersion": 39,
"style": "dark",
"tags": ["edu", "parent-bff", "slo"],
"templating": {
"list": []
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "parent-bff SLO 监控面板",
"uid": "edu-parent-bff-slo",
"version": 1,
"weekStart": ""
}

View File

@@ -0,0 +1,13 @@
apiVersion: v2
name: parent-bff
description: parent-bff 服务级 Helm Chart家长端 BFF 聚合层GraphQL 端口 3010
type: application
version: 0.1.0
appVersion: "0.1.0"
keywords:
- edu
- bff
- parent
- graphql
maintainers:
- name: edu-arch

View File

@@ -0,0 +1,29 @@
{{- define "parent-bff.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "parent-bff.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "parent-bff.labels" -}}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
{{ include "parent-bff.selectorLabels" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: edu-platform
app.kubernetes.io/component: bff
{{- end -}}
{{- define "parent-bff.selectorLabels" -}}
app.kubernetes.io/name: {{ include "parent-bff.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

View File

@@ -0,0 +1,13 @@
{{- if .Values.configMap.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "parent-bff.name" . }}-config
namespace: {{ .Values.namespace }}
labels:
{{- include "parent-bff.labels" . | nindent 4 }}
data:
{{- range $k, $v := .Values.configMap.data }}
{{ $k }}: {{ $v | quote }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,94 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "parent-bff.name" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "parent-bff.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "parent-bff.selectorLabels" . | nindent 6 }}
strategy:
type: {{ .Values.strategy.type }}
rollingUpdate:
maxSurge: {{ .Values.strategy.maxSurge }}
maxUnavailable: {{ .Values.strategy.maxUnavailable }}
template:
metadata:
labels:
{{- include "parent-bff.selectorLabels" . | nindent 8 }}
app.kubernetes.io/part-of: edu-platform
app.kubernetes.io/component: bff
{{- if .Values.metrics.enabled }}
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.metrics.port | quote }}
prometheus.io/path: {{ .Values.metrics.path | quote }}
{{- end }}
spec:
{{- if .Values.podAntiAffinity.enabled }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
{{- include "parent-bff.selectorLabels" . | nindent 20 }}
topologyKey: {{ .Values.podAntiAffinity.topologyKey }}
{{- end }}
containers:
- name: {{ include "parent-bff.name" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.targetPort }}
protocol: TCP
livenessProbe:
httpGet:
path: {{ .Values.probes.liveness.path }}
port: http
initialDelaySeconds: {{ .Values.probes.liveness.initialDelaySeconds }}
periodSeconds: {{ .Values.probes.liveness.periodSeconds }}
timeoutSeconds: {{ .Values.probes.liveness.timeoutSeconds }}
failureThreshold: {{ .Values.probes.liveness.failureThreshold }}
readinessProbe:
httpGet:
path: {{ .Values.probes.readiness.path }}
port: http
initialDelaySeconds: {{ .Values.probes.readiness.initialDelaySeconds }}
periodSeconds: {{ .Values.probes.readiness.periodSeconds }}
timeoutSeconds: {{ .Values.probes.readiness.timeoutSeconds }}
failureThreshold: {{ .Values.probes.readiness.failureThreshold }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
{{- if .Values.configMap.enabled }}
{{- range $k, $v := .Values.configMap.data }}
- name: {{ $k }}
valueFrom:
configMapKeyRef:
name: {{ include "parent-bff.name" $ }}-config
key: {{ $k }}
{{- end }}
{{- end }}
{{- range $secret := .Values.secretRefs }}
{{- range $key := $secret.keys }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ $secret.name }}
key: {{ $key }}
{{- end }}
{{- end }}
{{- if .Values.kafka.enabled }}
- name: KAFKA_BROKERS
value: {{ .Values.kafka.brokers | quote }}
- name: KAFKA_CONSUMER_GROUP_ID
value: {{ .Values.kafka.consumerGroupId | quote }}
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}

View File

@@ -0,0 +1,29 @@
{{- if .Values.hpa.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "parent-bff.name" . }}-hpa
namespace: {{ .Values.namespace }}
labels:
{{- include "parent-bff.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "parent-bff.name" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
{{- end }}

View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "parent-bff.name" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "parent-bff.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
selector:
{{- include "parent-bff.selectorLabels" . | nindent 4 }}
ports:
- name: http
port: {{ .Values.service.port }}
targetPort: http
protocol: TCP

View File

@@ -0,0 +1,22 @@
# parent-bff 开发环境
replicaCount: 1
image:
tag: dev
configMap:
data:
NODE_ENV: development
LOG_LEVEL: debug
DEV_MODE: "true"
CORS_ORIGINS: http://localhost:4002
hpa:
enabled: false
podAntiAffinity:
enabled: false
kafka:
enabled: false

View File

@@ -0,0 +1,35 @@
# parent-bff 生产环境
replicaCount: 3
image:
tag: prod
configMap:
data:
NODE_ENV: production
LOG_LEVEL: info
DEV_MODE: "false"
CORS_ORIGINS: https://parent.edu.example.com
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
cpu: 2000m
memory: 2Gi
hpa:
enabled: true
minReplicas: 3
maxReplicas: 10
targetCPUUtilizationPercentage: 70
targetMemoryUtilizationPercentage: 80
podAntiAffinity:
enabled: true
kafka:
enabled: true
brokers: kafka.edu-system.svc.cluster.local:9092

View File

@@ -0,0 +1,22 @@
# parent-bff 预发布环境
replicaCount: 2
image:
tag: staging
configMap:
data:
NODE_ENV: production
LOG_LEVEL: info
DEV_MODE: "false"
CORS_ORIGINS: https://parent-staging.edu.example.com
hpa:
enabled: true
minReplicas: 2
maxReplicas: 5
kafka:
enabled: true
brokers: kafka.edu-system.svc.cluster.local:9092

View File

@@ -0,0 +1,104 @@
# parent-bff 服务默认值
# 副本数(生产建议 ≥ 2
replicaCount: 2
image:
repository: edu/parent-bff
tag: latest # 生产请固定 tag
pullPolicy: IfNotPresent
# 服务端口GraphQL :3010
service:
type: ClusterIP
port: 3010
targetPort: 3010
# 命名空间
namespace: edu-services
# 探针配置
probes:
liveness:
path: /healthz
initialDelaySeconds: 15
periodSeconds: 20
timeoutSeconds: 3
failureThreshold: 3
readiness:
path: /readyz
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 2
# 资源配额
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
cpu: 1000m
memory: 1Gi
# 滚动更新策略
strategy:
type: RollingUpdate
maxSurge: 1
maxUnavailable: 0
# Prometheus 指标采集
metrics:
enabled: true
port: 3010
path: /metrics
# 安全上下文
securityContext:
runAsNonRoot: true
runAsUser: 1000
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
# podAntiAffinity跨节点分布
podAntiAffinity:
enabled: true
topologyKey: kubernetes.io/hostname
# HPA
hpa:
enabled: true
minReplicas: 2
maxReplicas: 10
targetCPUUtilizationPercentage: 70
targetMemoryUtilizationPercentage: 80
# 服务级 ConfigMap非敏感配置
configMap:
enabled: true
data:
NODE_ENV: production
LOG_LEVEL: info
DEV_MODE: "false"
PORT: "3010"
CORS_ORIGINS: https://parent.edu.example.com
REDIS_URL: redis://edu-redis.edu-system.svc.cluster.local:6379
IAM_GRPC_TARGET: iam.edu-services.svc.cluster.local:50052
CORE_EDU_GRPC_TARGET: core-edu.edu-services.svc.cluster.local:50053
DATA_ANA_GRPC_TARGET: data-ana.edu-services.svc.cluster.local:50055
MSG_GRPC_TARGET: msg.edu-services.svc.cluster.local:50056
PUSH_GATEWAY_URL: http://push-gateway.edu-services.svc.cluster.local:8081
# 敏感配置
secretRefs:
- name: edu-platform-secret
keys:
- REDIS_PASSWORD
- OTEL_EXPORTER_OTLP_ENDPOINT
# Kafka
kafka:
enabled: false # P5+ 启用
brokers: ""
consumerGroupId: parent-bff

View File

@@ -120,3 +120,146 @@ groups:
annotations:
summary: "内存使用过高 {{ $labels.instance }}"
description: "节点 {{ $labels.instance }} 内存使用率超过 90%,持续 5 分钟。"
# ============================================================
# parent-bff SLO 告警规则P6.3
# SLO 目标P95 延迟 < 200ms / 错误率 < 0.1% / 可用性 > 99.9%
# 对齐 02-architecture-design.md §10.4
# 指标来源services/parent-bff/src/shared/observability/metrics.ts
# ============================================================
- name: parent-bff-slo
rules:
# parent-bff GraphQL P95 延迟 > 200ms
- alert: ParentBffHighLatencyP95
expr: |
histogram_quantile(0.95,
sum(rate(parent_bff_graphql_duration_seconds_bucket[5m])) by (le, operation))
> 0.2
for: 5m
labels:
severity: warning
category: slo
service: parent-bff
annotations:
summary: "parent-bff P95 延迟过高 {{ $labels.operation }}"
description: "parent-bff GraphQL 操作 {{ $labels.operation }} 的 P95 延迟超过 200ms SLO 目标,持续 5 分钟。当前值: {{ $value }}s"
# parent-bff GraphQL 错误率 > 0.1%
- alert: ParentBffHighErrorRate
expr: |
(sum(rate(parent_bff_graphql_requests_total{status="error"}[5m])) by (operation)
/ sum(rate(parent_bff_graphql_requests_total[5m])) by (operation))
> 0.001
for: 5m
labels:
severity: critical
category: slo
service: parent-bff
annotations:
summary: "parent-bff 错误率过高 {{ $labels.operation }}"
description: "parent-bff GraphQL 操作 {{ $labels.operation }} 的错误率超过 0.1% SLO 目标,持续 5 分钟。当前值: {{ $value | humanizePercentage }}"
# parent-bff 可用性 < 99.9%5 分钟窗口内成功请求比例)
- alert: ParentBffLowAvailability
expr: |
(1
- (sum(rate(parent_bff_graphql_requests_total{status="error"}[5m]))
/ sum(rate(parent_bff_graphql_requests_total[5m]))))
< 0.999
for: 5m
labels:
severity: critical
category: slo
service: parent-bff
annotations:
summary: "parent-bff 可用性低于 99.9%"
description: "parent-bff 整体可用性低于 99.9% SLO 目标,持续 5 分钟。当前可用性: {{ $value | humanizePercentage }}"
# parent-bff 熔断器打开
- alert: ParentBffCircuitBreakerOpen
expr: parent_bff_circuit_state{state="open"} == 1
for: 30s
labels:
severity: critical
category: slo
service: parent-bff
annotations:
summary: "parent-bff 熔断器打开 {{ $labels.service }}"
description: "parent-bff 下游服务 {{ $labels.service }} 的熔断器处于 open 状态,相关请求将被快速失败。"
# parent-bff 下游错误率 > 5%
- alert: ParentBffDownstreamHighErrorRate
expr: |
(sum(rate(parent_bff_downstream_errors_total[5m])) by (service)
/ sum(rate(parent_bff_downstream_calls_total[5m])) by (service))
> 0.05
for: 5m
labels:
severity: warning
category: slo
service: parent-bff
annotations:
summary: "parent-bff 下游 {{ $labels.service }} 错误率高"
description: "parent-bff 调用下游服务 {{ $labels.service }} 的错误率超过 5%,持续 5 分钟。当前值: {{ $value | humanizePercentage }}"
# parent-bff 缓存命中率低
- alert: ParentBffLowCacheHitRate
expr: |
(sum(rate(parent_bff_cache_hits_total[5m]))
/ (sum(rate(parent_bff_cache_hits_total[5m])) + sum(rate(parent_bff_cache_misses_total[5m]))))
< 0.5
for: 10m
labels:
severity: warning
category: slo
service: parent-bff
annotations:
summary: "parent-bff 缓存命中率低"
description: "parent-bff 缓存命中率低于 50%,持续 10 分钟。当前命中率: {{ $value | humanizePercentage }}"
# parent-bff Kafka 消费积压
- alert: ParentBffKafkaLag
expr: |
sum by (topic) (
rate(parent_bff_event_consumed_total[5m])
) < 1
and
sum by (topic) (
increase(parent_bff_event_consumed_total[1h])
) > 0
for: 15m
labels:
severity: warning
category: slo
service: parent-bff
annotations:
summary: "parent-bff Kafka 消费停滞 {{ $labels.topic }}"
description: "parent-bff 在 topic {{ $labels.topic }} 上的消费速率近 15 分钟为 0但近 1 小时内有消费记录,可能存在消费停滞。"
# parent-bff push-gateway 推送失败率 > 5%
- alert: ParentBffPushFailureRate
expr: |
(sum(rate(parent_bff_event_pushed_total{push_status="failure"}[5m]))
/ sum(rate(parent_bff_event_pushed_total[5m])))
> 0.05
for: 5m
labels:
severity: warning
category: slo
service: parent-bff
annotations:
summary: "parent-bff push-gateway 推送失败率高"
description: "parent-bff 调用 push-gateway 推送的失败率超过 5%,持续 5 分钟。当前值: {{ $value | humanizePercentage }}"
# parent-bff ChildGuard 越权拦截突增
- alert: ParentBffChildGuardBlocksSpike
expr: |
rate(parent_bff_child_guard_blocks_total[5m]) > 0.1
for: 5m
labels:
severity: warning
category: slo
service: parent-bff
annotations:
summary: "parent-bff ChildGuard 拦截次数突增"
description: "parent-bff ChildGuard 越权拦截速率 > 0.1 次/秒,持续 5 分钟。可能存在恶意探测或前端 bug。当前速率: {{ $value }}/s"