Re: [PR] docs: update plugin docs with ADC and Ingress Controller examples [apisix]
Yilialinn merged PR #13336: URL: https://github.com/apache/apisix/pull/13336 -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] docs: update plugin docs with ADC and Ingress Controller examples [apisix]
kayx23 commented on code in PR #13336: URL: https://github.com/apache/apisix/pull/13336#discussion_r3212840373 ## docs/en/latest/plugins/aws-lambda.md: ## @@ -200,46 +477,186 @@ Next, select **Create resource** to create a sub-path: Enter the sub-path information and complete creation: - + +https://static.api7.ai/uploads/2024/04/26/7t1yiWjl_create-resource-2.png"; + alt="complete resource creation" + width="70%" +/> + Once redirected back to the main gateway console, you should see the newly created path. Select **Create method** to configure HTTP methods for the path and the associated action:  Select the allowed HTTP method in the dropdown. For the purpose of demonstration, this example continues to use the same Lambda function as the triggered action when the path is requested: - + +https://static.api7.ai/uploads/2024/04/26/vni7yS2q_create%20method%202.png"; + alt="create method and lambda function" + width="70%" +/> Review Comment: The new sub-path walkthrough still only matches `/aws-lambda` in the ADC, Gateway API, and APISIX CRD examples, but the verification step sends `GET /aws-lambda/api7-docs`. That request will never hit those routes as written, so the example is broken outside the Admin API tab. These variants need a prefix/wildcard match (for example `/aws-lambda/*` or the equivalent controller syntax) to actually demonstrate sub-path forwarding. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] docs: update plugin docs with ADC and Ingress Controller examples [apisix]
Copilot commented on code in PR #13336:
URL: https://github.com/apache/apisix/pull/13336#discussion_r3212777606
##
docs/en/latest/plugins/serverless.md:
##
@@ -87,37 +83,877 @@ admin_key=$(yq '.deployment.admin.admin_key[0].key'
conf/config.yaml | sed 's/"/
:::
-The following example enables `serverless-pre-function` and
`serverless-post-function` Plugins on a Route:
+The examples below demonstrate how you can configure the
`serverless-pre-function` and `serverless-post-function` plugins for different
scenarios.
+
+### Log Information before and after a Phase
+
+The example below demonstrates how you can configure the serverless plugins to
execute custom logics to log information to error logs before and after the
`rewrite` [phase](../terminology/plugin.md#plugins-execution-lifecycle).
+
+Create a Route as such:
+
+
Review Comment:
`` / `` are used but this page does not import them, which
will cause MDX compilation errors in Docusaurus. Add the standard imports
(`Tabs` and `TabItem` from `@theme/*`) near the top of the file (typically
right after the `` block), as done in other plugin docs (e.g.
`docs/en/latest/plugins/basic-auth.md`).
##
docs/en/latest/plugins/aws-lambda.md:
##
@@ -95,16 +95,31 @@ To create the Lambda function URL, go to the
**Configuration** tab of the Lambda
Finally, create a Route in APISIX with your function URL and IAM access keys:
+
Review Comment:
`` / `` are used but this page does not import them, which
will cause MDX compilation errors in Docusaurus. Add the standard imports near
the top of the file (right after the `` block).
##
docs/zh/latest/plugins/aws-lambda.md:
##
@@ -89,26 +89,37 @@ admin_key=$(yq '.deployment.admin.admin_key[0].key'
conf/config.yaml | sed 's/"/

-要创建 Lambda 函数 URL,请前往 Lambda 函数的 **配置** 标签页,在 **函数 URL** 下创建函数 URL:
+要创建 Lambda 函数 URL,请前往 Lambda 函数的 **配置** 标签页,在 **函数 URL** 下创建函数 URL:

最后,在 APISIX 中使用函数 URL 和 IAM 访问密钥创建路由:
+
Review Comment:
`` / `` are used but this page does not import them, which
will cause MDX compilation errors in Docusaurus. Add the standard imports near
the top (right after the `` block).
##
docs/zh/latest/plugins/public-api.md:
##
@@ -60,17 +70,28 @@ description: public-api 插件公开了一个内部 API 端点,使其可被公
在配置文件中禁用 Prometheus 导出服务器,并重新加载 APISIX 以使更改生效:
-```yaml
+```yaml title="conf/config.yaml"
plugin_attr:
prometheus:
enable_export_server: false
```
-接下来,创建一个带有 `public-api` 插件的路由,并为 APISIX 指标暴露一个公共 API 端点。你应将路由的 `uri`
设置为自定义端点路径,并将插件的 `uri` 设置为要暴露的内部端点。
+接下来,创建一个带有 `public-api` 插件的路由,并为 APISIX 指标暴露一个公共 API 端点:
+
+
Review Comment:
`` / `` are used but this page does not import them, which
will cause MDX compilation errors in Docusaurus. Add the standard imports near
the top (right after the `` block).
##
docs/en/latest/plugins/aws-lambda.md:
##
@@ -95,16 +95,31 @@ To create the Lambda function URL, go to the
**Configuration** tab of the Lambda
Finally, create a Route in APISIX with your function URL and IAM access keys:
+
+
+
+
```shell
curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
-H "X-API-KEY: ${admin_key}" \
-d '{
-"id": "aws-lambda-iam-route",
+"id": "aws-lambda-route",
Review Comment:
All three scenarios on this page use the same Route id (`aws-lambda-route`).
If a user follows multiple examples, they will overwrite the same Route, which
is confusing and makes it hard to compare configurations. Use distinct Route
ids per scenario (e.g., `aws-lambda-iam-route`, `aws-lambda-apikey-route`,
`aws-lambda-subpath-route`) or explicitly call out that later examples
overwrite the earlier Route.
##
docs/zh/latest/plugins/aws-lambda.md:
##
@@ -89,26 +89,37 @@ admin_key=$(yq '.deployment.admin.admin_key[0].key'
conf/config.yaml | sed 's/"/

-要创建 Lambda 函数 URL,请前往 Lambda 函数的 **配置** 标签页,在 **函数 URL** 下创建函数 URL:
+要创建 Lambda 函数 URL,请前往 Lambda 函数的 **配置** 标签页,在 **函数 URL** 下创建函数 URL:

最后,在 APISIX 中使用函数 URL 和 IAM 访问密钥创建路由:
+
+
+
+
```shell
curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
-H "X-API-KEY: ${admin_key}" \
-d '{
-"id": "aws-lambda-iam-route",
+"id": "aws-lambda-route",
Review Comment:
本页面的多个示例都使用相同的路由
id(`aws-lambda-route`)。如果读者按顺序操作,不同场景会相互覆盖同一路由,容易造成困惑。建议为不同场景使用不同的路由
id,或在文中明确说明后续示例会覆盖前一个路由。
##
docs/zh/latest/plugins/public-api.md:
##
@@ -126,8 +265,132 @@ curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
}'
```
+
+
+
+
+```yaml title="adc.yaml"
+services:
+ - name: h
Re: [PR] docs: update plugin docs with ADC and Ingress Controller examples [apisix]
Copilot commented on code in PR #13336:
URL: https://github.com/apache/apisix/pull/13336#discussion_r3199158691
##
docs/en/latest/plugins/serverless.md:
##
@@ -87,37 +83,958 @@ admin_key=$(yq '.deployment.admin.admin_key[0].key'
conf/config.yaml | sed 's/"/
:::
-The following example enables `serverless-pre-function` and
`serverless-post-function` Plugins on a Route:
+The examples below demonstrate how you can configure the
`serverless-pre-function` and `serverless-post-function` plugins for different
scenarios.
+
+### Log Information before and after a Phase
+
+The example below demonstrates how you can configure the serverless plugins to
execute custom logics to log information to error logs before and after the
`rewrite` [phase](../terminology/plugin.md#plugins-execution-lifecycle).
+
+Create a Route as such:
+
+
+
+
```shell
curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
-H "X-API-KEY: ${admin_key}" \
-d '{
-"id": "serverless-route",
-"uri": "/index.html",
+"id": "serverless-pre-route",
+"uri": "/anything",
"plugins": {
+ # highlight-start
"serverless-pre-function": {
"phase": "rewrite",
-"functions": ["return function() ngx.log(ngx.ERR, \"serverless pre
function\"); end"]
+"functions" : [
+ "return function()
+ngx.log(ngx.ERR, \"serverless pre function\");
+ end"
+]
},
"serverless-post-function": {
"phase": "rewrite",
-"functions": ["return function(conf, ctx) ngx.log(ngx.ERR, \"match uri
\", ctx.curr_req_matched and ctx.curr_req_matched._path); end"]
+"functions" : [
+ "return function(conf, ctx)
+ngx.log(ngx.ERR, \"match uri \", ctx.curr_req_matched and
ctx.curr_req_matched._path);
+ end"
+]
}
+ # highlight-end
},
"upstream": {
"type": "roundrobin",
"nodes": {
-"127.0.0.1:1980": 1
+"httpbin.org:80": 1
+ }
+}
+ }'
+```
+
+
+
+
+
+```yaml title="adc.yaml"
+services:
+ - name: httpbin
+routes:
+ - name: serverless-pre-route
+uris:
+ - /anything
+plugins:
+ # highlight-start
+ serverless-pre-function:
+phase: rewrite
+functions:
+ - |
+return function()
+ ngx.log(ngx.ERR, "serverless pre function")
+end
+ serverless-post-function:
+phase: rewrite
+functions:
+ - |
+return function(conf, ctx)
+ ngx.log(ngx.ERR, "match uri ", ctx.curr_req_matched and
ctx.curr_req_matched._path)
+end
+ # highlight-end
+upstream:
+ type: roundrobin
+ nodes:
+- host: httpbin.org
+ port: 80
+ weight: 1
+```
+
+Synchronize the configuration to the gateway:
+
+```shell
+adc sync -f adc.yaml
+```
+
+
+
+
+
+
+
+
+
+```yaml title="serverless-functions-ic.yaml"
+apiVersion: v1
+kind: Service
+metadata:
+ namespace: aic
+ name: httpbin-external-domain
+spec:
+ type: ExternalName
+ externalName: httpbin.org
+---
+apiVersion: apisix.apache.org/v1alpha1
+kind: PluginConfig
+metadata:
+ namespace: aic
+ name: serverless-functions-plugin-config
+spec:
+ plugins:
+# highlight-start
+- name: serverless-pre-function
+ config:
+phase: rewrite
+functions:
+ - |
+return function()
+ ngx.log(ngx.ERR, "serverless pre function")
+end
+- name: serverless-post-function
+ config:
+phase: rewrite
+functions:
+ - |
+return function(conf, ctx)
+ ngx.log(ngx.ERR, "match uri ", ctx.curr_req_matched and
ctx.curr_req_matched._path)
+end
+# highlight-end
+---
+apiVersion: gateway.networking.k8s.io/v1
+kind: HTTPRoute
+metadata:
+ namespace: aic
+ name: serverless-pre-route
+spec:
+ parentRefs:
+- name: apisix
+ rules:
+- matches:
+- path:
+type: Exact
+value: /anything
+ filters:
+- type: ExtensionRef
+ extensionRef:
+group: apisix.apache.org
+kind: PluginConfig
+name: serverless-functions-plugin-config
+ backendRefs:
+- name: httpbin-external-domain
+ port: 80
+```
+
+
+
+
+
+```yaml title="serverless-functions-ic.yaml"
+apiVersion: apisix.apache.org/v2
+kind: ApisixUpstream
+metadata:
+ namespace: aic
+ name: httpbin-external-domain
+spec:
+ ingressClassName: apisix
+ externalNodes:
+ - type: Domain
+name: httpbin.org
+---
+apiVersion: apisix.apache.org/v2
+kind: ApisixRoute
+metadata:
+ namespace: aic
+ name: serverless-pre-route
+spec:
+ ingressClassName: apisix
+ http:
+- name: serverless-pre-route
+ match:
+paths:
+ - /anything
+ upstreams:
+- name: httpbin-e
