forked from polarismesh/specification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circuitbreaker.proto
334 lines (297 loc) · 10 KB
/
circuitbreaker.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
syntax = "proto3";
package v1;
import "google/protobuf/wrappers.proto";
import "google/protobuf/duration.proto";
import "model.proto";
option go_package = "github.com/polarismesh/specification/source/go/api/v1/fault_tolerance";
option java_package = "com.tencent.polaris.specification.api.v1.fault.tolerance";
option java_outer_classname = "CircuitBreakerProto";
//单个熔断规则定义
message CircuitBreaker {
// deprecated
google.protobuf.StringValue id = 1;
// 规则版本
// deprecated
google.protobuf.StringValue version = 2;
// 规则名
// deprecated
google.protobuf.StringValue name = 3;
// 规则命名空间
// deprecated
google.protobuf.StringValue namespace = 4;
// 规则所属服务
google.protobuf.StringValue service = 5;
google.protobuf.StringValue service_namespace = 6;
//熔断规则可以分为被调规则和主调规则
//被调规则针对所有的指定主调生效,假如不指定则对所有的主调生效
//主调规则为当前主调方的规则,假如不指定则针对所有被调生效
// deprecated
repeated CbRule inbounds = 7;
// deprecated
repeated CbRule outbounds = 8;
// deprecated
google.protobuf.StringValue token = 9;
// deprecated
google.protobuf.StringValue owners = 10;
// 业务
// deprecated
google.protobuf.StringValue business = 11;
// 部门
// deprecated
google.protobuf.StringValue department = 12;
// 规则描述
// deprecated
google.protobuf.StringValue comment = 13;
// deprecated
google.protobuf.StringValue ctime = 14;
// deprecated
google.protobuf.StringValue mtime = 15;
google.protobuf.StringValue revision = 16;
reserved 17 to 20;
// circuitbreaker rules for current service
repeated CircuitBreakerRule rules = 21;
}
// 主调匹配规则
message SourceMatcher {
// 主调命名空间以及服务名,可以为*,代表全匹配
google.protobuf.StringValue service = 1;
google.protobuf.StringValue namespace = 2;
// 可选,主调业务标签,用于匹配是否使用该熔断规则,可放置用户的接口信息等
map<string, MatchString> labels = 3;
}
// 熔断恢复配置
message RecoverConfig {
// 触发熔断后到半开状态之间的等待间隔
google.protobuf.Duration sleepWindow = 1;
// 半开后,最多重试多少次恢复
google.protobuf.UInt32Value maxRetryAfterHalfOpen = 2;
// 半开后放量的最大百分比
repeated google.protobuf.UInt32Value requestRateAfterHalfOpen = 3;
// 熔断器半开到关闭所必须的最少成功率,默认100%
google.protobuf.UInt32Value successRateToClose = 4;
// 半开后最大放量数(用户不配置最大百分比时默认使用该配置)
google.protobuf.UInt32Value requestCountAfterHalfOpen = 5;
//主动探测配置
enum OutlierDetectWhen {
//不开启监控探测
NEVER = 0;
//只有在熔断恢复时才开启健康探测
ON_RECOVER = 1;
//一直开启健康探测
ALWAYS = 2;
}
OutlierDetectWhen outlierDetectWhen = 6;
}
// 熔断策略
message CbPolicy {
// 错误率熔断配置
message ErrRateConfig {
//是否启用错误率配置
google.protobuf.BoolValue enable = 1;
// 触发错误率熔断的最低请求阈值
google.protobuf.UInt32Value requestVolumeThreshold = 2;
// 可选。触发保持状态的错误率阈值,假如不配置,则默认不会进入Preserved状态
google.protobuf.UInt32Value errorRateToPreserved = 3;
// 触发熔断的错误率阈值
google.protobuf.UInt32Value errorRateToOpen = 4;
//错误码相关特定配置
message SpecialConfig {
// 熔断关心的错误类型,用户可以自己定义
google.protobuf.StringValue type = 1;
repeated google.protobuf.Int64Value errorCodes = 2;
google.protobuf.UInt32Value errorRateToPreserved = 3;
google.protobuf.UInt32Value errorRateToOpen = 4;
}
repeated SpecialConfig specials = 5;
}
ErrRateConfig errorRate = 1;
// 慢调用率熔断策略配置
message SlowRateConfig {
// 是否启用慢调用率配置
google.protobuf.BoolValue enable = 1;
// 最大响应时间,超过该时间属于慢调用请求
google.protobuf.Duration maxRt = 2;
// 可选。触发保持状态的超时率阈值,假如不配置,则默认不会进入Preserved状态
google.protobuf.UInt32Value slowRateToPreserved = 3;
// 触发熔断的超时率阈值
google.protobuf.UInt32Value slowRateToOpen = 4;
}
SlowRateConfig slowRate = 2;
// 熔断的决策周期,多久触发一次熔断决策
google.protobuf.Duration judgeDuration = 3;
//最大熔断比例,超过多少比例后不会继续熔断
google.protobuf.UInt32Value maxEjectionPercent = 4;
//连续错误数熔断配置
message ConsecutiveErrConfig {
// 是否启用连续错误数配置
google.protobuf.BoolValue enable = 1;
// 连续错误数阈值,进入Preserved状态
google.protobuf.UInt32Value consecutiveErrorToPreserved = 2;
// 连续错误数阈值,进入Open状态
google.protobuf.UInt32Value consecutiveErrorToOpen = 3;
}
ConsecutiveErrConfig consecutive = 5;
}
// 目标set的规则
message DestinationSet {
// 被调命名空间以及服务名,可以为*,代表全匹配
google.protobuf.StringValue service = 1;
google.protobuf.StringValue namespace = 2;
// 可选,SUBSET标识
map<string, MatchString> metadata = 3;
// 需要进行熔断的资源
// 支持SUBSET(子集群),以及INSTANCE(单个实例),默认为SUBSET
enum Resource {
// 针对实例分组进行熔断
SUBSET = 0;
// 针对实例进行熔断
INSTANCE = 1;
}
Resource resource = 4;
// 熔断决策类型,支持GLOBAL(分布式决策)以及LOCAL(本地决策),默认GLOBAL
// 当指定为GLOBAL时,则会定期上报统计数据并根据汇总数据进行熔断决策
enum Type {
GLOBAL = 0;
LOCAL = 1;
}
Type type = 5;
//熔断范围,是否扩散针对相同服务下所有接口进行熔断
enum Scope {
//触发熔断条件,扩散熔断所有接口
ALL = 0;
//触发熔断条件,只熔断当前接口
CURRENT = 1;
}
Scope scope = 6;
// 熔断数据度量周期
// 所有的阈值指标按此周期进行统计
google.protobuf.Duration metricWindow = 7;
// 熔断数据统计精度,决定数据度量的最小周期
// 度量滑窗的步长=window/precision
google.protobuf.UInt32Value metricPrecision = 8;
// 熔断数据上报周期,对分布式熔断有效
google.protobuf.Duration updateInterval = 9;
// 触发熔断后恢复配置
RecoverConfig recover = 10;
// 熔断策略
CbPolicy policy = 11;
// 被调的接口信息,指定哪些接口会使用该规则
MatchString method = 12;
// 返回码,指定哪些返回码会使用该规则
repeated google.protobuf.Int64Value errorCodes = 13;
}
// 具体熔断规则
message CbRule {
// 如果匹配Source规则,按照Destination进行熔断
// 多个Source之间的关系为或
repeated SourceMatcher sources = 1;
repeated DestinationSet destinations = 2;
}
message RuleMatcher {
message SourceService {
string service = 1;
string namespace = 2;
}
message DestinationService {
string service = 1;
string namespace = 2;
MatchString method = 3;
}
SourceService source = 1;
DestinationService destination = 2;
}
// circuitbreaking level
enum Level {
UNKNOWN = 0;
// service level circuitbreaking
SERVICE = 1;
// method level circuitbreaking
METHOD = 2;
// group level circuitbreaking
GROUP = 3;
// instance level circuitbreaking
INSTANCE = 4;
}
// new specific rule for circuitbreaker config
message CircuitBreakerRule {
string id = 1;
// rule name
string name = 2;
// namespace of rule
string namespace = 3;
// enable this router
bool enable = 4;
// revision routing version
string revision = 5;
// ctime create time of the rules
string ctime = 6;
// mtime modify time of the rules
string mtime = 7;
// etime enable time of the rules
string etime = 8;
// description simple description rules
string description = 9;
// reserve for metadata
reserved 10 to 20;
// the circuitbreaking level
Level level = 21;
// match condition for this rule
RuleMatcher rule_matcher = 22;
// error conditions to judge an invocation as an error
repeated ErrorCondition error_conditions = 23;
// trigger condition to trigger circuitbreaking
repeated TriggerCondition trigger_condition = 24;
// the maximum % of an upstream cluster that can be ejected
uint32 max_ejection_percent = 25;
// recover condition to make resource open to close
RecoverCondition recoverCondition = 26;
// fault detection enable config
FaultDetectConfig faultDetectConfig = 27;
// fall back configuration
FallbackConfig fallbackConfig = 28;
}
// the condition to judge an input invocation as an error
message ErrorCondition {
enum InputType {
UNKNOWN = 0;
RET_CODE = 1;
DELAY = 2;
}
InputType input_type = 1;
MatchString condition = 2;
}
// the error condition to trigger circuitbreaking
message TriggerCondition {
enum TriggerType {
UNKNOWN = 0;
ERROR_RATE = 1;
CONSECUTIVE_ERROR = 2;
}
TriggerType trigger_type = 1;
uint32 error_count = 2;
uint32 error_percent = 3;
uint32 interval = 4;
uint32 minimum_request = 5;
}
message RecoverCondition {
// seconds from open to half-open
uint32 sleep_window = 1;
// consecutive success request to recover
uint32 consecutiveSuccess = 2;
}
message FaultDetectConfig {
bool enable = 1;
}
message FallbackConfig {
bool enable = 1;
FallbackResponse response = 2;
}
message FallbackResponse {
int32 code = 1;
message MessageHeader {
string key = 1;
string value = 2;
}
repeated MessageHeader headers = 2;
string body = 3;
}