You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "wizhuo (via GitHub)" <gi...@apache.org> on 2023/10/19 05:15:48 UTC

[PR] feat:add zipkin variable [apisix]

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

   ### Description
   
   I would like to expose the zipkin span information during the rewrite phase so that it can be used in other plugins and scenarios. For example, it would be useful to include the trace ID when printing logs.
   
   Fixes # (issue)
   
   ### Checklist
   
   - [ ] I have explained the need for this PR and the problem it solves
   - [ ] I have explained the changes or the new features added to this PR
   - [ ] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] 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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "wizhuo (via GitHub)" <gi...@apache.org>.
wizhuo commented on PR #10361:
URL: https://github.com/apache/apisix/pull/10361#issuecomment-1772306387

   > Good job! Please make the ci pass
   
   I have already updated, please check


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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on code in PR #10361:
URL: https://github.com/apache/apisix/pull/10361#discussion_r1366426763


##########
t/plugin/zipkin3.t:
##########
@@ -0,0 +1,134 @@
+#
+# 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_long_string();
+no_root_location();
+log_level("info");
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->extra_yaml_config) {
+        my $extra_yaml_config = <<_EOC_;
+plugins:
+    - zipkin
+plugin_attr:
+    zipkin:
+        set_ngx_var: true
+_EOC_
+        $block->set_value("extra_yaml_config", $extra_yaml_config);
+    }
+
+    my $upstream_server_config = $block->upstream_server_config // <<_EOC_;
+        set \$zipkin_context_traceparent "";
+        set \$zipkin_trace_id "";
+        set \$zipkin_span_id "";
+_EOC_
+
+    $block->set_value("upstream_server_config", $upstream_server_config);
+
+    my $extra_init_by_lua = <<_EOC_;
+    local zipkin = require("apisix.plugins.zipkin")
+    local orig_func = zipkin.access
+    zipkin.access = function (...)
+        local traceparent = ngx.var.zipkin_context_traceparent
+        if traceparent == nil or traceparent == '' then
+           ngx.log(ngx.ERR,"ngx_var.zipkin_context_traceparent is empty")
+        else
+            ngx.log(ngx.ERR,"ngx_var.zipkin_context_traceparent:",ngx.var.zipkin_context_traceparent)
+        end
+
+        local orig = orig_func(...)
+        return orig
+    end
+_EOC_
+
+    $block->set_value("extra_init_by_lua", $extra_init_by_lua);
+
+    if (!$block->request) {
+            $block->set_value("request", "GET /t");
+    }
+
+    $block;
+});
+
+run_tests;
+
+__DATA__
+
+
+=== TEST 1: add plugin metadata
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "plugins": {
+                            "zipkin": {
+                                "endpoint": "http://127.0.0.1:9999/mock_zipkin",
+                                "sample_ratio": 1
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+
+
+
+=== TEST 2:  trigger zipkin with open set variables
+--- request
+GET /echo
+--- error_log eval
+qr/ngx_var.zipkin_context_traceparent:00-\w{32}-\w{16}-01*/
+
+
+
+
+

Review Comment:
   Three blanks are needed



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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on PR #10361:
URL: https://github.com/apache/apisix/pull/10361#issuecomment-1772359740

   @wizhuo please check the ci error


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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 merged PR #10361:
URL: https://github.com/apache/apisix/pull/10361


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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "wizhuo (via GitHub)" <gi...@apache.org>.
wizhuo commented on PR #10361:
URL: https://github.com/apache/apisix/pull/10361#issuecomment-1772366087

   > @wizhuo please check the ci error
   
   Please advise on how to resolve the following issue
   
   
   Error: nginx: [error] open() "/home/runner/work/apisix/apisix/logs/nginx.pid" failed (2: No such file or directory)
   [ info ] stop -> [ Done ]
   + git checkout conf/config.yaml
   Updated 0 paths from the index
   + for f in ./t/cli/test_*.sh
   + PATH=/usr/local/openresty-debug/nginx/sbin:/usr/local/openresty-debug/luajit/bin:/usr/local/openresty-debug/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
   + ./t/cli/test_zipkin_set_ngx_var.sh
   ./ci/linux_apisix_current_luarocks_runner.sh: line 74: ./t/cli/test_zipkin_set_ngx_var.sh: Permission denied
   Error: Process completed with exit code 126.
   
   


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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on PR #10361:
URL: https://github.com/apache/apisix/pull/10361#issuecomment-1772166409

   Good job! Please make the ci pass


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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on code in PR #10361:
URL: https://github.com/apache/apisix/pull/10361#discussion_r1366696973


##########
apisix/cli/ops.lua:
##########
@@ -546,6 +546,11 @@ Please modify "admin_key" in conf/config.yaml .
     if enabled_plugins["opentelemetry"] and yaml_conf.plugin_attr["opentelemetry"] then
         opentelemetry_set_ngx_var = yaml_conf.plugin_attr["opentelemetry"].set_ngx_var
     end
+
+    local zipkin_set_ngx_var
+    if enabled_plugins["zipkin"] and yaml_conf.plugin_attr["zipkin"] then
+        zipkin_set_ngx_var = yaml_conf.plugin_attr["zipkin"].set_ngx_var
+    end

Review Comment:
   Need one blank



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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on code in PR #10361:
URL: https://github.com/apache/apisix/pull/10361#discussion_r1366525869


##########
apisix/plugins/zipkin.lua:
##########
@@ -51,7 +55,12 @@ local schema = {
         span_version = {
             enum = {ZIPKIN_SPAN_VER_1, ZIPKIN_SPAN_VER_2},
             default = ZIPKIN_SPAN_VER_2,
-        },
+        },       
+        set_ngx_var = {
+            type = "boolean",
+            description = "set nginx variables",
+            default = false,
+          },

Review Comment:
   Why do you add the check here? Are you going to pass this configuration in the plugin parameters??It is unnecessary if you just want to define the configuration in `config.yaml` 



##########
apisix/plugins/zipkin.lua:
##########
@@ -51,7 +55,12 @@ local schema = {
         span_version = {
             enum = {ZIPKIN_SPAN_VER_1, ZIPKIN_SPAN_VER_2},
             default = ZIPKIN_SPAN_VER_2,
-        },
+        },       
+        set_ngx_var = {
+            type = "boolean",
+            description = "set nginx variables",
+            default = false,
+          },

Review Comment:
   Why do you add the check here? Are you going to pass this configuration in the plugin parameters??It is unnecessary if you just want to define the configuration in `config.yaml` 



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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on PR #10361:
URL: https://github.com/apache/apisix/pull/10361#issuecomment-1780578017

   @wizhuo Nice job!


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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on code in PR #10361:
URL: https://github.com/apache/apisix/pull/10361#discussion_r1366426167


##########
apisix/plugins/zipkin.lua:
##########
@@ -69,6 +78,11 @@ function _M.check_schema(conf)
     return core.schema.check(schema, conf)
 end
 
+local plugin_info  = plugin.plugin_attr(plugin_name) or {}
+
+
+
+

Review Comment:
   Why so many blanks?



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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on code in PR #10361:
URL: https://github.com/apache/apisix/pull/10361#discussion_r1366533110


##########
t/cli/test_zipkin_set_ngx_var.sh:
##########
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+. ./t/cli/common.sh
+
+echo '
+plugins:
+    - zipkin
+plugin_attr:
+  zipkin:
+    set_ngx_var: true
+' > conf/config.yaml
+
+make init
+
+if ! grep "set \$zipkin_context_traceparent          '';" conf/nginx.conf > /dev/null; then
+    echo "failed: zipkin_context_traceparent not found in nginx.conf"
+    exit 1
+fi
+
+if ! grep "set \$zipkin_trace_id                     '';" conf/nginx.conf > /dev/null; then
+    echo "failed: zipkin_trace_id not found in nginx.conf"
+    exit 1
+fi
+
+if ! grep "set \$zipkin_span_id                      '';" conf/nginx.conf > /dev/null; then
+    echo "failed: zipkin_span_id not found in nginx.conf"
+    exit 1
+fi
+
+

Review Comment:
   Please remove the redundant blank



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


Re: [PR] feat: add zipkin variable [apisix]

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on PR #10361:
URL: https://github.com/apache/apisix/pull/10361#issuecomment-1774365120

   @wizhuo you can test in your private repository with the following configuration
   ```
     - name: Run debugger
       if: ${{ failure() }}
       uses: mxschmitt/action-tmate@v3
       timeout-minutes: 15
   ```


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