Skip to content

Commit 3a70010

Browse files
Merge branch 'master' of github.com:apache/apisix into fix/otel-additional-attrs
Signed-off-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
2 parents 955db11 + 4762c33 commit 3a70010

15 files changed

Lines changed: 2086 additions & 963 deletions

apisix/plugins/ai-proxy-multi.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,11 @@ function _M.construct_upstream(instance)
439439
local upstream = {}
440440
local node = instance._dns_value
441441
if not node then
442-
return nil, "failed to resolve endpoint for instance: " .. instance.name
442+
resolve_endpoint(instance)
443+
node = instance._dns_value
444+
if not node then
445+
return nil, "failed to resolve endpoint for instance: " .. instance.name
446+
end
443447
end
444448

445449
if not node.host or not node.port then

apisix/plugins/opentelemetry.lua

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,6 @@ function _M.rewrite(conf, api_ctx)
377377
table.insert(attributes, attr.string("apisix.service_name", api_ctx.service_name))
378378
end
379379

380-
if conf.additional_attributes then
381-
inject_attributes(attributes, conf.additional_attributes, api_ctx.var, false)
382-
end
383-
384-
if conf.additional_header_prefix_attributes then
385-
inject_attributes(
386-
attributes,
387-
conf.additional_header_prefix_attributes,
388-
core.request.headers(api_ctx),
389-
true
390-
)
391-
end
392-
393380
-- extract trace context from the headers of downstream HTTP request
394381
local upstream_context = trace_context_propagator:extract(context, ngx.req)
395382

@@ -501,6 +488,26 @@ function _M.log(conf, api_ctx)
501488
inject_core_spans(ctx, api_ctx, conf)
502489
span:set_attributes(attr.int("http.status_code", status_code),
503490
attr.int("http.response.status_code", status_code))
491+
492+
493+
local attributes = {}
494+
if conf.additional_attributes then
495+
inject_attributes(attributes, conf.additional_attributes, api_ctx.var, false)
496+
end
497+
498+
if conf.additional_header_prefix_attributes then
499+
inject_attributes(
500+
attributes,
501+
conf.additional_header_prefix_attributes,
502+
core.request.headers(api_ctx),
503+
true
504+
)
505+
end
506+
507+
for i = 1, #attributes do
508+
span:set_attributes(attributes[i])
509+
end
510+
504511
update_time()
505512
span:finish()
506513
end

docs/en/latest/plugins/aws-lambda.md

Lines changed: 164 additions & 133 deletions
Large diffs are not rendered by default.

docs/en/latest/plugins/kafka-logger.md

Lines changed: 331 additions & 97 deletions
Large diffs are not rendered by default.

docs/en/latest/plugins/openid-connect.md

Lines changed: 304 additions & 131 deletions
Large diffs are not rendered by default.

docs/en/latest/plugins/prometheus.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Reload APISIX for changes to take effect.
9292

9393
| Name | Type | Required | Default | Valid values | Description |
9494
| ------------- | ------- | -------- | ------- | ------------ | ------------------------------------------ |
95-
| prefer_name | boolean | | False | | If true, export Route/Service name instead of their ID in Prometheus metrics. |
95+
| prefer_name | boolean | False | false | | If true, export Route/Service name instead of their ID in Prometheus metrics. |
9696

9797
## Metrics
9898

@@ -292,6 +292,14 @@ apisix_etcd_modify_indexes{key="global_rules"} 0
292292

293293
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.
294294

295+
:::caution
296+
297+
If a large quantity of metrics are being collected, the Plugin could take up a significant amount of CPU resources for metric computations and negatively impact the processing of regular requests.
298+
299+
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 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). When you expose the metric endpoint with the `public-api` Plugin, the offloading and cached metric serving still apply; however, the endpoint is then exposed on the public listener and requests to it go through the normal public API request path, which can add request-path overhead compared with the dedicated export server.
300+
301+
:::
302+
295303
Disable the Prometheus export server in the configuration file and reload APISIX for changes to take effect:
296304

297305
```yaml title="conf/config.yaml"
@@ -300,7 +308,7 @@ plugin_attr:
300308
enable_export_server: false
301309
```
302310
303-
Next, create a Route with [`public-api`](../../../en/latest/plugins/public-api.md) Plugin and expose a public API endpoint for APISIX metrics:
311+
Next, create a Route with [`public-api`](./public-api.md) Plugin and expose a public API endpoint for APISIX metrics:
304312

305313
```shell
306314
curl "http://127.0.0.1:9180/apisix/admin/routes/prometheus-metrics" -X PUT \
@@ -434,7 +442,7 @@ curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \
434442
-H "X-API-KEY: ${admin_key}" \
435443
-d '{
436444
"id": "prometheus-route",
437-
Include the following configurations in the configuration file to add labels for metrics and reload APISIX for changes to take effect:
445+
"uri": "/get",
438446
"name": "extra-label",
439447
"plugins": {
440448
"prometheus": {}
@@ -494,7 +502,7 @@ Create a Stream Route with the `prometheus` Plugin:
494502
curl "http://127.0.0.1:9180/apisix/admin/stream_routes" -X PUT \
495503
-H "X-API-KEY: ${admin_key}" \
496504
-d '{
497-
Include the following configurations in `config.yaml` to enable stream proxy and enable `prometheus` Plugin for stream proxy. Reload APISIX for changes to take effect:
505+
"id": "prometheus-route",
498506
"plugins": {
499507
"prometheus":{}
500508
},

docs/en/latest/plugins/serverless.md

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ keywords:
55
- API Gateway
66
- Plugin
77
- Serverless
8-
description: This document contains information about the Apache APISIX serverless Plugin.
8+
description: The serverless plugins, `serverless-pre-function` and `serverless-post-function`, allow you to dynamically run Lua functions at specified phases in APISIX.
99
---
1010

1111
<!--
@@ -35,12 +35,12 @@ Both Plugins have the same attributes.
3535

3636
## Attributes
3737

38-
| Name | Type | Required | Default | Valid values | Description |
39-
|-----------|---------------|----------|------------|------------------------------------------------------------------------------|------------------------------------------------------------------|
40-
| phase | string | False | ["access"] | ["rewrite", "access", "header_filter", "body_filter", "log", "before_proxy"] | Phase before or after which the serverless function is executed. |
41-
| functions | array[string] | True | | | List of functions that are executed sequentially. |
38+
| Name | Type | Required | Default | Valid values | Description |
39+
|-----------|---------------|----------|----------|------------------------------------------------------------------------------|------------------------------------------------------------------|
40+
| phase | string | False | "access" | ["rewrite", "access", "header_filter", "body_filter", "log", "before_proxy"] | Phase before or after which the serverless function is executed. |
41+
| functions | array[string] | True | | | List of functions that are executed sequentially. |
4242

43-
:::info IMPORTANT
43+
:::note
4444

4545
Only Lua functions are allowed here and not other Lua code.
4646

@@ -69,21 +69,16 @@ local count = 1
6969
ngx.say(count)
7070
```
7171

72-
:::
73-
74-
:::note
75-
7672
From v2.6, `conf` and `ctx` are passed as the first two arguments to a serverless function like regular Plugins.
7773

7874
Prior to v2.12.0, the phase `before_proxy` was called `balancer`. This was updated considering that this method would run after `access` and before the request goes Upstream and is unrelated to `balancer`.
7975

8076
:::
8177

82-
## Enable Plugin
83-
84-
The example below enables the Plugin on a specific Route:
78+
## Examples
8579

8680
:::note
81+
8782
You can fetch the `admin_key` from `config.yaml` and save to an environment variable with the following command:
8883

8984
```bash
@@ -92,53 +87,37 @@ admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"/
9287

9388
:::
9489

90+
The following example enables `serverless-pre-function` and `serverless-post-function` Plugins on a Route:
91+
9592
```shell
96-
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '
97-
{
93+
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \
94+
-H "X-API-KEY: ${admin_key}" \
95+
-d '{
96+
"id": "serverless-route",
9897
"uri": "/index.html",
9998
"plugins": {
100-
"serverless-pre-function": {
101-
"phase": "rewrite",
102-
"functions" : ["return function() ngx.log(ngx.ERR, \"serverless pre function\"); end"]
103-
},
104-
"serverless-post-function": {
105-
"phase": "rewrite",
106-
"functions" : ["return function(conf, ctx) ngx.log(ngx.ERR, \"match uri \", ctx.curr_req_matched and ctx.curr_req_matched._path); end"]
107-
}
99+
"serverless-pre-function": {
100+
"phase": "rewrite",
101+
"functions": ["return function() ngx.log(ngx.ERR, \"serverless pre function\"); end"]
102+
},
103+
"serverless-post-function": {
104+
"phase": "rewrite",
105+
"functions": ["return function(conf, ctx) ngx.log(ngx.ERR, \"match uri \", ctx.curr_req_matched and ctx.curr_req_matched._path); end"]
106+
}
108107
},
109108
"upstream": {
110-
"type": "roundrobin",
111-
"nodes": {
112-
"127.0.0.1:1980": 1
113-
}
109+
"type": "roundrobin",
110+
"nodes": {
111+
"127.0.0.1:1980": 1
112+
}
114113
}
115-
}'
114+
}'
116115
```
117116

118-
## Example usage
119-
120-
Once you have configured the Plugin as shown above, you can make a request as shown below:
117+
Send a request to the Route:
121118

122119
```shell
123-
curl -i http://127.0.0.1:9080/index.html
120+
curl -i "http://127.0.0.1:9080/index.html"
124121
```
125122

126-
You will find a message "serverless pre-function" and "match uri /index.html" in the error.log.
127-
128-
## Delete Plugin
129-
130-
To remove the `serverless` 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.
131-
132-
```shell
133-
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '
134-
{
135-
"methods": ["GET"],
136-
"uri": "/index.html",
137-
"upstream": {
138-
"type": "roundrobin",
139-
"nodes": {
140-
"127.0.0.1:1980": 1
141-
}
142-
}
143-
}'
144-
```
123+
You will find messages `serverless pre function` and `match uri /index.html` in the error log.

0 commit comments

Comments
 (0)