115 Star 698 Fork 166

GVPiresty / Apache APISIX

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
skywalking.md 7.39 KB
一键复制 编辑 原始数据 按行查看 历史
kwanhur 提交于 2022-03-13 19:49 . docs: unify plugin Description (#6532)
title
skywalking

Description

SkyWalking uses its native Nginx LUA tracer to provide tracing, topology analysis, and metrics from service and URI perspective.

The SkyWalking server can support both HTTP and gRPC protocols. Currently, the APISIX client only supports the HTTP protocol.

Attributes

Name Type Requirement Default Valid Description
sample_ratio number required 1 [0.00001, 1] the ratio of sampling

How To Enable

First of all, enable the SkyWalking plugin in the config.yaml:

# Add this in config.yaml
plugins:
  - ... # plugin you need
  - skywalking

Then reload APISIX, a background timer will be created to report data to the SkyWalking OAP server.

Here's an example, enable the SkyWalking plugin on the specified route:

curl http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "methods": ["GET"],
    "uris": [
        "/uid/*"
    ],
    "plugins": {
        "skywalking": {
            "sample_ratio": 1
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "10.110.149.175:8089": 1
        }
    }
}'

You also can complete the above operation through the web interface, first add a route, then add SkyWalking plugin:

How to set endpoint

We can set the endpoint by specifying the configuration in conf/config.yaml.

Name Type Default Description
service_name string "APISIX" service name for SkyWalking reporter
service_instance_name string "APISIX Instance Name" service instance name for SkyWalking reporter, set it to $hostname to get local hostname directly.
endpoint_addr string "http://127.0.0.1:12800" the HTTP endpoint of SkyWalking, for example: http://127.0.0.1:12800
report_interval integer use the value in the SkyWalking client library the report interval, in seconds

Here is an example:

plugin_attr:
  skywalking:
    service_name: APISIX
    service_instance_name: "APISIX Instance Name"
    endpoint_addr: http://127.0.0.1:12800

Test Plugin

Run SkyWalking Example

  1. Start the SkyWalking OAP Server:

    • By default, SkyWalking uses H2 storage, start SkyWalking directly by

      sudo docker run --name skywalking -d -p 1234:1234 -p 12800:12800 --restart always apache/skywalking-oap-server:8.7.0-es6
    • Of Course, you may want to use Elasticsearch storage instead

      1. First, you should install Elasticsearch:

        sudo docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 --restart always -e "discovery.type=single-node" elasticsearch:6.7.2
      2. Optionally, you can install ElasticSearch management page: elasticsearch-hq

        sudo docker run -d --name elastic-hq -p 5000:5000 --restart always elastichq/elasticsearch-hq
      3. Finally, run SkyWalking OAP server:

        sudo docker run --name skywalking -d -p 1234:1234 -p 12800:12800 --restart always --link elasticsearch:elasticsearch -e SW_STORAGE=elasticsearch -e SW_STORAGE_ES_CLUSTER_NODES=elasticsearch:9200 apache/skywalking-oap-server:8.7.0-es6
  2. SkyWalking Web UI:

    1. Run SkyWalking web UI Server:

      sudo docker run --name skywalking-ui -d -p 8080:8080 --link skywalking:skywalking -e SW_OAP_ADDRESS=skywalking:12800 --restart always apache/skywalking-ui
    2. Access the web UI of SkyWalking: You can access the dashboard from a browser: http://10.110.149.175:8080 It will show the following if the installation is successful.

  3. Test:

    • Access to upstream services through accessing APISIX:

      $ curl -v http://10.110.149.192:9080/uid/12
      HTTP/1.1 200 OK
      OK
      ...
    • Open the web UI of SkyWalking:

      http://10.110.149.175:8080/

      You can see the topology of all services

      You can also see the traces from all services

Disable Plugin

When you want to disable the SkyWalking plugin on a route/service, it is very simple, you can delete the corresponding JSON configuration in the plugin configuration, no need to restart the service, it will take effect immediately:

$ curl http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "methods": ["GET"],
    "uris": [
        "/uid/*"
    ],
    "plugins": {
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "10.110.149.175:8089": 1
        }
    }
}'

The SkyWalking plugin has been disabled now. The step works in the same fashion for other plugins.

If you want to completely disable the SkyWalking plugin, for example, stopping the background report timer, you will need to comment out the plugin in the config.yaml:

plugins:
  - ... # plugin you need
  #- skywalking

And then reload APISIX.

Upstream services(Code With SpringBoot)

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

@RestController
public class TestController {
    @RequestMapping("/uid/{count}")
    public String getUidList(@PathVariable("count") String countStr, HttpServletRequest request) {
       return "OK";
    }
}

Configure the SkyWalking agent when starting the service.

Update the file of agent/config/agent.config

agent.service_name=yourservername
collector.backend_service=10.110.149.175:11800

Run the script:

nohup java -javaagent:/root/skywalking/app/agent/skywalking-agent.jar \
-jar /root/skywalking/app/app.jar \
--server.port=8089 \
2>&1 > /root/skywalking/app/logs/nohup.log &
Lua
1
https://gitee.com/iresty/apisix.git
git@gitee.com:iresty/apisix.git
iresty
apisix
Apache APISIX
master

搜索帮助