import { useCircuitBreakerConfig, useUpdateCircuitBreakerConfig, } from "@/lib/query/failover"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { useState, useEffect } from "react"; import { toast } from "sonner"; /** * 熔断器配置面板 * 允许用户调整熔断器参数 */ export function CircuitBreakerConfigPanel() { const { data: config, isLoading } = useCircuitBreakerConfig(); const updateConfig = useUpdateCircuitBreakerConfig(); const [formData, setFormData] = useState({ failureThreshold: 5, successThreshold: 2, timeoutSeconds: 60, errorRateThreshold: 0.5, minRequests: 10, }); // 当配置加载完成时更新表单数据 useEffect(() => { if (config) { setFormData(config); } }, [config]); const handleSave = async () => { try { await updateConfig.mutateAsync(formData); toast.success("熔断器配置已保存", { closeButton: true }); } catch (error) { toast.error("保存失败: " + String(error)); } }; const handleReset = () => { if (config) { setFormData(config); } }; if (isLoading) { return
调整熔断器参数以控制故障检测和恢复行为
连续失败多少次后打开熔断器
熔断器打开后多久尝试恢复(半开状态)
半开状态下成功多少次后关闭熔断器
错误率超过此值时打开熔断器
计算错误率前的最小请求数