You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/02 08:34:45 UTC

[GitHub] [apisix] membphis commented on a change in pull request #2926: feat: server info

membphis commented on a change in pull request #2926:
URL: https://github.com/apache/apisix/pull/2926#discussion_r533981132



##########
File path: doc/plugins/server-info.md
##########
@@ -0,0 +1,115 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+- [中文](../zh-cn/plugins/server-info.md)
+
+# Summary
+
+- [**Name**](#name)
+- [**Attributes**](#attributes)
+- [**API**](#api)
+- [**How To Enable**](#how-to-enable)
+- [**Test Plugin**](#test-plugin)
+- [**Disable Plugin**](#disable-plugin)
+
+## Name
+
+`server-info` is a plugin that reports basic server information to etcd periodically and allows us to get them in the data plane through it's API.
+
+## Attributes
+
+None
+
+## API
+
+This plugin now exposes only one API `/apisix/server_info` to get basic server information.
+You may need to use [interceptors](../plugin-interceptors.md) to protect it.
+
+
+## How to Enable
+
+Just configure `server-info` in the plugin list of the configuration file `conf/config.yaml`.
+
+```
+plugins:                          # plugin list
+  - example-plugin
+  - limit-req
+  - node-status
+  - server-info
+  - jwt-auth
+  - zipkin
+  ......
+```
+
+After starting APISIX and accessing `/apisix/server_info` then you can get server information.
+
+## How to customize the server info report interval
+
+We can change the report interval in the `plugin_attr` section of `conf/config.yaml`.
+
+| Name         | Type   | Default  | Description                                                          |
+| ------------ | ------ | -------- | -------------------------------------------------------------------- |
+| report_interval | number | 60 | the interval (unit: second) to report server info to etcd.              |
+
+Here is an example, which modifies the report interval to 10 seconds.
+
+```yaml
+plugin_attr:
+  server-info:
+    report_interval: 10
+```
+
+## Test Plugin
+
+```bash
+curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq

Review comment:
       the URI should be `/apisix/server_info`

##########
File path: apisix/plugins/server-info.lua
##########
@@ -0,0 +1,274 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local require = require
+local core = require("apisix.core")
+
+local ngx_time = ngx.time
+local ngx_timer_at = ngx.timer.at
+local ngx_worker_id = ngx.worker.id
+local type = type
+
+local plugin_name = "server-info"
+local boot_time = os.time()
+local current_timer
+local schema = {
+    type = "object",
+    additionalProperties = false,
+}
+local attr_schema = {
+    type = "object",
+    properties = {
+        report_interval = {
+            type = "integer",
+            description = "server info reporting interval (unit: second)",
+            default = 60,
+            minimum = 5,

Review comment:
       need to specify a maximum value

##########
File path: doc/zh-cn/plugins/server-info.md
##########
@@ -0,0 +1,116 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+- [English](../../plugins/server-info.md)
+
+# Summary
+
+- [**插件简介**](#插件简介)
+- [插件属性](#插件属性)
+- [**插件接口**](#插件接口)
+- [启用插件](#启用插件)
+- [如何自定义服务信息上报间隔](#如何自定义服务信息上报间隔)
+- [测试插件](#测试插件)
+- [禁用插件](#禁用插件)
+
+## 插件简介
+
+`server-info` 是一款能够定期将服务基本信息上报至 etcd,同时允许我们通过它提供的 API 在数据面访问到这些数据的插件。
+
+## 插件属性
+
+无
+
+## 插件接口
+
+此插件提供了接口 `/apisix/server_info`,可以通过 [interceptors](../plugin-interceptors.md) 来保护该接口。
+
+## 启用插件
+
+在配置文件 `apisix/conf/config.yaml` 的插件列表中添加 `server-info`, 即可启用该插件。
+
+```
+plugins:                          # plugin list
+  - example-plugin
+  - limit-req
+  - node-status
+  - server-info
+  - jwt-auth
+  - zipkin
+  ......
+```
+
+在启动 APISIX 之后,即可通过访问 `/apisix/server_info` 来获取服务基本信息。
+
+## 如何自定义服务信息上报间隔
+
+我们可以在 `conf/config.yaml` 文件的 `plugin_attr` 一节中修改上报间隔。
+
+| 名称         | 类型   | 默认值  | 描述                                                          |
+| ------------ | ------ | -------- | -------------------------------------------------------------------- |
+| report_interval | number | 60 | 上报服务信息至 etcd 的间隔(单位:秒)|
+
+下面的例子将服务信息上报间隔修改成了 10 秒:
+
+```yaml
+plugin_attr:
+  server-info:
+    report_interval: 10
+```
+
+
+## 测试插件
+
+```bash
+curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq

Review comment:
       ditto




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org