You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/10/21 08:43:57 UTC

[GitHub] [apisix] membphis commented on a change in pull request #2455: feat: new plugin, api breaker

membphis commented on a change in pull request #2455:
URL: https://github.com/apache/apisix/pull/2455#discussion_r509098358



##########
File path: apisix/plugins/api-breaker.lua
##########
@@ -0,0 +1,248 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local core = require("apisix.core")
+local plugin_name = "api-breaker"
+local ngx = ngx
+local math = math
+local error = error
+local ipairs = ipairs
+
+local shared_buffer = ngx.shared['plugin-'.. plugin_name]
+if not shared_buffer then
+    error("failed to get ngx.shared dict when load plugin " .. plugin_name)
+end
+
+
+local schema = {
+    type = "object",
+    properties = {
+        break_response_code = {
+            type = "integer",
+            minimum = 200,
+            maximum = 599,
+        },
+        max_breaker_sec = {
+            type = "integer",
+            minimum = 3,
+            default = 300,
+        },
+        unhealthy = {
+            type = "object",
+            properties = {
+                http_statuses = {
+                    type = "array",
+                    minItems = 1,
+                    items = {
+                        type = "integer",
+                        minimum = 500,
+                        maximum = 599,
+                    },
+                    uniqueItems = true,
+                    default = {500}
+                },
+                failures = {
+                    type = "integer",
+                    minimum = 1,
+                    default = 3,
+                }
+            },
+            default = {http_statuses = {500}, failures = 3}
+        },
+        healthy = {
+            type = "object",
+            properties = {
+                http_statuses = {
+                    type = "array",
+                    minItems = 1,
+                    items = {
+                        type = "integer",
+                        minimum = 200,
+                        maximum = 499,
+                    },
+                    uniqueItems = true,
+                    default = {200}
+                },
+                successes = {
+                    type = "integer",
+                    minimum = 1,
+                    default = 3,
+                }
+            },
+            default = {http_statuses = {200}, successes = 3}
+        }
+    },
+    required = {"break_response_code"},
+}
+
+
+-- todo: we can move this into `core.talbe`

Review comment:
       related issue: https://github.com/apache/apisix/issues/2486




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org