bug: prometheus `disabled_labels` in a Route's plugin config is accepted but has no effect
Current Behavior
Setting disabled_labels under plugins.prometheus on a Route is accepted by the Admin API with no error or warning, but it has no effect. The exporter only reads disabled_labels from the prometheus plugin metadata, so the labels are still reported.
The plugin's route schema in apisix/plugins/prometheus.lua (L23–31) declares only prefer_name and has no additionalProperties = false (removed on purpose in https://github.com/apache/apisix/pull/4797), so the unknown field passes. disabled_labels exists only in metadata_schema (L67–76). Users already find it hard to know where this setting goes: https://github.com/apache/apisix/issues/13877.
Expected Behavior
The Admin API should reject disabled_labels in a Route's prometheus config, with an error that points to the prometheus plugin metadata. @juzhiyuan suggested an error rather than a warning, since a warning is easy to miss when the setting has no effect.
Error Logs
None. Nothing is logged, which is the problem.
Steps to Reproduce
- Create a route that sets
disabled_labelsin its prometheus config. The Admin API accepts it:curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X PUT -d '{ "uri": "/hello", "plugins": {"prometheus": {"disabled_labels": {"http_status": ["node"]}}}, "upstream": {"type": "roundrobin", "nodes": {"127.0.0.1:1980": 1}} }' - Send a few requests to
/hello. - Fetch
http://127.0.0.1:9091/apisix/prometheus/metrics. Thenodelabel onapisix_http_statusis still filled in. - Put the same
disabled_labelsinPUT /apisix/admin/plugin_metadata/prometheusinstead, and it takes effect.
An upgrade question for the maintainers: an error in check_schema would also apply when APISIX loads routes from etcd. apisix/http/route.lua checks every loaded route with plugin_checker, and apisix/core/config_etcd.lua skips a route that fails. So a route saved with disabled_labels on 3.18–3.20, where it was accepted, would stop loading after an upgrade. Is a breaking-change note in the CHANGELOG the right way to handle that, or would you prefer another approach?
Environment
- APISIX version: reported on 3.19.0;
apisix/plugins/prometheus.luais unchanged in 3.20.0 and on master (64d831f4f3) - It is in schema validation, so it does not depend on the OS, OpenResty or etcd version