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

NameTypeRequirementDefaultValidDescription
sample_rationumberrequired1[0.00001, 1]the ratio of sampling

How To Enable

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

  1. # Add this in config.yaml
  2. plugins:
  3. - ... # plugin you need
  4. - 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:

  1. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "methods": ["GET"],
  4. "uris": [
  5. "/uid/*"
  6. ],
  7. "plugins": {
  8. "skywalking": {
  9. "sample_ratio": 1
  10. }
  11. },
  12. "upstream": {
  13. "type": "roundrobin",
  14. "nodes": {
  15. "10.110.149.175:8089": 1
  16. }
  17. }
  18. }'

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.

NameTypeDefaultDescription
service_namestring“APISIX”service name for SkyWalking reporter
service_instance_namestring“APISIX Instance Name”service instance name for SkyWalking reporter, set it to $hostname to get local hostname directly.
endpoint_addrstringhttp://127.0.0.1:12800”the HTTP endpoint of SkyWalking, for example: http://127.0.0.1:12800
report_intervalintegeruse the value in the SkyWalking client librarythe report interval, in seconds

Here is an example:

  1. plugin_attr:
  2. skywalking:
  3. service_name: APISIX
  4. service_instance_name: "APISIX Instance Name"
  5. 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

      1. 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:

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

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

        1. 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:

      1. 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:

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

      1. 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:

  1. $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "methods": ["GET"],
  4. "uris": [
  5. "/uid/*"
  6. ],
  7. "plugins": {
  8. },
  9. "upstream": {
  10. "type": "roundrobin",
  11. "nodes": {
  12. "10.110.149.175:8089": 1
  13. }
  14. }
  15. }'

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:

  1. plugins:
  2. - ... # plugin you need
  3. #- skywalking

And then reload APISIX.

Upstream services(Code With SpringBoot)

  1. import org.springframework.web.bind.annotation.PathVariable;
  2. import org.springframework.web.bind.annotation.RequestMapping;
  3. import org.springframework.web.bind.annotation.RestController;
  4. import javax.servlet.http.HttpServletRequest;
  5. @RestController
  6. public class TestController {
  7. @RequestMapping("/uid/{count}")
  8. public String getUidList(@PathVariable("count") String countStr, HttpServletRequest request) {
  9. return "OK";
  10. }
  11. }

Configure the SkyWalking agent when starting the service.

Update the file of agent/config/agent.config

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

Run the script:

  1. nohup java -javaagent:/root/skywalking/app/agent/skywalking-agent.jar \
  2. -jar /root/skywalking/app/app.jar \
  3. --server.port=8089 \
  4. 2>&1 > /root/skywalking/app/logs/nohup.log &