Skip to content

Commit 80a99aa

Browse files
author
tianhao53
committed
fix: remove these irrelevant formatting changes.
1 parent 535a2b0 commit 80a99aa

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

apisix/plugins/api-breaker.lua

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -269,60 +269,60 @@ end
269269

270270
-- Circuit breaker state management functions
271271
local function get_circuit_breaker_state(ctx)
272-
local state_key = gen_state_key(ctx)
273-
local state, err = shared_buffer:get(state_key)
274-
if err then
275-
core.log.warn("failed to get circuit breaker state: ", err)
276-
return CLOSED
277-
end
278-
return state or CLOSED
272+
local state_key = gen_state_key(ctx)
273+
local state, err = shared_buffer:get(state_key)
274+
if err then
275+
core.log.warn("failed to get circuit breaker state: ", err)
276+
return CLOSED
277+
end
278+
return state or CLOSED
279279
end
280280

281281
local function set_circuit_breaker_state(ctx, state)
282-
local state_key = gen_state_key(ctx)
283-
local last_change_key = gen_last_state_change_key(ctx)
284-
local current_time = ngx.time()
282+
local state_key = gen_state_key(ctx)
283+
local last_change_key = gen_last_state_change_key(ctx)
284+
local current_time = ngx.time()
285285

286-
shared_buffer:set(state_key, state)
287-
shared_buffer:set(last_change_key, current_time)
286+
shared_buffer:set(state_key, state)
287+
shared_buffer:set(last_change_key, current_time)
288288

289-
core.log.info("Circuit breaker state changed to: ", state, " at: ", current_time)
289+
core.log.info("Circuit breaker state changed to: ", state, " at: ", current_time)
290290
end
291291

292292
-- Sliding window management
293293
local function reset_sliding_window(ctx, current_time, window_size)
294-
local window_start_key = gen_window_start_time_key(ctx)
295-
local total_requests_key = gen_total_requests_key(ctx)
296-
local unhealthy_key = gen_unhealthy_key(ctx)
294+
local window_start_key = gen_window_start_time_key(ctx)
295+
local total_requests_key = gen_total_requests_key(ctx)
296+
local unhealthy_key = gen_unhealthy_key(ctx)
297297

298-
shared_buffer:set(window_start_key, current_time)
299-
shared_buffer:set(total_requests_key, 0)
300-
shared_buffer:set(unhealthy_key, 0)
298+
shared_buffer:set(window_start_key, current_time)
299+
shared_buffer:set(total_requests_key, 0)
300+
shared_buffer:set(unhealthy_key, 0)
301301

302-
-- Reset circuit breaker state to CLOSED when sliding window resets
303-
shared_buffer:delete(gen_state_key(ctx))
304-
shared_buffer:delete(gen_last_state_change_key(ctx))
305-
shared_buffer:delete(gen_half_open_calls_key(ctx))
306-
shared_buffer:delete(gen_half_open_success_key(ctx))
302+
-- Reset circuit breaker state to CLOSED when sliding window resets
303+
shared_buffer:delete(gen_state_key(ctx))
304+
shared_buffer:delete(gen_last_state_change_key(ctx))
305+
shared_buffer:delete(gen_half_open_calls_key(ctx))
306+
shared_buffer:delete(gen_half_open_success_key(ctx))
307307

308-
core.log.info("Sliding window reset at: ", current_time, " window size: ", window_size, "s")
308+
core.log.info("Sliding window reset at: ", current_time, " window size: ", window_size, "s")
309309
end
310310

311311
local function check_and_reset_window(ctx, conf)
312-
local current_time = ngx.time()
313-
local window_start_key = gen_window_start_time_key(ctx)
314-
local window_start_time, err = shared_buffer:get(window_start_key)
312+
local current_time = ngx.time()
313+
local window_start_key = gen_window_start_time_key(ctx)
314+
local window_start_time, err = shared_buffer:get(window_start_key)
315315

316-
if err then
317-
core.log.warn("failed to get window start time: ", err)
318-
return
319-
end
316+
if err then
317+
core.log.warn("failed to get window start time: ", err)
318+
return
319+
end
320320

321-
local window_size = conf.unhealthy.sliding_window_size or 300
321+
local window_size = conf.unhealthy.sliding_window_size or 300
322322

323-
if not window_start_time or (current_time - window_start_time) >= window_size then
324-
reset_sliding_window(ctx, current_time, window_size)
325-
end
323+
if not window_start_time or (current_time - window_start_time) >= window_size then
324+
reset_sliding_window(ctx, current_time, window_size)
325+
end
326326
end
327327

328328
-- Count-based circuit breaker (based on latest APISIX version)
@@ -487,12 +487,12 @@ local function ratio_based_access(conf, ctx)
487487
end
488488

489489
function _M.access(conf, ctx)
490-
if conf.policy == "unhealthy-ratio" then
491-
return ratio_based_access(conf, ctx)
492-
else
493-
-- Default to count-based (unhealthy-count)
494-
return count_based_access(conf, ctx)
495-
end
490+
if conf.policy == "unhealthy-ratio" then
491+
return ratio_based_access(conf, ctx)
492+
else
493+
-- Default to count-based (unhealthy-count)
494+
return count_based_access(conf, ctx)
495+
end
496496
end
497497

498498
-- Count-based logging (based on latest APISIX version)
@@ -549,7 +549,7 @@ local function count_based_log(conf, ctx)
549549
local healthy_count, err = shared_buffer:incr(healthy_key, 1, 0)
550550
if err then
551551
core.log.warn("failed to `incr` healthy_key: ", healthy_key,
552-
" err: ", err)
552+
" err: ", err)
553553
end
554554

555555
-- clear related status
@@ -659,12 +659,12 @@ local function ratio_based_log(conf, ctx)
659659
end
660660

661661
function _M.log(conf, ctx)
662-
if conf.policy == "unhealthy-ratio" then
663-
ratio_based_log(conf, ctx)
664-
else
665-
-- Default to count-based (unhealthy-count)
666-
count_based_log(conf, ctx)
667-
end
662+
if conf.policy == "unhealthy-ratio" then
663+
ratio_based_log(conf, ctx)
664+
else
665+
-- Default to count-based (unhealthy-count)
666+
count_based_log(conf, ctx)
667+
end
668668
end
669669

670670
return _M

t/lib/server.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ function _M.wolf_rbac_access_check()
324324
username="admin", id="100"} }}))
325325
elseif resName == '/hello/500' then
326326
ngx.status = 500
327-
ngx.say(json_encode({ok=false, reason="ERR_SERVER_ERROR" }))
327+
ngx.say(json_encode({ok=false, reason="ERR_SERVER_ERROR"}))
328328
elseif resName == '/hello/401' then
329329
ngx.status = 401
330330
ngx.say(json_encode({ok=false, reason="ERR_TOKEN_INVALID"}))
@@ -646,7 +646,7 @@ function _M.google_secret_apisix_jack()
646646
data = "eyJrZXkiOiJ2YWx1ZSJ9",
647647
dataCrc32c = "2296192492"
648648
}
649-
}
649+
}
650650

651651
ngx.status = 200
652652
ngx.say(json_encode(response))
@@ -695,7 +695,7 @@ function _M.google_secret_apisix_error_jack()
695695
data = "eyJrZXkiOiJ2YWx1ZSJ9",
696696
dataCrc32c = "2296192492"
697697
}
698-
}
698+
}
699699

700700
ngx.status = 200
701701
ngx.say(json_encode(response))
@@ -744,7 +744,7 @@ function _M.google_secret_apisix_mysql()
744744
data = "c2VjcmV0",
745745
dataCrc32c = "0xB03C4D4D"
746746
}
747-
}
747+
}
748748

749749
ngx.status = 200
750750
ngx.say(json_encode(response))

0 commit comments

Comments
 (0)