This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new c8c24de feat: optimize skywalking instancename (#4069)
c8c24de is described below
commit c8c24deca40d8a2efe1a3c25ada24f40b1cdd995
Author: seven dickens <[email protected]>
AuthorDate: Mon Apr 26 13:14:29 2021 +0800
feat: optimize skywalking instancename (#4069)
---
apisix/plugins/skywalking.lua | 5 +++++
docs/en/latest/plugins/skywalking.md | 6 +++---
docs/zh/latest/plugins/skywalking.md | 6 +++---
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/apisix/plugins/skywalking.lua b/apisix/plugins/skywalking.lua
index 14b1323..2cf99c3 100644
--- a/apisix/plugins/skywalking.lua
+++ b/apisix/plugins/skywalking.lua
@@ -129,6 +129,11 @@ function _M.init()
-- TODO: maybe need to fetch them from plugin-metadata
local metadata_shdict = ngx.shared.tracing_buffer
+
+ if local_plugin_info.service_instance_name == "$hostname" then
+ local_plugin_info.service_instance_name = core.utils.gethostname()
+ end
+
metadata_shdict:set('serviceName', local_plugin_info.service_name)
metadata_shdict:set('serviceInstanceName',
local_plugin_info.service_instance_name)
diff --git a/docs/en/latest/plugins/skywalking.md
b/docs/en/latest/plugins/skywalking.md
index b496b84..d72a8de 100644
--- a/docs/en/latest/plugins/skywalking.md
+++ b/docs/en/latest/plugins/skywalking.md
@@ -90,9 +90,9 @@ We can set the endpoint by specified 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 |
-| 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 |
+| 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:
diff --git a/docs/zh/latest/plugins/skywalking.md
b/docs/zh/latest/plugins/skywalking.md
index ec5acb6..daa0cc8 100644
--- a/docs/zh/latest/plugins/skywalking.md
+++ b/docs/zh/latest/plugins/skywalking.md
@@ -94,9 +94,9 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H
'X-API-KEY: edd1c9f034335f1
| 名称 | 类型 | 默认值 | 描述
|
| ------------ | ------ | -------- |
----------------------------------------------------- |
| service_name | string | "APISIX" | skywalking 上报的 service 名称
|
-|service_instance_name|string| "APISIX Instance Name" | skywalking 上报的 service
实例名 |
-| endpoint_addr| string | "http://127.0.0.1:12800" | Skywalking 的 HTTP
endpoint 地址,例如:http://127.0.0.1:12800 |
-| report_interval| integer | 使用 skywalking 客户端内置的值 | 上报时间间隔,单位是秒|
+| service_instance_name | string | "APISIX Instance Name" | skywalking 上报的
service 实例名, 如果期望直接获取本机主机名则设置为 `$hostname` |
+| endpoint_addr | string | "http://127.0.0.1:12800" | Skywalking 的 HTTP
endpoint 地址,例如:http://127.0.0.1:12800 |
+| report_interval | integer | 使用 skywalking 客户端内置的值 | 上报时间间隔,单位是秒|
配置示例: