From 8b3436fc0a6a3589f9c172a6635d894284fc33cc Mon Sep 17 00:00:00 2001 From: Yilia Lin <114121331+Yilialinn@users.noreply.github.com> Date: Thu, 6 Feb 2025 17:33:23 +0800 Subject: [PATCH 1/9] docs: improve public-api plugin docs --- docs/en/latest/plugins/public-api.md | 207 +++++++-------------------- 1 file changed, 48 insertions(+), 159 deletions(-) diff --git a/docs/en/latest/plugins/public-api.md b/docs/en/latest/plugins/public-api.md index 6d1034119cd7..cd4964463aed 100644 --- a/docs/en/latest/plugins/public-api.md +++ b/docs/en/latest/plugins/public-api.md @@ -4,7 +4,7 @@ keywords: - Apache APISIX - API Gateway - Public API -description: The public-api is used for exposing an API endpoint through a general HTTP API router. +description: The `public-api` plugin exposes an internal API endpoint, making it publicly accessible. One of the primary use cases of this plugin is to expose internal endpoints created by other plugins. --- -## Description - -The `public-api` is used for exposing an API endpoint through a general HTTP API router. - -When you are using custom Plugins, you can use the `public-api` Plugin to define a fixed, public API for a particular functionality. For example, you can create a public API endpoint `/apisix/batch-requests` for grouping multiple API requests in one request using the [batch-requests](./batch-requests.md) Plugin. + + + -:::note - -The public API added in a custom Plugin is not exposed by default and the user should manually configure a Route and enable the `public-api` Plugin on it. +## Description -::: +The `public-api` plugin exposes an internal API endpoint, making it publicly accessible. One of the primary use cases of this plugin is to expose internal endpoints created by other plugins. ## Attributes -| Name | Type | Required | Default | Description | -|------|--------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------| -| uri | string | False | "" | URI of the public API. When setting up a Route, use this attribute to configure the original public API URI. | +| Name | Type | Required | Default | Valid Values | Description | +|---------|-----------|----------|---------|--------------|-------------| +| uri | string | False | - | - | Internal endpoint to expose. If not configured, expose the route URI. | -## Example usage +## Example -The example below uses the [batch-requests](./batch-requests.md) Plugin and the [key-auth](./key-auth.md) Plugin along with the `public-api` Plugin. Refer to their documentation for its configuration. This step is omitted below and only explains the configuration of the `public-api` Plugin. +### Expose Prometheus Metrics at Custom Endpoint -### Basic usage +The following example demonstrates how you can disable the Prometheus export server that, by default, exposes an endpoint on port `9091`, and expose APISIX Prometheus metrics on a new public API endpoint on port `9080`, which APISIX uses to listen to other client requests. -You can enable the Plugin on a specific Route as shown below: +You will also configure the route such that the internal endpoint `/apisix/prometheus/metrics` is exposed at a custom endpoint. -```shell -curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r1' \ - -H 'X-API-KEY: ' \ - -H 'Content-Type: application/json' \ - -d '{ - "uri": "/apisix/batch-requests", - "plugins": { - "public-api": {} - } -}' -``` +:::caution -Now, if you make a request to the configured URI, you will receive a batch-requests response: - -```shell -curl --location --request POST 'http://127.0.0.1:9080/apisix/batch-requests' \ ---header 'Content-Type: application/json' \ ---data '{ - "headers": { - "Content-Type": "application/json", - "admin-jwt":"xxxx" - }, - "timeout": 500, - "pipeline": [ - { - "method": "POST", - "path": "/community.GiftSrv/GetGifts", - "body": "test" - }, - { - "method": "POST", - "path": "/community.GiftSrv/GetGifts", - "body": "test2" - } - ] -}' -``` +If a large quantity of metrics is being collected, the plugin could take up a significant amount of CPU resources for metric computations and negatively impact the processing of regular requests. -```shell -[ - { - "status": 200, - "reason": "OK", - "body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}", - "headers": { - "Connection": "keep-alive", - "Date": "Sat, 11 Apr 2020 17:53:20 GMT", - "Content-Type": "application/json", - "Content-Length": "81", - "Server": "APISIX web server" - } - }, - { - "status": 200, - "reason": "OK", - "body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}", - "headers": { - "Connection": "keep-alive", - "Date": "Sat, 11 Apr 2020 17:53:20 GMT", - "Content-Type": "application/json", - "Content-Length": "81", - "Server": "APISIX web server" - } - } -] -``` +To address this issue, APISIX uses [privileged agent](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) and offloads the metric computations to a separate process. This optimization applies automatically if you use the metric endpoint configured in the configuration files, as demonstrated [above](#get-apisix-metrics). If you expose the metric endpoint with the `public-api` plugin, you will not benefit from this optimization. -### Using custom URI +::: -You can also use a custom URI for exposing the API as shown below: +Disable the Prometheus export server in the configuration file and reload APISIX for changes to take effect: -```shell -curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r2' \ - -H 'X-API-KEY: ' \ - -H 'Content-Type: application/json' \ - -d '{ - "uri": "/batch-requests-gifs", - "plugins": { - "public-api": { - "uri": "/apisix/batch-requests" - } - } -}' +```yaml title="conf/config.yaml" +plugin_attr: + prometheus: + enable_export_server: false ``` -Now you can make requests to this new endpoint: +Next, create a route with the `public-api` plugin and expose a public API endpoint for APISIX metrics. You should set the route `uri` to the custom endpoint path and set the plugin `uri` to the internal endpoint to be exposed. ```shell -curl --location --request POST 'http://127.0.0.1:9080/batch-requests-gifs' \ ---header 'Content-Type: application/json' \ ---data '{...}' -``` - -### Securing the Route - -You can use the `key-auth` Plugin to add authentication and secure the Route: - -```shell -curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r2' \ - -H 'X-API-KEY: ' \ - -H 'Content-Type: application/json' \ - -d '{ - "uri": "/batch-requests-gifs", +curl "http://127.0.0.1:9180/apisix/admin/routes/prometheus-metrics" -X PUT \ + -H "X-API-KEY: ${admin_key}" \ + -d '{ + "uri": "/prometheus_metrics", "plugins": { - "public-api": {}, - "key-auth": {} + "public-api": { + "uri": "/apisix/prometheus/metrics" + } } -}' + }' ``` -Now, only authenticated requests are allowed: - -```shell -curl --location --request POST 'http://127.0.0.1:9080/batch-requests-gifs' \ - -H "apikey: test-apikey" - -H 'Content-Type: application/json' \ - --data '{...}' -``` +Send a request to the custom metrics endpoint: ```shell -HTTP/1.1 200 OK +curl "http://127.0.0.1:9080/prometheus_metrics" ``` -The below request will fail: - -```shell -curl --location --request POST 'http://127.0.0.1:9080/batch-requests-gifs' \ - -H 'Content-Type: application/json' \ - --data '{...}' -``` - -```shell -HTTP/1.1 401 Unauthorized -``` - -## Delete Plugin - -To remove the `public-api` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. - -:::note -You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command: - -```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') -``` - -::: - -```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "uri": "/hello", - "upstream": { - "type": "roundrobin", - "nodes": { - "127.0.0.1:1980": 1 - } - } -}' +You should see an output similar to the following: + +```text +# HELP apisix_http_requests_total The total number of client requests since APISIX started +# TYPE apisix_http_requests_total gauge +apisix_http_requests_total 1 +# HELP apisix_nginx_http_current_connections Number of HTTP connections +# TYPE apisix_nginx_http_current_connections gauge +apisix_nginx_http_current_connections{state="accepted"} 1 +apisix_nginx_http_current_connections{state="active"} 1 +apisix_nginx_http_current_connections{state="handled"} 1 +apisix_nginx_http_current_connections{state="reading"} 0 +apisix_nginx_http_current_connections{state="waiting"} 0 +apisix_nginx_http_current_connections{state="writing"} 1 +... ``` From db91fe129b2417e3f487f1fe39cca7427a846b62 Mon Sep 17 00:00:00 2001 From: Yilia Lin <114121331+Yilialinn@users.noreply.github.com> Date: Thu, 6 Feb 2025 17:46:39 +0800 Subject: [PATCH 2/9] Update public-api.md --- docs/en/latest/plugins/public-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/public-api.md b/docs/en/latest/plugins/public-api.md index cd4964463aed..6590d836f27e 100644 --- a/docs/en/latest/plugins/public-api.md +++ b/docs/en/latest/plugins/public-api.md @@ -52,7 +52,7 @@ You will also configure the route such that the internal endpoint `/apisix/prome If a large quantity of metrics is being collected, the plugin could take up a significant amount of CPU resources for metric computations and negatively impact the processing of regular requests. -To address this issue, APISIX uses [privileged agent](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) and offloads the metric computations to a separate process. This optimization applies automatically if you use the metric endpoint configured in the configuration files, as demonstrated [above](#get-apisix-metrics). If you expose the metric endpoint with the `public-api` plugin, you will not benefit from this optimization. +To address this issue, APISIX uses [privileged agent](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) and offloads the metric computations to a separate process. This optimization applies automatically if you use the metric endpoint configured under `plugin_attr.prometheus.export_addr` in the configuration file. If you expose the metric endpoint with the `public-api` plugin, you will not benefit from this optimization. ::: From 375b506a4c271b965f746e8f9166c9c65615b563 Mon Sep 17 00:00:00 2001 From: Yilia Date: Fri, 7 Feb 2025 18:02:52 +0800 Subject: [PATCH 3/9] Update public-api.md --- docs/zh/latest/plugins/public-api.md | 218 ++++++--------------------- 1 file changed, 47 insertions(+), 171 deletions(-) diff --git a/docs/zh/latest/plugins/public-api.md b/docs/zh/latest/plugins/public-api.md index 56abc253237a..982a36f8fce1 100644 --- a/docs/zh/latest/plugins/public-api.md +++ b/docs/zh/latest/plugins/public-api.md @@ -4,7 +4,7 @@ keywords: - APISIX - API 网关 - Public API -description: 本文介绍了 public-api 的相关操作,你可以使用 public-api 插件保护你需要暴露的 API 的端点。 +description: `public-api` 插件公开了一个内部 API 端点,使其可被公开访问。该插件的主要用途之一是公开由其他插件创建的内部端点。 --- -## 描述 - -`public-api` 插件可用于通过创建路由的方式暴露用户自定义的 API。 - -你可以通过在路由中添加 `public-api` 插件,来保护**自定义插件为了实现特定功能**而暴露的 API。例如,你可以使用 [batch-requests](./batch-requests.md) 插件创建一个公共 API 端点 `/apisix/batch-requests` 用于在一个请求中组合多个 API 请求。 + + + -:::note 注意 - -默认情况下,在自定义插件中添加的公共 API 不对外暴露的,你需要手动配置一个路由并启用 `public-api` 插件。 +## 描述 -::: +`public-api` 插件公开了一个内部 API 端点,使其可被公开访问。该插件的主要用途之一是公开由其他插件创建的内部端点。 ## 属性 -| 名称 | 类型 | 必选项 | 默认值 | 描述 | -|------|--------|----------|---------|------------------------------------------------------------| -| uri | string | 否 | "" | 公共 API 的 URI。在设置路由时,使用此属性来配置初始的公共 API URI。 | +| 名称 | 类型 | 必选项 | 默认值 | 描述 | +|------|--------|-------|-------|------| +| uri | string | 否 | - | 内部端点的 URI。如果未配置,则暴露路由的 URI。| -## 启用插件 +## 示例 -`public-api` 插件需要与授权插件一起配合使用,以下示例分别用到了 [batch-requests](./batch-requests.md) 插件和 [`key-auth`](./key-auth.md) +### 在自定义端点暴露 Prometheus 指标 -### 基本用法 +以下示例演示如何禁用默认在端口 `9091` 上暴露端点的 Prometheus 导出服务器,并在 APISIX 用于监听其他客户端请求的端口 `9080` 上,通过新的公共 API 端点暴露 APISIX 的 Prometheus 指标。 -首先,你需要启用并配置 `batch-requests` 插件,详细使用方法请参考 [batch-requests](./batch-requests.md) 插件文档。 +你还将配置路由,使内部端点 `/apisix/prometheus/metrics` 在自定义端点上暴露。 -然后,使用以下命令在指定路由上启用并配置 `public-api` 插件: +:::caution -:::note +如果收集了大量指标,插件可能会占用大量 CPU 资源进行指标计算,并对常规请求的处理产生负面影响。 -您可以这样从 `config.yaml` 中获取 `admin_key` 并存入环境变量: - -```bash -admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g') -``` +为了解决这个问题,APISIX 使用 [特权代理](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) 机制,并将指标计算卸载至独立进程。如果使用配置文件中 `plugin_attr.prometheus.export_addr` 设定的指标端点,该优化将自动生效。但如果通过 `public-api` 插件暴露指标端点,则无法享受此优化。 ::: -```shell -curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r1' \ - -H 'X-API-KEY: ' \ - -H 'Content-Type: application/json' \ - -d '{ - "uri": "/apisix/batch-requests", - "plugins": { - "public-api": {} - } -}' -``` - -**测试插件** - -向配置的 URI 发出访问请求,会返回一个包含多个 API 请求结果的的响应: - -```shell -curl --location --request POST 'http://127.0.0.1:9080/apisix/batch-requests' \ ---header 'Content-Type: application/json' \ ---data '{ - "headers": { - "Content-Type": "application/json", - "admin-jwt":"xxxx" - }, - "timeout": 500, - "pipeline": [ - { - "method": "POST", - "path": "/community.GiftSrv/GetGifts", - "body": "test" - }, - { - "method": "POST", - "path": "/community.GiftSrv/GetGifts", - "body": "test2" - } - ] -}' -``` - -```shell -[ - { - "status": 200, - "reason": "OK", - "body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}", - "headers": { - "Connection": "keep-alive", - "Date": "Sat, 11 Apr 2020 17:53:20 GMT", - "Content-Type": "application/json", - "Content-Length": "81", - "Server": "APISIX web server" - } - }, - { - "status": 200, - "reason": "OK", - "body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}", - "headers": { - "Connection": "keep-alive", - "Date": "Sat, 11 Apr 2020 17:53:20 GMT", - "Content-Type": "application/json", - "Content-Length": "81", - "Server": "APISIX web server" - } - } -] -``` - -### 使用自定义 URI - -首先,你需要启用并配置 `batch-requests` 插件,详细使用方法请参考 [batch-requests](./batch-requests.md) 插件文档。 - -然后,你可以使用一个自定义的 URI 来暴露 API: +在配置文件中禁用 Prometheus 导出服务器,并重新加载 APISIX 以使更改生效: -```shell -curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r2' \ - -H 'X-API-KEY: ' \ - -H 'Content-Type: application/json' \ - -d '{ - "uri": "/batch-requests-gifs", - "plugins": { - "public-api": { - "uri": "/apisix/batch-requests" - } - } -}' -``` - -**测试插件** - -向自定义的 URI 发出访问请求,如果返回一个包含多个 API 请求结果的响应,则代表插件生效: - -```shell -curl --location --request POST 'http://127.0.0.1:9080/batch-requests-gifs' \ ---header 'Content-Type: application/json' \ ---data '{...}' +```yaml +plugin_attr: + prometheus: + enable_export_server: false ``` -### 确保 Route 安全 - -你可以配合使用 `key-auth` 插件来添加认证,从而确保路由的安全: +接下来,创建一个带有 `public-api` 插件的路由,并为 APISIX 指标暴露一个公共 API 端点。你应将路由的 `uri` 设置为自定义端点路径,并将插件的 `uri` 设置为要暴露的内部端点。 ```shell -curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/r2' \ - -H 'X-API-KEY: ' \ - -H 'Content-Type: application/json' \ - -d '{ - "uri": "/batch-requests-gifs", +curl http://127.0.0.1:9180/apisix/admin/routes/prometheus-metrics -X PUT \ + -H 'X-API-KEY: ${admin_key}' \ + -d '{ + "uri": "/prometheus_metrics", "plugins": { - "public-api": {}, - "key-auth": {} + "public-api": { + "uri": "/apisix/prometheus/metrics" + } } -}' -``` - -**测试插件** - -通过上述命令启用插件并添加认证后,只有经过认证的请求才能访问。 - -发出访问请求并指定 `apikey`,如果返回 `200` HTTP 状态码,则说明请求被允许: - -```shell -curl --location --request POST 'http://127.0.0.1:9080/batch-requests-gifs' \ - -H "apikey: test-apikey" - -H 'Content-Type: application/json' \ - --data '{...}' -``` - -```shell -HTTP/1.1 200 OK + }' ``` -发出访问请求,如果返回 `401` HTTP 状态码,则说明请求被阻止,插件生效: - -```shell -curl --location --request POST 'http://127.0.0.1:9080/batch-requests-gifs' \ - -H 'Content-Type: application/json' \ - --data '{...}' -``` +向自定义指标端点发送请求: ```shell -HTTP/1.1 401 Unauthorized +curl http://127.0.0.1:9080/prometheus_metrics ``` -## 删除插件 - -当你需要删除该插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务: - -```shell -curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d ' -{ - "uri": "/hello", - "upstream": { - "type": "roundrobin", - "nodes": { - "127.0.0.1:1980": 1 - } - } -}' +你应看到类似以下的输出: + +```text +# HELP apisix_http_requests_total The total number of client requests since APISIX started +# TYPE apisix_http_requests_total gauge +apisix_http_requests_total 1 +# HELP apisix_nginx_http_current_connections Number of HTTP connections +# TYPE apisix_nginx_http_current_connections gauge +apisix_nginx_http_current_connections{state="accepted"} 1 +apisix_nginx_http_current_connections{state="active"} 1 +apisix_nginx_http_current_connections{state="handled"} 1 +apisix_nginx_http_current_connections{state="reading"} 0 +apisix_nginx_http_current_connections{state="waiting"} 0 +apisix_nginx_http_current_connections{state="writing"} 1 +... ``` From ca536f83ae297073aaebc2ce0bd47943bf13723c Mon Sep 17 00:00:00 2001 From: Yilia Date: Sat, 8 Feb 2025 09:58:55 +0800 Subject: [PATCH 4/9] update --- docs/en/latest/plugins/public-api.md | 12 ++++++------ docs/zh/latest/plugins/public-api.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/en/latest/plugins/public-api.md b/docs/en/latest/plugins/public-api.md index 6590d836f27e..a7ada0371a7f 100644 --- a/docs/en/latest/plugins/public-api.md +++ b/docs/en/latest/plugins/public-api.md @@ -32,13 +32,13 @@ description: The `public-api` plugin exposes an internal API endpoint, making it ## Description -The `public-api` plugin exposes an internal API endpoint, making it publicly accessible. One of the primary use cases of this plugin is to expose internal endpoints created by other plugins. +The `public-api` Plugin exposes an internal API endpoint, making it publicly accessible. One of the primary use cases of this Plugin is to expose internal endpoints created by other Plugins. ## Attributes | Name | Type | Required | Default | Valid Values | Description | |---------|-----------|----------|---------|--------------|-------------| -| uri | string | False | - | - | Internal endpoint to expose. If not configured, expose the route URI. | +| uri | string | False | - | - | Internal endpoint to expose. If not configured, expose the Route URI. | ## Example @@ -46,13 +46,13 @@ The `public-api` plugin exposes an internal API endpoint, making it publicly acc The following example demonstrates how you can disable the Prometheus export server that, by default, exposes an endpoint on port `9091`, and expose APISIX Prometheus metrics on a new public API endpoint on port `9080`, which APISIX uses to listen to other client requests. -You will also configure the route such that the internal endpoint `/apisix/prometheus/metrics` is exposed at a custom endpoint. +You will also configure the Route such that the internal endpoint `/apisix/prometheus/metrics` is exposed at a custom endpoint. :::caution -If a large quantity of metrics is being collected, the plugin could take up a significant amount of CPU resources for metric computations and negatively impact the processing of regular requests. +If a large quantity of metrics is being collected, the Plugin could take up a significant amount of CPU resources for metric computations and negatively impact the processing of regular requests. -To address this issue, APISIX uses [privileged agent](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) and offloads the metric computations to a separate process. This optimization applies automatically if you use the metric endpoint configured under `plugin_attr.prometheus.export_addr` in the configuration file. If you expose the metric endpoint with the `public-api` plugin, you will not benefit from this optimization. +To address this issue, APISIX uses [privileged agent](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) and offloads the metric computations to a separate process. This optimization applies automatically if you use the metric endpoint configured under `plugin_attr.prometheus.export_addr` in the configuration file. If you expose the metric endpoint with the `public-api` Plugin, you will not benefit from this optimization. ::: @@ -64,7 +64,7 @@ plugin_attr: enable_export_server: false ``` -Next, create a route with the `public-api` plugin and expose a public API endpoint for APISIX metrics. You should set the route `uri` to the custom endpoint path and set the plugin `uri` to the internal endpoint to be exposed. +Next, create a Route with the `public-api` Plugin and expose a public API endpoint for APISIX metrics. You should set the Route `uri` to the custom endpoint path and set the Plugin `uri` to the internal endpoint to be exposed. ```shell curl "http://127.0.0.1:9180/apisix/admin/routes/prometheus-metrics" -X PUT \ diff --git a/docs/zh/latest/plugins/public-api.md b/docs/zh/latest/plugins/public-api.md index 982a36f8fce1..dd60addb71d3 100644 --- a/docs/zh/latest/plugins/public-api.md +++ b/docs/zh/latest/plugins/public-api.md @@ -36,9 +36,9 @@ description: `public-api` 插件公开了一个内部 API 端点,使其可被 ## 属性 -| 名称 | 类型 | 必选项 | 默认值 | 描述 | -|------|--------|-------|-------|------| -| uri | string | 否 | - | 内部端点的 URI。如果未配置,则暴露路由的 URI。| +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +|------|--------|-------|-------|------|------| +| uri | string | 否 | - | - | 内部端点的 URI。如果未配置,则暴露路由的 URI。| ## 示例 @@ -46,13 +46,13 @@ description: `public-api` 插件公开了一个内部 API 端点,使其可被 以下示例演示如何禁用默认在端口 `9091` 上暴露端点的 Prometheus 导出服务器,并在 APISIX 用于监听其他客户端请求的端口 `9080` 上,通过新的公共 API 端点暴露 APISIX 的 Prometheus 指标。 -你还将配置路由,使内部端点 `/apisix/prometheus/metrics` 在自定义端点上暴露。 +此外,还会配置路由,使内部端点 `/apisix/prometheus/metrics` 通过自定义端点对外公开。 :::caution -如果收集了大量指标,插件可能会占用大量 CPU 资源进行指标计算,并对常规请求的处理产生负面影响。 +如果收集了大量指标,插件可能会占用大量 CPU 资源用于计算,从而影响正常请求的处理。 -为了解决这个问题,APISIX 使用 [特权代理](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) 机制,并将指标计算卸载至独立进程。如果使用配置文件中 `plugin_attr.prometheus.export_addr` 设定的指标端点,该优化将自动生效。但如果通过 `public-api` 插件暴露指标端点,则无法享受此优化。 +为了解决这个问题,APISIX 使用 [特权代理进程](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/process.md#enable_privileged_agent) ,并将指标计算卸载至独立进程。如果使用配置文件中 `plugin_attr.prometheus.export_addr` 设定的指标端点,该优化将自动生效。但如果通过 `public-api` 插件暴露指标端点,则不会受益于此优化。 ::: From 6235b1aec919c57f27851beecab4d442342528f7 Mon Sep 17 00:00:00 2001 From: Yilia Lin <114121331+Yilialinn@users.noreply.github.com> Date: Sat, 8 Feb 2025 11:33:59 +0800 Subject: [PATCH 5/9] fix comment --- docs/en/latest/plugins/public-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/public-api.md b/docs/en/latest/plugins/public-api.md index a7ada0371a7f..ed4e0ef93101 100644 --- a/docs/en/latest/plugins/public-api.md +++ b/docs/en/latest/plugins/public-api.md @@ -4,7 +4,7 @@ keywords: - Apache APISIX - API Gateway - Public API -description: The `public-api` plugin exposes an internal API endpoint, making it publicly accessible. One of the primary use cases of this plugin is to expose internal endpoints created by other plugins. +description: The public-api plugin exposes an internal API endpoint, making it publicly accessible. One of the primary use cases of this plugin is to expose internal endpoints created by other plugins. ---