Skip to content

Commit 81519f3

Browse files
authored
doc: add skywalking plugin instructions (#1636)
1 parent 82f85e5 commit 81519f3

File tree

7 files changed

+379
-0
lines changed

7 files changed

+379
-0
lines changed

doc/images/plugin/skywalking-1.png

21.7 KB
Loading

doc/images/plugin/skywalking-2.png

29.9 KB
Loading

doc/images/plugin/skywalking-3.png

61.1 KB
Loading

doc/images/plugin/skywalking-4.png

29.6 KB
Loading

doc/images/plugin/skywalking-5.png

48.4 KB
Loading

doc/plugins/skywalking-cn.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
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+
[English](skywalking.md)
21+
22+
# 目录
23+
- [目录](#目录)
24+
- [名字](#名字)
25+
- [属性](#属性)
26+
- [如何启用](#如何启用)
27+
- [测试插件](#测试插件)
28+
- [运行 Skywalking 实例](#运行-Skywalking-实例)
29+
- [禁用插件](#禁用插件)
30+
- [上游服务是java的SpringBoot示例代码](#上游服务是java的SpringBoot示例代码)
31+
32+
## 名字
33+
34+
`Skywalking`(https://github.com/apache/skywalking) 是一个开源的服务跟踪插件。
35+
36+
服务端目前支持http和grpc两种协议,在apisix中目前只支持http协议
37+
38+
## 属性
39+
40+
* `endpoint`: Skywalking 的 http 节点,例如`http://127.0.0.1:12800`
41+
* `sample_ratio`: 监听的比例,最小为0.00001,最大为1。
42+
* `service_name`: 可选参数,标记当前服务的名称,默认值是`APISIX`
43+
44+
## 如何启用
45+
46+
下面是一个示例,在指定的 route 上开启了 skywalking 插件:
47+
48+
```shell
49+
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
50+
{
51+
"methods": ["GET"],
52+
"uris": [
53+
"/uid/*"
54+
],
55+
"plugins": {
56+
"skywalking": {
57+
"endpoint": "http://10.110.149.175:12800",
58+
"sample_ratio": 1,
59+
"service_name": "APISIX_SERVER"
60+
}
61+
},
62+
"upstream": {
63+
"type": "roundrobin",
64+
"nodes": {
65+
"10.110.149.175:8089": 1
66+
}
67+
}
68+
}'
69+
```
70+
71+
你可以使用浏览器打开 dashboard:`http://127.0.0.1:9080/apisix/dashboard/`,通过 web 界面来完成上面的操作,先增加一个 route:
72+
73+
![](../images/plugin/skywalking-1.png)
74+
75+
然后在 route 页面中添加 skywalking 插件:
76+
77+
![](../images/plugin/skywalking-2.png)
78+
79+
## 测试插件
80+
81+
### 运行 Skywalking 实例
82+
83+
#### 例子:
84+
1. 启动Skywalking Server:
85+
- 默认使用H2存储,直接启动skywalking即可
86+
```
87+
sudo docker run --name skywalking -d -p 1234:1234 -p 11800:11800 -p 12800:12800 --restart always apache/skywalking-oap-server
88+
```
89+
90+
- 如果使用elasticsearch存储
91+
1. 则需要先安装elasticsearch:
92+
```
93+
sudo docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 --restart always -e "discovery.type=single-node" elasticsearch:6.7.2
94+
95+
```
96+
2. 安装 ElasticSearch管理界面elasticsearch-hq
97+
```
98+
sudo docker run -d --name elastic-hq -p 5000:5000 --restart always elastichq/elasticsearch-hq
99+
```
100+
3. 启动skywalking:
101+
```
102+
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
103+
```
104+
2. Skywalking管理系统:
105+
1. 启动管理系统:
106+
```
107+
sudo docker run --name skywalking-ui -d -p 8080:8080 --link skywalking:skywalking -e SW_OAP_ADDRESS=skywalking:12800 --restart always apache/skywalking-ui
108+
```
109+
2. 打开管理页面
110+
在浏览器里面输入http://10.110.149.175:8080,出现了如下界面,则表示安装成功
111+
![](../images/plugin/skywalking-3.png)
112+
113+
3. 测试示例:
114+
- 通过访问apisix,访问上游服务
115+
116+
```bash
117+
$ curl -v http://10.110.149.192:9080/uid/12
118+
HTTP/1.1 200 OK
119+
OK
120+
...
121+
```
122+
- 打开浏览器,访问 Skywalking 的 web 页面:
123+
```
124+
http://10.110.149.175:8080/
125+
```
126+
可以看到访问拓扑图\
127+
![](../../doc/images/plugin/skywalking-4.png)\
128+
可以看到服务追踪图\
129+
![](../../doc/images/plugin/skywalking-5.png)
130+
## 禁用插件
131+
132+
当你想去掉插件的时候,很简单,在插件的配置中把对应的 json 配置删除即可,无须重启服务,即刻生效:
133+
134+
```shell
135+
$ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value='
136+
{
137+
"methods": ["GET"],
138+
"uris": [
139+
"/uid/*"
140+
],
141+
"plugins": {
142+
},
143+
"upstream": {
144+
"type": "roundrobin",
145+
"nodes": {
146+
"10.110.149.175:8089": 1
147+
}
148+
}
149+
}'
150+
```
151+
152+
现在就已经移除了 Skywalking 插件了。其他插件的开启和移除也是同样的方法。
153+
154+
155+
## 上游服务是java的SpringBoot示例代码
156+
157+
```java
158+
package com.lenovo.ai.controller;
159+
160+
import org.springframework.web.bind.annotation.PathVariable;
161+
import org.springframework.web.bind.annotation.RequestMapping;
162+
import org.springframework.web.bind.annotation.RestController;
163+
import javax.servlet.http.HttpServletRequest;
164+
165+
/**
166+
* @author cyxinda
167+
* @create 2020-05-29 14:02
168+
* @desc skywalking测试中央控制层
169+
**/
170+
@RestController
171+
public class TestController {
172+
@RequestMapping("/uid/{count}")
173+
public String getUidList(@PathVariable("count") String countStr, HttpServletRequest request) {
174+
System.out.println("counter:::::"+countStr);
175+
return "OK";
176+
}
177+
}
178+
```
179+
启动服务的时候,需要配置skywalking agent,
180+
修改agent/config/agent.config中的配置
181+
```
182+
agent.service_name=yourservername
183+
collector.backend_service=10.110.149.175:11800
184+
```
185+
启动服务脚本:
186+
```
187+
nohup java -javaagent:/root/skywalking/app/agent/skywalking-agent.jar \
188+
-jar /root/skywalking/app/app.jar \
189+
--server.port=8089 \
190+
2>&1 > /root/skywalking/app/logs/nohup.log &
191+
```
192+

doc/plugins/skywalking.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
![](../images/plugin/skywalking-1.png)\
71+
Then add skywalking plugin:\
72+
![](../images/plugin/skywalking-2.png)
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+
![](../images/plugin/skywalking-3.png)
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+
![](../../doc/images/plugin/skywalking-4.png)\
120+
You can also see the tracer of all service\
121+
![](../../doc/images/plugin/skywalking-5.png)
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

Comments
 (0)