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/12/30 15:42:59 UTC

[GitHub] [apisix] ronething opened a new pull request, #8593: feat: stream subsystem support dns service discovery

ronething opened a new pull request, #8593:
URL: https://github.com/apache/apisix/pull/8593

   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   Fixes #7779
   
   For SRV record which has port 0, we will fallback to use the upstream protocol's default port. 
   
   i'm not sure what is the tcp protocol's default port, so my test case is temporary like below.
   
   `proxy request to 127.0.0.1:nil`
   
   ```
   === TEST 14: SRV (port is 0)
   --- apisix_yaml
   upstreams:
       - service_name: "zero.srv.test.local"
         discovery_type: dns
         type: roundrobin
         id: 1
   --- error_log
   connect() failed
   --- grep_error_log eval
   qr/proxy request to \S+/
   --- grep_error_log_out
   proxy request to 127.0.0.1:nil
   ```
   
   i will modify `scheme_to_port` it if need.
   
   ```
   local scheme_to_port = {
       http = 80,
       https = 443,
       grpc = 80,
       grpcs = 443
   }
   ```
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [x] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
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] ronething commented on a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1062169687


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 15: SRV (override port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 16: prefer A than SRV when A is ahead of SRV in config.yaml
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+        order:
+            - A
+            - SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 17: Invalid order type in config.yaml

Review Comment:
   i will remove it later.



##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 15: SRV (override port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 16: prefer A than SRV when A is ahead of SRV in config.yaml
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+        order:
+            - A
+            - SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 17: Invalid order type in config.yaml

Review Comment:
   i will remove these tests later.



-- 
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] ronething commented on a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1063149797


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil

Review Comment:
   i ignore zero port node when is in the stream subsystem.



##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 15: SRV (override port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 16: prefer A than SRV when A is ahead of SRV in config.yaml
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+        order:
+            - A
+            - SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 17: Invalid order type in config.yaml

Review Comment:
   done.



-- 
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] ronething commented on pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on PR #8593:
URL: https://github.com/apache/apisix/pull/8593#issuecomment-1378156963

   @tokers @soulbird Could you please take a look? 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] spacewander merged pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
spacewander merged PR #8593:
URL: https://github.com/apache/apisix/pull/8593


-- 
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] ronething commented on a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1062169542


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil

Review Comment:
   For HTTP, we will fill node info in `apisix/upstream.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/upstream.lua#L178
   
   For Stream, if node port is 0, it will not be filled node info, so the error log is like `proxy request to 127.0.0.1:nil` which in the `apisix/balancer.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/balancer.lua#L384
   
   i wonder if we need to reject zero port in the stream, we should reject in where, can you give me some hint? thank you.



-- 
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] ronething commented on a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1063150054


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53

Review Comment:
   done.



-- 
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] ronething commented on a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1062169542


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil

Review Comment:
   For HTTP, we will fill node info in `apisix/upstream.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/upstream.lua#L178
   
   For Stream, if node port is 0, it will not be filled node info, so the error log is like `proxy request to 127.0.0.1:nil` which in the `apisix/balancer.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/balancer.lua#L384
   
   i wonder if we need to reject zero port in the stream, we should reject in where, can you give me some hints? thank you.



-- 
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 a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1062131672


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil

Review Comment:
   Maybe we need to reject zero port in the stream, as there is not default port for TCP.
   `proxy request to 127.0.0.1:nil` such an error log looks like a bug in APISIX.



##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53

Review Comment:
   The expected error log is not long enough and confusing.
   Why don't we use https://github.com/apache/apisix/blob/93454252a51c7e14c140999532edf6ddd8ce5667/t/discovery/dns/sanity.t#L89



##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 15: SRV (override port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 16: prefer A than SRV when A is ahead of SRV in config.yaml
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+        order:
+            - A
+            - SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:nil
+
+
+
+=== TEST 17: Invalid order type in config.yaml

Review Comment:
   Do we need these tests? The order of type doesn't matter with the L4 or L7.



##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");

Review Comment:
   I spend some time and figure out we can set it directly with:
   ```suggestion
           $block->set_value("stream_request", "GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n");
   ```



-- 
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] ronething commented on a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1062169542


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil

Review Comment:
   For L7, we will fill node info in `apisix/upstream.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/upstream.lua#L178
   
   For L4, if node port is 0, it will not be filled node info, so the error log is like `proxy request to 127.0.0.1:nil` which in the `apisix/balancer.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/balancer.lua#L384
   
   i wonder if we need to reject zero port in the stream, we should reject in where, can you give me some hint? thank you.



-- 
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] ronething commented on a diff in pull request #8593: feat: stream subsystem support dns service discovery

Posted by GitBox <gi...@apache.org>.
ronething commented on code in PR #8593:
URL: https://github.com/apache/apisix/pull/8593#discussion_r1062169542


##########
t/discovery/stream/dns.t:
##########
@@ -0,0 +1,431 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_root_location();
+no_shuffle();
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->yaml_config) {
+        my $yaml_config = <<_EOC_;
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+_EOC_
+
+        $block->set_value("yaml_config", $yaml_config);
+    }
+
+    if ($block->apisix_yaml) {
+        my $upstream = <<_EOC_;
+stream_routes:
+  - id: 1
+    server_port: 1985
+    upstream_id: 1
+#END
+_EOC_
+
+        $block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
+    }
+
+    if (!$block->stream_request) {
+        # GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n
+        $block->set_value("stream_request", "\x47\x45\x54\x20\x2f\x68\x65\x6c\x6c\x6f\x20\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x31\x32\x37\x2e\x30\x2e\x30\x2e\x31\x3a\x31\x39\x38\x35\x0d\x0a\x0d\x0a");
+    }
+
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: default port to 53
+--- log_level: debug
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1"
+--- apisix_yaml
+upstreams:
+    - service_name: sd.test.local
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+127.0.0.1:53
+
+
+
+=== TEST 2: A
+--- apisix_yaml
+upstreams:
+    - service_name: "sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 3: AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "ipv6.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to [0:0:0:0:0:0:0:1]:1980
+
+
+
+=== TEST 4: prefer A to AAAA
+--- listen_ipv6
+--- apisix_yaml
+upstreams:
+    - service_name: "mix.sd.test.local:1980"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1980
+
+
+
+=== TEST 5: no /etc/hosts
+--- apisix_yaml
+upstreams:
+    - service_name: test.com
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 6: no /etc/resolv.conf
+--- yaml_config
+apisix:
+    node_listen: 1984
+    enable_admin: false
+    enable_resolv_search_option: false
+deployment:
+    role: data_plane
+    role_data_plane:
+        config_provider: yaml
+discovery:                        # service discovery center
+    dns:
+        servers:
+            - "127.0.0.1:1053"
+--- apisix_yaml
+upstreams:
+    - service_name: apisix
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+failed to query the DNS server
+
+
+
+=== TEST 7: SRV
+--- apisix_yaml
+upstreams:
+    - service_name: "srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 8: SRV (RFC 2782 style)
+--- apisix_yaml
+upstreams:
+    - service_name: "_sip._tcp.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 9: SRV (different port)
+--- apisix_yaml
+upstreams:
+    - service_name: "port.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 10: SRV (zero weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 11: SRV (split weight)
+--- apisix_yaml
+upstreams:
+    - service_name: "split-weight.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- grep_error_log eval
+qr/upstream nodes: \{[^}]+\}/
+--- grep_error_log_out eval
+qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
+--- stream_response_like
+hello world
+
+
+
+=== TEST 12: SRV (priority)
+--- apisix_yaml
+upstreams:
+    - service_name: "priority.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- stream_response_like
+hello world
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:1979
+proxy request to 127.0.0.2:1980
+
+
+
+=== TEST 13: prefer SRV than A
+--- apisix_yaml
+upstreams:
+    - service_name: "srv-a.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+proxy request to 127.0.0.1:1980
+--- stream_response_like
+hello world
+
+
+
+=== TEST 14: SRV (port is 0)
+--- apisix_yaml
+upstreams:
+    - service_name: "zero.srv.test.local"
+      discovery_type: dns
+      type: roundrobin
+      id: 1
+--- error_log
+connect() failed
+--- grep_error_log eval
+qr/proxy request to \S+/
+--- grep_error_log_out
+proxy request to 127.0.0.1:nil

Review Comment:
   For L7, we will fill node info in `apisix/upstream.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/upstream.lua#L178
   
   For L4, if node port is 0, it will not be filled node info, so the error log is like `proxy request to 127.0.0.1:nil` which in the `apisix/balancer.lua` https://github.com/apache/apisix/blob/030019b5297268b2171df5aa661d84c3c1ab6b92/apisix/balancer.lua#L384
   
   if we need to reject zero port in the stream, i wonder we should reject in where, can you give me some hint? thank you.



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