diff --git a/apisix/discovery/eureka-filter/init.lua b/apisix/discovery/eureka-filter/init.lua new file mode 100644 index 000000000000..d8be918a659f --- /dev/null +++ b/apisix/discovery/eureka-filter/init.lua @@ -0,0 +1,44 @@ +local eureka = require("apisix.discovery.eureka") +local core = require("apisix.core") +local log = core.log + +local _M = { + version = 0.1 +} + +function _M.init_worker() + eureka.init_worker() +end + +function _M.nodes(service_name, discovery_args) + local nodes = eureka.nodes(service_name) + if not nodes then + return nil + end + + if not discovery_args or not discovery_args.zone then + return nodes + end + + local zone = discovery_args.zone + local filtered_nodes = {} + + for _, node in ipairs(nodes) do + if node.metadata and node.metadata.zone == zone then + core.table.insert(filtered_nodes, node) + end + end + + if #filtered_nodes == 0 then + log.warn("no nodes found for service [", service_name, "] in zone [", zone, "]") + return nodes + end + + return filtered_nodes +end + +function _M.dump_data() + return eureka.dump_data() +end + +return _M diff --git a/apisix/discovery/eureka-filter/schema.lua b/apisix/discovery/eureka-filter/schema.lua new file mode 100644 index 000000000000..184ec417e6ef --- /dev/null +++ b/apisix/discovery/eureka-filter/schema.lua @@ -0,0 +1,40 @@ +-- +-- 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. +-- +return { + type = "object", + properties = { + host = { + type = "array", + minItems = 1, + items = { + type = "string", + }, + }, + fetch_interval = {type = "integer", minimum = 1, default = 30}, + prefix = {type = "string"}, + weight = {type = "integer", minimum = 0}, + timeout = { + type = "object", + properties = { + connect = {type = "integer", minimum = 1, default = 2000}, + send = {type = "integer", minimum = 1, default = 2000}, + read = {type = "integer", minimum = 1, default = 5000}, + } + }, + }, + required = {"host"} +} \ No newline at end of file