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 2022/01/29 03:12:14 UTC

[GitHub] [apisix] water1st opened a new pull request #6232: add consul support

water1st opened a new pull request #6232:
URL: https://github.com/apache/apisix/pull/6232


   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   add consul support
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the PR manners:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. If you need to resolve merge conflicts after the PR is reviewed, please merge master but do not rebase
   6. Use "request review" to notify the reviewer once you have resolved the review
   7. Only reviewer can click "Resolve conversation" to mark the reviewer's review resolved
   -->
   
   * [ ] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] spacewander commented on pull request #6232: feat(discovery): add consul support

Posted by GitBox <gi...@apache.org>.
spacewander commented on pull request #6232:
URL: https://github.com/apache/apisix/pull/6232#issuecomment-1025054831


   @bisakhmondal 
   Could you help @water1st if she/he has trouble with the test cases? Thanks!


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] github-actions[bot] commented on pull request #6232: feat(discovery): add consul support

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #6232:
URL: https://github.com/apache/apisix/pull/6232#issuecomment-1085724248


   This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] bisakhmondal commented on a change in pull request #6232: feat(discovery): add consul support

Posted by GitBox <gi...@apache.org>.
bisakhmondal commented on a change in pull request #6232:
URL: https://github.com/apache/apisix/pull/6232#discussion_r795133584



##########
File path: apisix/discovery/consul/init.lua
##########
@@ -0,0 +1,118 @@
+--
+-- 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 require            = require
+local local_conf         = require("apisix.core.config_local").local_conf()
+local core               = require("apisix.core")
+local cjson              = require('cjson')
+local http               = require('resty.http')
+local log                = core.log
+local ipairs             = ipairs
+local math               = math
+local random             = math.random
+local consul_conf        = local_conf.discovery.consul
+
+
+local function get_consul_server_endpoint(service_name)
+    local server = consul_conf.servers[random(1, #consul_conf.servers)]
+    if string.sub(server,#server) == "/" then
+        server = string.sub(server, 1, #server - 1)
+    end
+    
+    local path = "/v1/catalog/service/" .. service_name
+
+    local split = "?"
+
+    if consul_conf.dc ~= nil and consul_conf.dc ~= "" then
+        path = path .. split .. "dc=" .. consul_conf.dc
+        if split == "?" then
+            split = "&"
+        end
+    end
+
+    if consul_conf.alc_token ~= nil and #consul_conf.alc_token ~= "" then
+        path = path .. split .. "token=" .. consul_conf.alc_token
+        if split == "?" then
+            split = "&"
+        end
+    end
+
+    local endpoint = server .. path

Review comment:
       You don't have to do it manually. How about using https://github.com/golgote/neturl#querystring-builder ?




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] bisakhmondal commented on pull request #6232: feat(discovery): add consul support

Posted by GitBox <gi...@apache.org>.
bisakhmondal commented on pull request #6232:
URL: https://github.com/apache/apisix/pull/6232#issuecomment-1025079606


   > @bisakhmondal Could you help @water1st if she/he has trouble with the test cases? Thanks!
   
   Hi @water1st, for the code lint: you can run `make lint` before pushing your changes to the PR ([ref](https://github.com/apache/apisix/blob/master/CONTRIBUTING.md#check-code-style-and-test-case-style))
   
   As you have created a new directory (/discovey/consul), it won't be installed automatically unless you add an entry here. could you please do it? The other CIs will also pass after that.
   https://github.com/apache/apisix/blob/bbebdc9606e47f325180737cabf3cf479b69d013/Makefile#L275-L282 


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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