mikyll commented on issue #12150:
URL: https://github.com/apache/apisix/issues/12150#issuecomment-2812172723
Hi @NandanSatheeshJupiter
I tested this on minikube and the "log" plugin is loaded correctly, in fact,
APISIX only logs the following error:
```lang-none
2025/04/17 08:19:59 [error] 73#73: *27 [lua] plugin.lua:144: load_plugin():
failed to load plugin [jwt-auth-headers] err: module
'apisix.plugins.jwt-auth-headers' not found:
no field package.preload['apisix.plugins.jwt-auth-headers']
no file
'/usr/local/apisix//deps/share/lua/5.1/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/apisix//deps/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file '/usr/local/apisix/apisix/plugins/jwt-auth-headers.lua'
no file '/usr/local/apisix/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers.ljbc'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers/init.ljbc'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers.ljbc'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers/init.ljbc'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers/init.lua'
no file './apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/luajit/share/luajit-2.1/apisix/plugins/jwt-auth-headers.lua'
no file '/usr/local/share/lua/5.1/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file '/usr/local/apisix/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/apisix/deps/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file './apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/luajit/share/luajit-2.1/apisix/plugins/jwt-auth-headers.lua'
no file '/usr/local/share/lua/5.1/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers.ljbc'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers/init.ljbc'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers.ljbc'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers/init.ljbc'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers/init.lua'
no file './apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/luajit/share/luajit-2.1/apisix/plugins/jwt-auth-headers.lua'
no file '/usr/local/share/lua/5.1/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/jwt-auth-headers.lua'
no file
'/usr/local/openresty/luajit/share/lua/5.1/apisix/plugins/jwt-auth-headers/init.lua'
no file
'/usr/local/apisix//deps/lib64/lua/5.1/apisix/plugins/jwt-auth-headers.so'
no file
'/usr/local/apisix//deps/lib/lua/5.1/apisix/plugins/jwt-auth-headers.so'
no file
'/usr/local/openresty/site/lualib/apisix/plugins/jwt-auth-headers.so'
no file '/usr/local/openresty/lualib/apisix/plugins/jwt-auth-headers.so'
no file './apisix/plugins/jwt-auth-headers.so'
no file '/usr/local/lib/lua/5.1/apisix/plugins/jwt-auth-headers.so'
no file
'/usr/local/openresty/luajit/lib/lua/5.1/apisix/plugins/jwt-auth-headers.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './apisix/plugins/jwt-auth-headers.so'
no file '/usr/local/lib/lua/5.1/apisix/plugins/jwt-auth-headers.so'
no f
```
This is expected, since you haven't defined "jwt-auth-headers" yet 🙂
However, the reason why you're not seeing the log is caused by the following:
1. Incorrect APISIX log level in `config.yaml`;
2. "log" plugin priority.
## Issues
### 1. APISIX Log Level
In your `config.yaml`, you have:
```yaml
logger:
level: "info"
```
Which doesn't actually change APISIX log level. To change the log level you
should use the following:
```yaml
nginx_config:
error_log_level: info
```
However, since at "info" level, APISIX logs are _a lot_, if you only want to
test that the plugin is working, I suggest you to change the plugin level to
"warn" instead:
```lua
core.log.warn("log plugin triggered!")
```
You can have a look at
[config.yaml.example](https://github.com/apache/apisix/blob/master/conf/config.yaml.example)
for a more comprehensive example.
### 2. Plugin Priority
Since your "log" plugin has priority `0`, when you enable it on route
`/health`, it will **never** execute, because "serverless-pre-function" has
higher priority (10000) and it truncates the request processing, by returning
`200`.
You could change that by:
1. increasing the priority in "log" plugin:
```lua
local _M = {
version = 0.1,
priority = 20000, -- Or any number > 10000
name = plugin_name,
}
```
2. increasing the priority in "log" instance, using plugin metadata:
```yaml
routes:
- id: 100
uri: /health
plugins:
log:
_meta:
priority: 20000 # Or any number > 10000
serverless-pre-function:
phase: access
functions:
- |
return function(conf, ctx)
ngx.say('APISIX is healthy')
ngx.exit(200)
end
```
## Full Example
```yaml
apiVersion: v1
kind: Namespace
metadata:
name: apisix
---
apiVersion: v1
kind: ConfigMap
metadata:
name: apisix-config
namespace: apisix
data:
config.yaml: |
apisix:
node_listen: 9080
enable_admin_cors: true
admin_key:
- name: "admin"
key: edd1c9f034335f136f87ad84b625c8f1
role: admin
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
plugins:
- log
- jwt-auth-headers
- serverless-pre-function
- grpc-transcode
- limit-req
- limit-count
- proxy-rewrite
- ip-restriction
- response-rewrite
# nginx_config:
# error_log_level: info
---
apiVersion: v1
kind: ConfigMap
metadata:
name: apisix-routes
namespace: apisix
data:
apisix.yaml: |
routes:
- id: 100
uri: /health
plugins:
log:
serverless-pre-function:
phase: access
functions:
- |
return function(conf, ctx)
ngx.say('APISIX is healthy')
ngx.exit(200)
end
- id: 1
uri: /hello
upstream:
type: roundrobin
nodes:
"127.0.0.1:8080": 1
plugins:
jwt-auth-headers:
header: Authorization
query: token
cookie: jwt
hide_credentials: true
clock_skew: 60
claims_to_headers:
key: X-User-Id
username: X-User-Role
iss: X-User-Email
response-rewrite:
headers:
set:
X-Config-Version: "v1"
body: "Hello from APISIX v1\n"
# Testing route
- id: test_log
uri: /test_log
plugins:
log:
_meta:
priority: 30000
#END
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: apisix
namespace: apisix
annotations:
reloader.stakater.com/auto: "true"
configmap.reloader.stakater.com/reload:
"apisix-config,apisix-routes,apisix-custom-plugin-log"
spec:
replicas: 1
selector:
matchLabels:
app: apisix
template:
metadata:
labels:
app: apisix
spec:
containers:
- name: apisix
image: apache/apisix:3.12.0-debian
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: 500m
memory: 1Gi
ports:
- containerPort: 9080
name: http
- containerPort: 9443
name: https
- containerPort: 9180
name: admin
livenessProbe:
httpGet:
path: /health
port: 9080
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /health
port: 9080
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
volumeMounts:
- name: config
mountPath: /usr/local/apisix/conf/config.yaml
subPath: config.yaml
- name: routes
mountPath: /usr/local/apisix/conf/apisix.yaml
subPath: apisix.yaml
- name: custom-plugin-log
mountPath: /usr/local/apisix/apisix/plugins/log.lua
subPath: log.lua
volumes:
- name: config
configMap:
name: apisix-config
- name: routes
configMap:
name: apisix-routes
- name: custom-plugin-log
configMap:
name: apisix-custom-plugin-log
---
apiVersion: v1
kind: Service
metadata:
name: apisix
namespace: apisix
spec:
type: NodePort
ports:
- port: 80
targetPort: 9080
name: http
- port: 9180
targetPort: 9180
name: admin
selector:
app: apisix
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: hpa
namespace: apisix
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: apisix
maxReplicas: 10
minReplicas: 2
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 75
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 75
behavior:
scaleDown:
stabilizationWindowSeconds: 120
policies:
- type: Pods
value: 1
periodSeconds: 30
---
apiVersion: v1
kind: ConfigMap
metadata:
name: apisix-custom-plugin-log
namespace: apisix
data:
log.lua: |
local core = require("apisix.core")
local plugin_name = "log"
local _M = {
version = 0.1,
priority = 0,
name = plugin_name,
}
_M.schema = {
type = "object",
properties = {},
}
function _M.access(conf, ctx)
core.log.warn("log plugin triggered!")
end
return _M
---
```
Hope that helped 🙂 let me know if you still encounter issues or unexpected
behaviour
--
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]