|
| 1 | +<!-- |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright ownership. |
| 6 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | +# (the "License"); you may not use this file except in compliance with |
| 8 | +# the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +--> |
| 19 | + |
| 20 | +[Chinese](skywalking-cn.md) |
| 21 | + |
| 22 | +# Summary |
| 23 | +- [**Summary**](#Summary) |
| 24 | + - [**Name**](#Name) |
| 25 | + - [**Attributes**](#Attributes) |
| 26 | + - [**How To Enable**](#How-To-Enable) |
| 27 | + - [**Test Plugin**](#Test-Plugin) |
| 28 | + - [**Run Skywalking Example**](#Run-Skywalking-Example) |
| 29 | + - [**Disable Plugin**](#Disable-Plugin) |
| 30 | + - [**Upstream services(Code With SpringBoot)**](#Upstream-services(Code-With-SpringBoot)) |
| 31 | + |
| 32 | +## Name |
| 33 | + |
| 34 | +**Skywalking**(https://github.com/apache/skywalking) is an OpenTracing plugin.\ |
| 35 | +The skywalking server can supports both http and grpc protocols . The APISIX client only support http protocols. |
| 36 | +## Attributes |
| 37 | +|Name |Requirement |Description| |
| 38 | +|-------|-------|-------| |
| 39 | +|endpoint|required| the http endpoint of Skywalking ,for example: http://127.0.0.1:12800| |
| 40 | +|sample_ratio|required| the ratio of sample, the minimum is 0.00001, the maximum is 1| |
| 41 | +|service_name|optional| service name for skywalking reporter, the default values is **APISIX**| |
| 42 | + |
| 43 | +## How To Enable |
| 44 | + |
| 45 | +Here's an example, enable the skywalking plugin on the specified route: |
| 46 | + |
| 47 | +```shell |
| 48 | +curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' |
| 49 | +{ |
| 50 | + "methods": ["GET"], |
| 51 | + "uris": [ |
| 52 | + "/uid/*" |
| 53 | + ], |
| 54 | + "plugins": { |
| 55 | + "skywalking": { |
| 56 | + "endpoint": "http://10.110.149.175:12800", |
| 57 | + "sample_ratio": 1, |
| 58 | + "service_name": "APISIX_SERVER" |
| 59 | + } |
| 60 | + }, |
| 61 | + "upstream": { |
| 62 | + "type": "roundrobin", |
| 63 | + "nodes": { |
| 64 | + "10.110.149.175:8089": 1 |
| 65 | + } |
| 66 | + } |
| 67 | +}' |
| 68 | +``` |
| 69 | +You can open dashboard with a browser:`http://127.0.0.1:9080/apisix/dashboard/`,to complete the above operation through the web interface, first add a route:\ |
| 70 | +\ |
| 71 | +Then add skywalking plugin:\ |
| 72 | + |
| 73 | +## Test Plugin |
| 74 | + |
| 75 | +### Run-Skywalking-Example |
| 76 | + |
| 77 | +#### e.g. |
| 78 | +1. Run Skywalking Server: |
| 79 | + - By default,use H2 storage , start skywalking directly |
| 80 | + ``` |
| 81 | + sudo docker run --name skywalking -d -p 1234:1234 -p 11800:11800 -p 12800:12800 --restart always apache/skywalking-oap-server |
| 82 | + ``` |
| 83 | +
|
| 84 | + - Of Course,you can use elasticsearch storage |
| 85 | + 1. Firstly, you should install elasticsearch: |
| 86 | + ``` |
| 87 | + sudo docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 --restart always -e "discovery.type=single-node" elasticsearch:6.7.2 |
| 88 | + ``` |
| 89 | + 2. You can install ElasticSearch management page: elasticsearch-hq(Optional) |
| 90 | + ``` |
| 91 | + sudo docker run -d --name elastic-hq -p 5000:5000 --restart always elastichq/elasticsearch-hq |
| 92 | + ``` |
| 93 | + 3. Run skywalking server: |
| 94 | + ``` |
| 95 | + sudo docker run --name skywalking -d -p 1234:1234 -p 11800:11800 -p 12800:12800 --restart always --link elasticsearch:elasticsearch -e SW_STORAGE=elasticsearch -e SW_STORAGE_ES_CLUSTER_NODES=elasticsearch:9200 apache/skywalking-oap-server |
| 96 | + ``` |
| 97 | +2. Skywalking WebUI: |
| 98 | + 1. Run SkyWalking webUI Server: |
| 99 | + ``` |
| 100 | + sudo docker run --name skywalking-ui -d -p 8080:8080 --link skywalking:skywalking -e SW_OAP_ADDRESS=skywalking:12800 --restart always apache/skywalking-ui |
| 101 | + ``` |
| 102 | + 2. Open the webUI of skywalking: |
| 103 | + You can open dashboard with a browser: http://10.110.149.175:8080 .it will be a successful install as follow: |
| 104 | +  |
| 105 | +
|
| 106 | +3. Test: |
| 107 | + - Access to upstream services through access apisix: |
| 108 | + ```bash |
| 109 | + $ curl -v http://10.110.149.192:9080/uid/12 |
| 110 | + HTTP/1.1 200 OK |
| 111 | + OK |
| 112 | + ... |
| 113 | + ``` |
| 114 | + - Open the webUI of skyWalking: |
| 115 | + ``` |
| 116 | + http://10.110.149.175:8080/ |
| 117 | + ``` |
| 118 | + You can see the topology of all service\ |
| 119 | + \ |
| 120 | + You can also see the tracer of all service\ |
| 121 | +  |
| 122 | +
|
| 123 | +## Disable Plugin |
| 124 | +
|
| 125 | +When you want to disable the skyWalking plugin, it is very simple, |
| 126 | + you can delete the corresponding json configuration in the plugin configuration, |
| 127 | + no need to restart the service, it will take effect immediately: |
| 128 | +
|
| 129 | +```shell |
| 130 | +$ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value=' |
| 131 | +{ |
| 132 | + "methods": ["GET"], |
| 133 | + "uris": [ |
| 134 | + "/uid/*" |
| 135 | + ], |
| 136 | + "plugins": { |
| 137 | + }, |
| 138 | + "upstream": { |
| 139 | + "type": "roundrobin", |
| 140 | + "nodes": { |
| 141 | + "10.110.149.175:8089": 1 |
| 142 | + } |
| 143 | + } |
| 144 | +}' |
| 145 | +``` |
| 146 | + |
| 147 | +The skywalking plugin has been disabled now. It works for other plugins. |
| 148 | + |
| 149 | + |
| 150 | +## Upstream services(Code With SpringBoot) |
| 151 | + |
| 152 | +```java |
| 153 | +package com.lenovo.ai.controller; |
| 154 | + |
| 155 | +import org.springframework.web.bind.annotation.PathVariable; |
| 156 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 157 | +import org.springframework.web.bind.annotation.RestController; |
| 158 | +import javax.servlet.http.HttpServletRequest; |
| 159 | + |
| 160 | +/** |
| 161 | + * @author cyxinda |
| 162 | + * @create 2020-05-29 14:02 |
| 163 | + * @desc skywalking test controller |
| 164 | + **/ |
| 165 | +@RestController |
| 166 | +public class TestController { |
| 167 | + @RequestMapping("/uid/{count}") |
| 168 | + public String getUidList(@PathVariable("count") String countStr, HttpServletRequest request) { |
| 169 | + System.out.println("counter:::::-----"+countStr); |
| 170 | + return "OK"; |
| 171 | + } |
| 172 | +} |
| 173 | +``` |
| 174 | +Configuring the skywalking agent, when starting the service. |
| 175 | +update the file of agent/config/agent.config |
| 176 | +``` |
| 177 | +agent.service_name=yourservername |
| 178 | +collector.backend_service=10.110.149.175:11800 |
| 179 | +``` |
| 180 | +Run the script: |
| 181 | +``` |
| 182 | +nohup java -javaagent:/root/skywalking/app/agent/skywalking-agent.jar \ |
| 183 | +-jar /root/skywalking/app/app.jar \ |
| 184 | +--server.port=8089 \ |
| 185 | +2>&1 > /root/skywalking/app/logs/nohup.log & |
| 186 | +``` |
| 187 | + |
0 commit comments