This is an automated email from the ASF dual-hosted git repository. zhaoyunxing pushed a commit to branch compress in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
commit c178568f70d25a984fae1d502391cc5f70947aa3 Author: phil <[email protected]> AuthorDate: Mon May 24 10:05:16 2021 +0800 Feature/openzipkin (#119) * update: add opentrace example use zipkin & prometheus * update: add zipkin & prometheus in dubbo-go example * update: readme * update: update readme, and add more implementations * update: README --- .run/openzipkin/zipkin-go-client.run.xml | 15 ++ .run/openzipkin/zipkin-go-server-a.run.xml | 16 ++ .run/openzipkin/zipkin-go-server-b.run.xml | 15 ++ go.mod | 5 +- go.sum | 17 ++ openzipkin/README.md | 174 ++++++++++++++++++++ openzipkin/README_zh.md | 179 +++++++++++++++++++++ openzipkin/doc/app_dependency.png | Bin 0 -> 32882 bytes openzipkin/doc/zipkin_trace.png | Bin 0 -> 319434 bytes openzipkin/docker-compose.yml | 58 +++++++ openzipkin/go-client/cmd/client.go | 155 ++++++++++++++++++ openzipkin/go-client/conf/client.yml | 67 ++++++++ openzipkin/go-client/conf/log.yml | 27 ++++ openzipkin/go-client/pkg/user.go | 50 ++++++ openzipkin/go-server-a/cmd/server.go | 109 +++++++++++++ openzipkin/go-server-a/conf/client.yml | 59 +++++++ openzipkin/go-server-a/conf/log.yml | 27 ++++ openzipkin/go-server-a/conf/server.yml | 67 ++++++++ openzipkin/go-server-a/docker/docker-compose.yml | 9 ++ openzipkin/go-server-a/pkg/user.go | 88 ++++++++++ .../go-server-a/tests/integration/main_test.go | 71 ++++++++ .../tests/integration/userprovider_test.go | 38 +++++ openzipkin/go-server-b/cmd/server.go | 107 ++++++++++++ openzipkin/go-server-b/conf/client.yml | 60 +++++++ openzipkin/go-server-b/conf/log.yml | 27 ++++ openzipkin/go-server-b/conf/server.yml | 57 +++++++ openzipkin/go-server-b/docker/docker-compose.yml | 9 ++ openzipkin/go-server-b/pkg/user.go | 62 +++++++ .../go-server-b/tests/integration/main_test.go | 71 ++++++++ .../tests/integration/userprovider_test.go | 39 +++++ .../prometheus/create-datasource-and-dashboard.sh | 33 ++++ openzipkin/prometheus/prometheus.yml | 13 ++ 32 files changed, 1722 insertions(+), 2 deletions(-) diff --git a/.run/openzipkin/zipkin-go-client.run.xml b/.run/openzipkin/zipkin-go-client.run.xml new file mode 100644 index 0000000..8538c26 --- /dev/null +++ b/.run/openzipkin/zipkin-go-client.run.xml @@ -0,0 +1,15 @@ +<component name="ProjectRunConfigurationManager"> + <configuration default="false" name="openzipkin-go-client" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="openzipkin"> + <module name="dubbo-go-samples" /> + <working_directory value="$PROJECT_DIR$" /> + <envs> + <env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/openzipkin/go-client/conf/log.yml" /> + <env name="CONF_CONSUMER_FILE_PATH" value="$PROJECT_DIR$/openzipkin/go-client/conf/client.yml" /> + </envs> + <kind value="PACKAGE" /> + <filePath value="$PROJECT_DIR$/openzipkin/go-client/cmd/client.go" /> + <package value="github.com/apache/dubbo-go-samples/openzipkin/go-client/cmd" /> + <directory value="$PROJECT_DIR$" /> + <method v="2" /> + </configuration> +</component> \ No newline at end of file diff --git a/.run/openzipkin/zipkin-go-server-a.run.xml b/.run/openzipkin/zipkin-go-server-a.run.xml new file mode 100644 index 0000000..268acbc --- /dev/null +++ b/.run/openzipkin/zipkin-go-server-a.run.xml @@ -0,0 +1,16 @@ +<component name="ProjectRunConfigurationManager"> + <configuration default="false" name="openzipkin-go-server-a" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="openzipkin"> + <module name="dubbo-go-samples" /> + <working_directory value="$PROJECT_DIR$" /> + <envs> + <env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/openzipkin/go-server-a/conf/log.yml" /> + <env name="CONF_PROVIDER_FILE_PATH" value="$PROJECT_DIR$/openzipkin/go-server-a/conf/server.yml" /> + <env name="CONF_CONSUMER_FILE_PATH" value="$PROJECT_DIR$/openzipkin/go-server-a/conf/client.yml" /> + </envs> + <kind value="PACKAGE" /> + <filePath value="$PROJECT_DIR$/openzipkin/go-server-a/cmd/server.go" /> + <package value="github.com/apache/dubbo-go-samples/openzipkin/go-server-a/cmd" /> + <directory value="$PROJECT_DIR$" /> + <method v="2" /> + </configuration> +</component> \ No newline at end of file diff --git a/.run/openzipkin/zipkin-go-server-b.run.xml b/.run/openzipkin/zipkin-go-server-b.run.xml new file mode 100644 index 0000000..b6137d9 --- /dev/null +++ b/.run/openzipkin/zipkin-go-server-b.run.xml @@ -0,0 +1,15 @@ +<component name="ProjectRunConfigurationManager"> + <configuration default="false" name="openzipkin-go-server-b" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="openzipkin"> + <module name="dubbo-go-samples" /> + <working_directory value="$PROJECT_DIR$" /> + <envs> + <env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/openzipkin/go-server-b/conf/log.yml" /> + <env name="CONF_PROVIDER_FILE_PATH" value="$PROJECT_DIR$/openzipkin/go-server-b/conf/server.yml" /> + </envs> + <kind value="PACKAGE" /> + <filePath value="$PROJECT_DIR$/openzipkin/go-server-b/cmd/server.go" /> + <package value="github.com/apache/dubbo-go-samples/openzipkin/go-server-b/cmd" /> + <directory value="$PROJECT_DIR$" /> + <method v="2" /> + </configuration> +</component> \ No newline at end of file diff --git a/go.mod b/go.mod index 3885d92..629c7f9 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,7 @@ module github.com/apache/dubbo-go-samples require ( cloud.google.com/go v0.50.0 // indirect + contrib.go.opencensus.io/exporter/prometheus v0.3.0 github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 // indirect github.com/alibaba/sentinel-golang v1.0.2 github.com/apache/dubbo-getty v1.4.3 @@ -13,7 +14,6 @@ require ( github.com/emicklei/go-restful/v3 v3.4.0 github.com/golang/protobuf v1.4.3 github.com/gophercloud/gophercloud v0.3.0 // indirect - github.com/hashicorp/golang-lru v0.5.3 // indirect github.com/imdario/mergo v0.3.9 // indirect github.com/linode/linodego v0.10.0 // indirect github.com/miekg/dns v1.1.27 // indirect @@ -28,7 +28,8 @@ require ( github.com/transaction-wg/seata-golang v0.2.1-alpha github.com/uber/jaeger-client-go v2.22.1+incompatible github.com/uber/jaeger-lib v2.2.0+incompatible // indirect - google.golang.org/grpc v1.33.1 + go.opencensus.io v0.23.0 + google.golang.org/grpc v1.33.2 google.golang.org/grpc/examples v0.0.0-20210322221411-d26af8e39165 // indirect ) diff --git a/go.sum b/go.sum index 6f9977b..96d650d 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7 cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +contrib.go.opencensus.io/exporter/prometheus v0.3.0 h1:08FMdJYpItzsknogU6PiiNo7XQZg/25GjH236+YCwD0= +contrib.go.opencensus.io/exporter/prometheus v0.3.0/go.mod h1:rpCPVQKhiyH8oomWgm34ZmgIdZa8OVYO5WAIygPbBBE= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v40.3.0+incompatible h1:NthZg3psrLxvQLN6rVm07pZ9mv2wvGNaBNGQ3fnPvLE= github.com/Azure/azure-sdk-for-go v40.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= @@ -77,9 +79,11 @@ github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJM github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 h1:rFw4nCn9iMW+Vajsk51NtYIcwSTkXr+JGrMd36kTDJw= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alibaba/sentinel-golang v1.0.2 h1:Acopq74hOtZN4MV1v811MQ6QcqPFLDSczTrRXv9zpIg= github.com/alibaba/sentinel-golang v1.0.2/go.mod h1:QsB99f/z35D2AiMrAWwgWE85kDTkBUIkcmPrRt+61NI= @@ -355,6 +359,8 @@ github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= @@ -480,6 +486,7 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk= github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hil v0.0.0-20160711231837-1e86c6b523c5 h1:uk280DXEbQiCOZgCOI3elFSeNxf8YIZiNsbr2pQLYD0= @@ -762,6 +769,7 @@ github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= +github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.8.0 h1:zvJNkoCFAnYFNC24FV8nW4JdRJ3GIFcLbg65lL/JDcw= github.com/prometheus/client_golang v1.8.0/go.mod h1:O9VU6huf47PktckDQfMTX0Y8tY0/7TSWwj+ITvv0TnM= @@ -779,6 +787,7 @@ github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4= github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= @@ -790,9 +799,12 @@ github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.2.0 h1:wH4vA7pcjKuZzjF7lM8awk4fnuJO6idemZXoKnULUx4= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/statsd_exporter v0.20.0 h1:M0hQphnq2WyWKS5CefQL8PqWwBOBPhiAkyLo5l4ZYvE= +github.com/prometheus/statsd_exporter v0.20.0/go.mod h1:YL3FWCG8JBBtaUSxAg4Gz2ZYu22bS84XM89ZQXXTWmQ= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rboyer/safeio v0.2.1/go.mod h1:Cq/cEPK+YXFn622lsQ0K4KsPZSPtaptHHEldsy7Fmig= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -940,6 +952,8 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= +go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -1036,6 +1050,7 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= @@ -1095,6 +1110,7 @@ golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1238,6 +1254,7 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/openzipkin/README.md b/openzipkin/README.md new file mode 100644 index 0000000..54ef3db --- /dev/null +++ b/openzipkin/README.md @@ -0,0 +1,174 @@ +# Zipkin in Dubbo-go Example + +## Backend + +**Zipkin** is a distributed tracing system. It helps **Dubbo-go** gathering timing data which is used to troubleshoot latency problems in service architectures. + +## Introduction + +```markdown +. +├── README.md +├── README_zh.md +├── docker-compose.yml +├── go-client +├── go-server-a +├── go-server-b +└── prometheus +``` + +- go-client :The Service Consumer +- go-server-a :The Service Provider A +- go-server-b :The Service Provider B + +Client calls ProviderA , and then calls ProviderB, +ProviderA also makes a request to ProviderB! + +dependencies : + + +## Code + +register Zipkin. Reporter,Endpoint,Tracer,default sample `AlwaysSample` + +```go +func registerZipkin() { + // set up a span reporter + reporter := zipkinhttp.NewReporter("http://localhost:9411/api/v2/spans") + + // create our local service endpoint + endpoint, err := zipkin.NewEndpoint("go-server-a", "localhost:80") + if err != nil { + gxlog.CError("unable to create local endpoint: %+v\n", err) + } + + // set sampler , default AlwaysSample + // sampler := zipkin.NewModuloSampler(1) + + // initialize our tracer + // nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint), zipkin.WithSampler(sampler)) + nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint)) + if err != nil { + gxlog.CError("unable to create tracer: %+v\n", err) + } + + // use zipkin-go-opentracing to wrap our tracer + tracer := zipkinot.Wrap(nativeTracer) + + // optionally set as Global OpenTracing tracer instance + opentracing.SetGlobalTracer(tracer) +} +``` + +## Config + +Provider config filter: + +```yaml + +services: + ... +filter: "tracing" + +``` + +## Filter + +Dubbo-go supports `opentrace filter` + +```go +func (tf *tracingFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { + var ( + spanCtx context.Context + span opentracing.Span + ) + operationName := invoker.GetUrl().ServiceKey() + "#" + invocation.MethodName() + + wiredCtx := ctx.Value(constant.TRACING_REMOTE_SPAN_CTX) + preSpan := opentracing.SpanFromContext(ctx) + + if preSpan != nil { + // it means that someone already create a span to trace, so we use the span to be the parent span + span = opentracing.StartSpan(operationName, opentracing.ChildOf(preSpan.Context())) + spanCtx = opentracing.ContextWithSpan(ctx, span) + + } else if wiredCtx != nil { + + // it means that there has a remote span, usually from client side. so we use this as the parent + span = opentracing.StartSpan(operationName, opentracing.ChildOf(wiredCtx.(opentracing.SpanContext))) + spanCtx = opentracing.ContextWithSpan(ctx, span) + } else { + // it means that there is not any span, so we create a span as the root span. + span, spanCtx = opentracing.StartSpanFromContext(ctx, operationName) + } + + defer func() { + span.Finish() + }() + + result := invoker.Invoke(spanCtx, invocation) + span.SetTag(successKey, result.Error() == nil) + if result.Error() != nil { + span.LogFields(log.String(errorKey, result.Error().Error())) + } + return result +} +``` + +## Install Zipkin + +First Way: + +Follow [Zipkin's quick start](https://zipkin.io/pages/quickstart.html) to install zipkin. + +```bash +curl -sSL https://zipkin.io/quickstart.sh | bash -s +``` + +Zipkin supports various backend storages including Cassandra, ElasticSearch and MySQL. Here we use the simplest storage - in-memory for demo purpose. + +```bash +java -jar zipkin.jar +``` + +Once the process starts, you can verify zipkin server works by access http://localhost:9411 + +Or Use Docker: + +See [/dubbo-go-sample/zipkin/docker/docker-compose.yml](docker-compose.yml) + +```dockerfile +services: + # The zipkin process services the UI, and also exposes a POST endpoint that + # instrumentation can send trace data to. + zipkin: + image: ghcr.io/openzipkin/zipkin-slim:${TAG:-latest} + container_name: zipkin + # Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables + environment: + - STORAGE_TYPE=mem + # Point the zipkin at the storage backend + - MYSQL_HOST=mysql + # Uncomment to enable self-tracing + # - SELF_TRACING_ENABLED=true + # Uncomment to increase heap size + # - JAVA_OPTS=-Xms128m -Xmx128m -XX:+ExitOnOutOfMemoryError + ports: + # Port used for the Zipkin UI and HTTP Api + - 9411:9411 + # Uncomment to enable debug logging + # command: --logging.level.zipkin2=DEBUG +``` + +```bash +docker-compose -f docker/docker-compose.yml up -d zipkin +``` + +### How To Run + +Refer to [HOWTO.md](../HOWTO_zh.md) under the root directory to run this sample. + +## The End + +Trace : + diff --git a/openzipkin/README_zh.md b/openzipkin/README_zh.md new file mode 100644 index 0000000..72d8ec3 --- /dev/null +++ b/openzipkin/README_zh.md @@ -0,0 +1,179 @@ +# Zipkin 在 Dubbo-go 应用示例 + +# 背景 + +Zipkin是一个分布式跟踪系统。它有助于收集解决 Dubbo-go 服务中的延迟问题所需的时序数据。 +包括该数据的收集和查找。 + +# 介绍 + +本示例演示了 Zipkin 在 Dubbo-go 应用程序中的基本用法。 + +```markdown +. +├── README.md +├── README_zh.md +├── docker-compose.yml +├── go-client +├── go-server-a +├── go-server-b +└── prometheus +``` + +- go-client :服务消费者 +- go-server-a :服务提供者 A +- go-server-b :服务提供者 B + +为了演示效果,示例中 Client 会同时对 ProviderA 与 ProviderB 发起请求, +ProviderA 内部也会对 ProviderB 发起请求! + +依赖关系: + + + +## 代码说明 + +服务启动时注册 Zipkin,包括 Reporter,Endpoint,Tracer,默认采样比例全采样 `AlwaysSample` ,可自行配置 + +```go +func registerZipkin() { + // set up a span reporter + reporter := zipkinhttp.NewReporter("http://localhost:9411/api/v2/spans") + + // create our local service endpoint + endpoint, err := zipkin.NewEndpoint("go-server-a", "localhost:80") + if err != nil { + gxlog.CError("unable to create local endpoint: %+v\n", err) + } + + // set sampler , default AlwaysSample + // sampler := zipkin.NewModuloSampler(1) + + // initialize our tracer + // nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint), zipkin.WithSampler(sampler)) + nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint)) + if err != nil { + gxlog.CError("unable to create tracer: %+v\n", err) + } + + // use zipkin-go-opentracing to wrap our tracer + tracer := zipkinot.Wrap(nativeTracer) + + // optionally set as Global OpenTracing tracer instance + opentracing.SetGlobalTracer(tracer) +} +``` + +## 配置 + +服务提供者配置过滤器: + +```yaml + +services: + ... +filter: "tracing" + +``` + +## 过滤器 + +Dubbo-go 提供 opentrace filter 实现,基于简单配置即可 + +```go +func (tf *tracingFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { + var ( + spanCtx context.Context + span opentracing.Span + ) + operationName := invoker.GetUrl().ServiceKey() + "#" + invocation.MethodName() + + wiredCtx := ctx.Value(constant.TRACING_REMOTE_SPAN_CTX) + preSpan := opentracing.SpanFromContext(ctx) + + if preSpan != nil { + // it means that someone already create a span to trace, so we use the span to be the parent span + span = opentracing.StartSpan(operationName, opentracing.ChildOf(preSpan.Context())) + spanCtx = opentracing.ContextWithSpan(ctx, span) + + } else if wiredCtx != nil { + + // it means that there has a remote span, usually from client side. so we use this as the parent + span = opentracing.StartSpan(operationName, opentracing.ChildOf(wiredCtx.(opentracing.SpanContext))) + spanCtx = opentracing.ContextWithSpan(ctx, span) + } else { + // it means that there is not any span, so we create a span as the root span. + span, spanCtx = opentracing.StartSpanFromContext(ctx, operationName) + } + + defer func() { + span.Finish() + }() + + result := invoker.Invoke(spanCtx, invocation) + span.SetTag(successKey, result.Error() == nil) + if result.Error() != nil { + span.LogFields(log.String(errorKey, result.Error().Error())) + } + return result +} +``` + + +## 安装 Zipkin + +第一种: + +参考 [Zipkin's quick start](https://zipkin.io/pages/quickstart.html) 安装 Zopkin + +Follow [Zipkin's quick start](https://zipkin.io/pages/quickstart.html) to install zipkin. + +```bash +curl -sSL https://zipkin.io/quickstart.sh | bash -s +``` + +Zipkin支持多种后端存储,包括Cassandra, ElasticSearch和MySQL。这里我们使用最简单的内存存储作为演示目的。 + + +```bash +java -jar zipkin.jar +``` + +您可以通过访问 http://localhost:9411 验证安装效果 + +或者使用 Docker : + +See [/dubbo-go-sample/zipkin/docker/docker-compose.yml](docker-compose.yml) + +```dockerfile +version: '2.4' + +services: + # The zipkin process services the UI, and also exposes a POST endpoint that + # instrumentation can send trace data to. + zipkin: + image: ghcr.io/openzipkin/zipkin-slim:${TAG:-latest} + container_name: zipkin + # Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables + environment: + - STORAGE_TYPE=mem + # Point the zipkin at the storage backend + - MYSQL_HOST=mysql + # Uncomment to enable self-tracing + # - SELF_TRACING_ENABLED=true + # Uncomment to increase heap size + # - JAVA_OPTS=-Xms128m -Xmx128m -XX:+ExitOnOutOfMemoryError + ports: + # Port used for the Zipkin UI and HTTP Api + - 9411:9411 + # Uncomment to enable debug logging + # command: --logging.level.zipkin2=DEBUG +``` + +## 如何运行 +请参阅根目录中的 [HOWTO.md](../HOWTO_zh.md) 来运行本例。 + +## 效果 + +链路: + diff --git a/openzipkin/doc/app_dependency.png b/openzipkin/doc/app_dependency.png new file mode 100644 index 0000000..473387d Binary files /dev/null and b/openzipkin/doc/app_dependency.png differ diff --git a/openzipkin/doc/zipkin_trace.png b/openzipkin/doc/zipkin_trace.png new file mode 100644 index 0000000..a43531a Binary files /dev/null and b/openzipkin/doc/zipkin_trace.png differ diff --git a/openzipkin/docker-compose.yml b/openzipkin/docker-compose.yml new file mode 100644 index 0000000..5ee5798 --- /dev/null +++ b/openzipkin/docker-compose.yml @@ -0,0 +1,58 @@ +version: '2.4' + +services: + zipkin: + image: ghcr.io/openzipkin/zipkin-slim:${TAG:-latest} + container_name: zipkin + # Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables + environment: + - STORAGE_TYPE=mem + # Point the zipkin at the storage backend + - MYSQL_HOST=mysql + # Uncomment to enable self-tracing + # - SELF_TRACING_ENABLED=true + # Uncomment to increase heap size + # - JAVA_OPTS=-Xms128m -Xmx128m -XX:+ExitOnOutOfMemoryError + ports: + # Port used for the Zipkin UI and HTTP Api + - 9411:9411 + # Uncomment to enable debug logging + # command: --logging.level.zipkin2=DEBUG + prometheus: + # Use a quay.io mirror to prevent build outages due to Docker Hub pull quotas + # Use latest from https://quay.io/repository/prometheus/prometheus?tab=tags + image: quay.io/prometheus/prometheus:latest + container_name: prometheus + ports: + - 9090:9090 + depends_on: + - zipkin + volumes: + - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml + + grafana: + # Use a quay.io mirror to prevent build outages due to Docker Hub pull quotas + # Use latest from https://quay.io/repository/app-sre/grafana?tab=tags + image: quay.io/app-sre/grafana:7.3.4 +# image: quay.io/opencloudio/ibm-monitoring-grafana-operator:1.12.0 + container_name: grafana + ports: + - 3000:3000 + depends_on: + - prometheus + environment: + - GF_AUTH_ANONYMOUS_ENABLED=true + - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin + + setup_grafana_datasource: + # This is an arbitrary small image that has curl installed + # Use a quay.io mirror to prevent build outages due to Docker Hub pull quotas + # Use latest from https://quay.io/repository/quay.io/rackspace/curl?tab=tags + image: quay.io/rackspace/curl:7.70.0 + container_name: setup_grafana_datasource + depends_on: + - grafana + volumes: + - ./prometheus/create-datasource-and-dashboard.sh:/tmp/create.sh:ro + working_dir: /tmp + entrypoint: /tmp/create.sh \ No newline at end of file diff --git a/openzipkin/go-client/cmd/client.go b/openzipkin/go-client/cmd/client.go new file mode 100644 index 0000000..872ef8c --- /dev/null +++ b/openzipkin/go-client/cmd/client.go @@ -0,0 +1,155 @@ +/* + * 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. + */ + +package main + +import ( + "context" + "contrib.go.opencensus.io/exporter/prometheus" + "go.opencensus.io/stats/view" + "math/rand" + "os" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + "github.com/apache/dubbo-go/config" + _ "github.com/apache/dubbo-go/filter/filter_impl" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + _ "github.com/apache/dubbo-go/registry/zookeeper" + "github.com/dubbogo/gost/log" + // tracing zipkin & prometheus + "github.com/opentracing/opentracing-go" + zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" + "github.com/openzipkin/zipkin-go" + zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" +) + +import ( + "github.com/apache/dubbo-go-samples/openzipkin/go-client/pkg" +) + +var userProviderA = new(pkg.UserProviderA) +var userProviderB = new(pkg.UserProviderB) + +func init() { + config.SetConsumerService(userProviderA) + config.SetConsumerService(userProviderB) + hessian.RegisterPOJO(&pkg.User{}) +} + +// need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run +func main() { + + config.Load() + + // register zipkin & prometheus exporter + registerZipkin() + registerPrometheus() + + time.Sleep(3 * time.Second) + + gxlog.CInfo("\n\n\nstart to test dubbo") + + getUserAll(context.Background()) +} + +func getUserAll(ctx context.Context) { + span, ctx := opentracing.StartSpanFromContext(ctx, "getUserAll") + + getUserA(ctx) + span.Finish() + + getUserB(ctx) + span.Finish() + + getUserA(ctx) + span.Finish() + + getUserB(ctx) + span.Finish() +} + +func getUserA(ctx context.Context) { + + time.Sleep(time.Duration(rand.Intn(977)+300) * time.Millisecond) + user := &pkg.User{} + err := userProviderA.GetUser(ctx, []interface{}{"A001"}, user) + if err != nil { + gxlog.CError("error: %v\n", err) + os.Exit(1) + return + } + gxlog.CInfo("response result: %v\n", user) + +} +func getUserB(ctx context.Context) { + + time.Sleep(time.Duration(rand.Intn(977)+300) * time.Millisecond) + user := &pkg.User{} + err := userProviderB.GetUser(ctx, []interface{}{"A001"}, user) + if err != nil { + gxlog.CError("error: %v\n", err) + os.Exit(1) + return + } + gxlog.CInfo("response result: %v\n", user) +} + +// zipkin / opentracing specific stuff +func registerZipkin() { + // set up a span reporter + reporter := zipkinhttp.NewReporter("http://localhost:9411/api/v2/spans") + + // create our local service endpoint + endpoint, err := zipkin.NewEndpoint("go-client", "localhost:80") + if err != nil { + gxlog.CError("unable to create local endpoint: %+v\n", err) + } + + // set sampler , default AlwaysSample + //sampler := zipkin.NewModuloSampler(1) + + // initialize our tracer + //nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint), zipkin.WithSampler(sampler)) + nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint)) + + if err != nil { + gxlog.CError("unable to create tracer: %+v\n", err) + } + + // use zipkin-go-opentracing to wrap our tracer + tracer := zipkinot.Wrap(nativeTracer) + + // optionally set as Global OpenTracing tracer instance + opentracing.SetGlobalTracer(tracer) +} + +// register prometheus exporter for zipkin +func registerPrometheus() *prometheus.Exporter { + pe, err := prometheus.NewExporter(prometheus.Options{Namespace: "go-client"}) + if err != nil { + gxlog.CError("Failed to create Prometheus exporter: %v", err) + } + view.RegisterExporter(pe) + return pe +} diff --git a/openzipkin/go-client/conf/client.yml b/openzipkin/go-client/conf/client.yml new file mode 100644 index 0000000..79bd4ad --- /dev/null +++ b/openzipkin/go-client/conf/client.yml @@ -0,0 +1,67 @@ +# dubbo client yaml configure file + +check: true +# client +request_timeout: "3s" +# connect timeout +connect_timeout: "3s" + +# application config +application: + organization: "dubbo.io" + name: "UserInfoClient" + module: "dubbo-go user-info client" + version: "0.0.1" + environment: "dev" + +# registry config +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +# reference config +references: + "UserProviderA": + registry: "demoZk" + protocol: "dubbo" + interface: "org.apache.dubbo.UserProviderA" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + "UserProviderB": + registry: "demoZk" + protocol: "dubbo" + interface: "org.apache.dubbo.UserProviderB" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + +# protocol config +protocol_conf: + dubbo: + reconnect_interval: 0 + connection_number: 1 + heartbeat_period: "5s" + session_timeout: "180s" + pool_size: 64 + pool_ttl: 600 + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024000 + session_name: "client" diff --git a/openzipkin/go-client/conf/log.yml b/openzipkin/go-client/conf/log.yml new file mode 100644 index 0000000..2b6e93a --- /dev/null +++ b/openzipkin/go-client/conf/log.yml @@ -0,0 +1,27 @@ +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capital" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/openzipkin/go-client/pkg/user.go b/openzipkin/go-client/pkg/user.go new file mode 100644 index 0000000..47261a8 --- /dev/null +++ b/openzipkin/go-client/pkg/user.go @@ -0,0 +1,50 @@ +/* + * 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. + */ + +package pkg + +import ( + "context" + "time" +) + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProviderA struct { + GetUser func(ctx context.Context, req []interface{}, rsp *User) error +} + +func (u *UserProviderA) Reference() string { + return "UserProviderA" +} + +type UserProviderB struct { + GetUser func(ctx context.Context, req []interface{}, rsp *User) error +} + +func (u *UserProviderB) Reference() string { + return "UserProviderB" +} + +func (User) JavaClassName() string { + return "org.apache.dubbo.User" +} diff --git a/openzipkin/go-server-a/cmd/server.go b/openzipkin/go-server-a/cmd/server.go new file mode 100644 index 0000000..fc06874 --- /dev/null +++ b/openzipkin/go-server-a/cmd/server.go @@ -0,0 +1,109 @@ +/* + * 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. + */ + +package main + +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + "github.com/apache/dubbo-go/common/logger" + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + "github.com/apache/dubbo-go/config" + _ "github.com/apache/dubbo-go/filter/filter_impl" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + _ "github.com/apache/dubbo-go/registry/zookeeper" + gxlog "github.com/dubbogo/gost/log" + + // tracing + "github.com/opentracing/opentracing-go" + zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" + "github.com/openzipkin/zipkin-go" + zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" +) + +import ( + "github.com/apache/dubbo-go-samples/openzipkin/go-server-a/pkg" +) + +var ( + survivalTimeout = int(3e9) +) + +// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run +func main() { + + hessian.RegisterPOJO(&pkg.User{}) + config.Load() + registerZipkin() + + initSignal() +} + +func initSignal() { + signals := make(chan os.Signal, 1) + // It is not possible to block SIGKILL or syscall.SIGSTOP + signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + for { + sig := <-signals + logger.Infof("get signal %s", sig.String()) + switch sig { + case syscall.SIGHUP: + // reload() + default: + time.AfterFunc(time.Duration(survivalTimeout), func() { + logger.Warnf("app exit now by force...") + os.Exit(1) + }) + + // The program exits normally or timeout forcibly exits. + fmt.Println("provider app exit now...") + return + } + } +} +func registerZipkin() { + // set up a span reporter + reporter := zipkinhttp.NewReporter("http://localhost:9411/api/v2/spans") + + // create our local service endpoint + endpoint, err := zipkin.NewEndpoint("go-server-a", "localhost:80") + if err != nil { + gxlog.CError("unable to create local endpoint: %+v\n", err) + } + + // initialize our tracer + nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint)) + if err != nil { + gxlog.CError("unable to create tracer: %+v\n", err) + } + + // use zipkin-go-opentracing to wrap our tracer + tracer := zipkinot.Wrap(nativeTracer) + + // optionally set as Global OpenTracing tracer instance + opentracing.SetGlobalTracer(tracer) +} diff --git a/openzipkin/go-server-a/conf/client.yml b/openzipkin/go-server-a/conf/client.yml new file mode 100644 index 0000000..78c96f6 --- /dev/null +++ b/openzipkin/go-server-a/conf/client.yml @@ -0,0 +1,59 @@ +# dubbo client yaml configure file + +check: true +# client +request_timeout: "3s" +# connect timeout +connect_timeout: "3s" + +# application config +application: + organization: "dubbo.io" + name: "UserInfoTest" + module: "dubbo-go user-info client" + version: "0.0.1" + environment: "dev" + +# registry config +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +# reference config +references: + "UserProviderB": + registry: "demoZk" + protocol: "dubbo" + interface: "org.apache.dubbo.UserProviderB" + cluster: "failover" + methods: + - name: "GetUser" + retries: 3 + +# protocol config +protocol_conf: + dubbo: + reconnect_interval: 0 + connection_number: 1 + heartbeat_period: "5s" + session_timeout: "180s" + pool_size: 64 + pool_ttl: 600 + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024000 + session_name: "client" diff --git a/openzipkin/go-server-a/conf/log.yml b/openzipkin/go-server-a/conf/log.yml new file mode 100644 index 0000000..8c3f700 --- /dev/null +++ b/openzipkin/go-server-a/conf/log.yml @@ -0,0 +1,27 @@ +level: "info" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capital" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/openzipkin/go-server-a/conf/server.yml b/openzipkin/go-server-a/conf/server.yml new file mode 100644 index 0000000..e5c965c --- /dev/null +++ b/openzipkin/go-server-a/conf/server.yml @@ -0,0 +1,67 @@ +# dubbo server yaml configure file + +# application config +application: + organization: "dubbo.io" + name: "UserInfoServer" + module: "dubbo-go user-info server" + version: "0.0.1" + environment: "dev" + +# registry config +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + +# service config +services: + "UserProviderA": + registry: "demoZk" + protocol: "dubbo" + interface: "org.apache.dubbo.UserProviderA" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +# reference config +references: + "UserProviderB": + registry: "demoZk" + protocol: "dubbo" + interface: "org.apache.dubbo.UserProviderB" + cluster: "failover" + methods: + - name: "GetUser" + retries: 3 + +filter: "tracing" + +# protocol config +protocols: + "dubbo": + name: "dubbo" + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "180s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024000 + session_name: "server" diff --git a/openzipkin/go-server-a/docker/docker-compose.yml b/openzipkin/go-server-a/docker/docker-compose.yml new file mode 100644 index 0000000..8724179 --- /dev/null +++ b/openzipkin/go-server-a/docker/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3' + +services: + zookeeper: + image: zookeeper + ports: + - 2181:2181 + restart: on-failure + diff --git a/openzipkin/go-server-a/pkg/user.go b/openzipkin/go-server-a/pkg/user.go new file mode 100644 index 0000000..d0ca328 --- /dev/null +++ b/openzipkin/go-server-a/pkg/user.go @@ -0,0 +1,88 @@ +/* + * 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. + */ + +package pkg + +import ( + "context" + "math/rand" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" + "github.com/dubbogo/gost/log" +) + +var userProviderB = new(UserProviderB) + +func init() { + config.SetProviderService(new(UserProvider)) + config.SetConsumerService(userProviderB) + hessian.RegisterPOJO(&User{}) +} + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProvider struct { +} + +func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) { + gxlog.CInfo("req:%#v", req) + time.Sleep(time.Duration(rand.Intn(977)+300) * time.Millisecond) + rsp := User{"A001", "Alex Stocks In Group A", 18, time.Now()} + gxlog.CInfo("rsp:%#v", rsp) + + gxlog.CInfo("request provider B , req:%#v", req) + getUserB(ctx) + + return &rsp, nil +} + +func getUserB(ctx context.Context) { + + time.Sleep(time.Duration(rand.Intn(977)+300) * time.Millisecond) + user := &User{} + err := userProviderB.GetUser(ctx, []interface{}{"A001"}, user) + if err != nil { + gxlog.CError("error: %v\n", err) + return + } + gxlog.CInfo("response result: %v\n", user) +} + +func (u *UserProvider) Reference() string { + return "UserProviderA" +} + +func (u User) JavaClassName() string { + return "org.apache.dubbo.User" +} + +type UserProviderB struct { + GetUser func(ctx context.Context, req []interface{}, rsp *User) error +} + +func (u *UserProviderB) Reference() string { + return "UserProviderB" +} diff --git a/openzipkin/go-server-a/tests/integration/main_test.go b/openzipkin/go-server-a/tests/integration/main_test.go new file mode 100644 index 0000000..4a75f7a --- /dev/null +++ b/openzipkin/go-server-a/tests/integration/main_test.go @@ -0,0 +1,71 @@ +// +build integration + +/* + * 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. + */ + +package integration + +import ( + "context" + "os" + "testing" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" + + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + _ "github.com/apache/dubbo-go/filter/filter_impl" + _ "github.com/apache/dubbo-go/metadata/service/inmemory" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + _ "github.com/apache/dubbo-go/registry/zookeeper" +) + +var userProvider = new(UserProvider) + +func TestMain(m *testing.M) { + config.SetConsumerService(userProvider) + hessian.RegisterPOJO(&User{}) + config.Load() + time.Sleep(3 * time.Second) + + os.Exit(m.Run()) +} + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProvider struct { + GetUser func(ctx context.Context, req []interface{}, rsp *User) error +} + +func (u *UserProvider) Reference() string { + return "UserProvider" +} + +func (User) JavaClassName() string { + return "org.apache.dubbo.User" +} diff --git a/openzipkin/go-server-a/tests/integration/userprovider_test.go b/openzipkin/go-server-a/tests/integration/userprovider_test.go new file mode 100644 index 0000000..3c4661a --- /dev/null +++ b/openzipkin/go-server-a/tests/integration/userprovider_test.go @@ -0,0 +1,38 @@ +// +build integration + +/* + * 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. + */ + +package integration + +import ( + "context" + "testing" +) +import ( + "github.com/stretchr/testify/assert" +) + +func TestGetUser(t *testing.T) { + user := &User{} + err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user) + assert.Nil(t, err) + assert.Equal(t, "A001", user.ID) + assert.Equal(t, "Alex Stocks In Group A", user.Name) + assert.Equal(t, int32(18), user.Age) + assert.NotNil(t, user.Time) +} diff --git a/openzipkin/go-server-b/cmd/server.go b/openzipkin/go-server-b/cmd/server.go new file mode 100644 index 0000000..17dfc6c --- /dev/null +++ b/openzipkin/go-server-b/cmd/server.go @@ -0,0 +1,107 @@ +/* + * 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. + */ + +package main + +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + "github.com/apache/dubbo-go/common/logger" + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + "github.com/apache/dubbo-go/config" + _ "github.com/apache/dubbo-go/filter/filter_impl" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + _ "github.com/apache/dubbo-go/registry/zookeeper" + gxlog "github.com/dubbogo/gost/log" + // trace: zipkin + "github.com/opentracing/opentracing-go" + zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing" + "github.com/openzipkin/zipkin-go" + zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http" +) + +import ( + "github.com/apache/dubbo-go-samples/openzipkin/go-server-b/pkg" +) + +var ( + survivalTimeout = int(3e9) +) + +// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run +func main() { + hessian.RegisterPOJO(&pkg.User{}) + config.Load() + registerZipkin() + + initSignal() +} + +func initSignal() { + signals := make(chan os.Signal, 1) + // It is not possible to block SIGKILL or syscall.SIGSTOP + signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + for { + sig := <-signals + logger.Infof("get signal %s", sig.String()) + switch sig { + case syscall.SIGHUP: + // reload() + default: + time.AfterFunc(time.Duration(survivalTimeout), func() { + logger.Warnf("app exit now by force...") + os.Exit(1) + }) + + // The program exits normally or timeout forcibly exits. + fmt.Println("provider app exit now...") + return + } + } +} +func registerZipkin() { + // set up a span reporter + reporter := zipkinhttp.NewReporter("http://localhost:9411/api/v2/spans") + + // create our local service endpoint + endpoint, err := zipkin.NewEndpoint("go-server-b", "localhost:80") + if err != nil { + gxlog.CError("unable to create local endpoint: %+v\n", err) + } + + // initialize our tracer + nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint)) + if err != nil { + gxlog.CError("unable to create tracer: %+v\n", err) + } + + // use zipkin-go-opentracing to wrap our tracer + tracer := zipkinot.Wrap(nativeTracer) + + // optionally set as Global OpenTracing tracer instance + opentracing.SetGlobalTracer(tracer) +} diff --git a/openzipkin/go-server-b/conf/client.yml b/openzipkin/go-server-b/conf/client.yml new file mode 100644 index 0000000..735fb03 --- /dev/null +++ b/openzipkin/go-server-b/conf/client.yml @@ -0,0 +1,60 @@ +# dubbo client yaml configure file + +check: true +# client +request_timeout: "3s" +# connect timeout +connect_timeout: "3s" + +# application config +application: + organization: "dubbo.io" + name: "UserInfoTest" + module: "dubbo-go user-info client" + version: "0.0.1" + environment: "dev" + +# registry config +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +# reference config +references: + "UserProvider": + registry: "demoZk" + protocol: "dubbo" + interface: "org.apache.dubbo.UserProvider" + group: "GroupB" + cluster: "failover" + methods: + - name: "GetUser" + retries: 3 + +# protocol config +protocol_conf: + dubbo: + reconnect_interval: 0 + connection_number: 1 + heartbeat_period: "5s" + session_timeout: "180s" + pool_size: 64 + pool_ttl: 600 + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024000 + session_name: "client" diff --git a/openzipkin/go-server-b/conf/log.yml b/openzipkin/go-server-b/conf/log.yml new file mode 100644 index 0000000..970d988 --- /dev/null +++ b/openzipkin/go-server-b/conf/log.yml @@ -0,0 +1,27 @@ +level: "error" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capital" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/openzipkin/go-server-b/conf/server.yml b/openzipkin/go-server-b/conf/server.yml new file mode 100644 index 0000000..c96d38a --- /dev/null +++ b/openzipkin/go-server-b/conf/server.yml @@ -0,0 +1,57 @@ +# dubbo server yaml configure file + +# application config +application: + organization: "dubbo.io" + name: "UserInfoServer" + module: "dubbo-go user-info server" + version: "0.0.1" + environment: "dev" + +# registry config +registries: + "demoZk": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + +# service config +services: + "UserProviderB": + registry: "demoZk" + protocol: "dubbo" + interface: "org.apache.dubbo.UserProviderB" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +#filter: "zipkin" +filter: "tracing" + +# protocol config +protocols: + "dubbo": + name: "dubbo" + +protocol_conf: + dubbo: + session_number: 700 + session_timeout: "180s" + getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024000 + session_name: "server" diff --git a/openzipkin/go-server-b/docker/docker-compose.yml b/openzipkin/go-server-b/docker/docker-compose.yml new file mode 100644 index 0000000..8724179 --- /dev/null +++ b/openzipkin/go-server-b/docker/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3' + +services: + zookeeper: + image: zookeeper + ports: + - 2181:2181 + restart: on-failure + diff --git a/openzipkin/go-server-b/pkg/user.go b/openzipkin/go-server-b/pkg/user.go new file mode 100644 index 0000000..aee528a --- /dev/null +++ b/openzipkin/go-server-b/pkg/user.go @@ -0,0 +1,62 @@ +/* + * 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. + */ + +package pkg + +import ( + "context" + "math/rand" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" + "github.com/dubbogo/gost/log" +) + +func init() { + config.SetProviderService(new(UserProvider)) + // ------for hessian2------ + hessian.RegisterPOJO(&User{}) +} + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProvider struct { +} + +func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) { + gxlog.CInfo("req:%#v", req) + time.Sleep(time.Duration(rand.Intn(977)+300) * time.Millisecond) + rsp := User{"A001", "Alex Stocks In Provider B", 18, time.Now()} + gxlog.CInfo("rsp:%#v", rsp) + return &rsp, nil +} + +func (u *UserProvider) Reference() string { + return "UserProviderB" +} + +func (u User) JavaClassName() string { + return "org.apache.dubbo.User" +} diff --git a/openzipkin/go-server-b/tests/integration/main_test.go b/openzipkin/go-server-b/tests/integration/main_test.go new file mode 100644 index 0000000..4a75f7a --- /dev/null +++ b/openzipkin/go-server-b/tests/integration/main_test.go @@ -0,0 +1,71 @@ +// +build integration + +/* + * 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. + */ + +package integration + +import ( + "context" + "os" + "testing" + "time" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" + "github.com/apache/dubbo-go/config" + + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + _ "github.com/apache/dubbo-go/filter/filter_impl" + _ "github.com/apache/dubbo-go/metadata/service/inmemory" + _ "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + _ "github.com/apache/dubbo-go/registry/zookeeper" +) + +var userProvider = new(UserProvider) + +func TestMain(m *testing.M) { + config.SetConsumerService(userProvider) + hessian.RegisterPOJO(&User{}) + config.Load() + time.Sleep(3 * time.Second) + + os.Exit(m.Run()) +} + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProvider struct { + GetUser func(ctx context.Context, req []interface{}, rsp *User) error +} + +func (u *UserProvider) Reference() string { + return "UserProvider" +} + +func (User) JavaClassName() string { + return "org.apache.dubbo.User" +} diff --git a/openzipkin/go-server-b/tests/integration/userprovider_test.go b/openzipkin/go-server-b/tests/integration/userprovider_test.go new file mode 100644 index 0000000..3726251 --- /dev/null +++ b/openzipkin/go-server-b/tests/integration/userprovider_test.go @@ -0,0 +1,39 @@ +// +build integration + +/* + * 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. + */ + +package integration + +import ( + "context" + "testing" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestGetUser(t *testing.T) { + user := &User{} + err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user) + assert.Nil(t, err) + assert.Equal(t, "A001", user.ID) + assert.Equal(t, "Alex Stocks In Group B", user.Name) + assert.Equal(t, int32(18), user.Age) + assert.NotNil(t, user.Time) +} diff --git a/openzipkin/prometheus/create-datasource-and-dashboard.sh b/openzipkin/prometheus/create-datasource-and-dashboard.sh new file mode 100644 index 0000000..76b88cc --- /dev/null +++ b/openzipkin/prometheus/create-datasource-and-dashboard.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Copyright 2015-2020 The OpenZipkin Authors +# +# Licensed 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. +# + +set -xeuo pipefail + +if ! curl --retry 5 --retry-connrefused --retry-delay 0 -sf http://grafana:3000/api/datasources/name/prom; then + curl -sf -X POST -H "Content-Type: application/json" \ + --data-binary '{"name":"prom","type":"prometheus","url":"http://prometheus:9090","access":"proxy","isDefault":true}' \ + http://grafana:3000/api/datasources +fi + +dashboard_id=1598 +last_revision=$(curl -sf https://grafana.com/api/dashboards/${dashboard_id}/revisions | grep '"revision":' | sed 's/ *"revision": \([0-9]*\),/\1/' | sort -n | tail -1) + +echo '{"dashboard": ' > data.json +curl -s https://grafana.com/api/dashboards/${dashboard_id}/revisions/${last_revision}/download >> data.json +echo ', "inputs": [{"name": "DS_PROMETHEUS", "pluginId": "prometheus", "type": "datasource", "value": "prom"}], "overwrite": false}' >> data.json +curl --retry-connrefused --retry 5 --retry-delay 0 -sf \ + -X POST -H "Content-Type: application/json" \ + --data-binary @data.json \ + http://grafana:3000/api/dashboards/import diff --git a/openzipkin/prometheus/prometheus.yml b/openzipkin/prometheus/prometheus.yml new file mode 100644 index 0000000..3c0c1bc --- /dev/null +++ b/openzipkin/prometheus/prometheus.yml @@ -0,0 +1,13 @@ +global: + scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + - job_name: 'zipkin' + scrape_interval: 5s + metrics_path: '/prometheus' + static_configs: + - targets: ['zipkin:9411'] \ No newline at end of file
