omkar619-dev opened a new pull request, #14216: URL: https://github.com/apache/apisix/pull/14216
### Description The `prometheus` plugin reads `disabled_labels` only from its plugin metadata. The plugin's own schema declares only `prefer_name` and has no `additionalProperties = false` (removed on purpose in https://github.com/apache/apisix/pull/4797). So `disabled_labels` set in a Route's `prometheus` config is accepted and stored, but it has no effect, and nothing tells the user it is ignored. As @juzhiyuan suggested, this PR rejects `disabled_labels` outside the plugin metadata, with an error that points to the plugin metadata. A warning would be easy to miss when the setting has no effect. Changes: - `apisix/plugins/prometheus.lua`: `check_schema` returns an error when `disabled_labels` is set in the plugin configuration. The plugin metadata path is unchanged. - `t/plugin/prometheus-label-filter.t`: TEST 8 sets `disabled_labels` in a Route's `prometheus` config and expects a 400 with the new error. - `docs/en/latest/plugins/prometheus.md` and `docs/zh/latest/plugins/prometheus.md`: one sentence in the Metadata section that says where `disabled_labels` can be set. Testing, in the dev container from `example/build-dev-image.dockerfile` with etcd 3.5: - Without the change to `prometheus.lua`, TEST 8 fails, because the Admin API accepts and stores the route. - With the change, `prove t/plugin/prometheus-label-filter.t` passes. - `make lint`, codespell, eclint, markdownlint, autocorrect and `utils/fix-zh-doc-segment.py` pass on the changed files. #### Backward compatibility This change is not fully backward compatible, so I left that box unchecked. `check_schema` also runs when APISIX loads configuration from etcd. `check_route` calls `plugin_checker` on every route ([route.lua L121-L125](https://github.com/apache/apisix/blob/64d831f4f389ad652eb9b180fd4fd5f9c794b5b0/apisix/http/route.lua#L121-L125)), and an item that fails the checker is logged as an error and skipped ([config_etcd.lua L647-L654](https://github.com/apache/apisix/blob/64d831f4f389ad652eb9b180fd4fd5f9c794b5b0/apisix/core/config_etcd.lua#L647-L654)). A running node keeps its last valid copy ([L668-L676](https://github.com/apache/apisix/blob/64d831f4f389ad652eb9b180fd4fd5f9c794b5b0/apisix/core/config_etcd.lua#L668-L676)), but a node that has just started has no previous copy ([L1111](https://github.com/apache/apisix/blob/64d831f4f389ad652eb9b180fd4fd5f9c794b5b0/apisix/core/config_etcd.lua#L1111)). So a Route saved with `disabled_labels` in its `prometheus` config on 3.18.0 to 3.20.0 would not be loaded after an upgrade, and its requests would get 404 until the field is removed. Services, Consumers, Global Rules and Plugin Configs run the same plugin check on load, so they would be skipped the same way. Removing the field changes no metrics, because it never had an effect there. I see two ways to handle this: 1. Keep the error, as this PR does, and add a `Change` entry to the CHANGELOG telling users to remove `disabled_labels` from plugin configurations before they upgrade. 2. Log a warning and ignore the field for now, then switch to the error in a later release. I'm happy to switch the PR to the second option if you prefer it. The PR template also asks for a mailing list discussion for changes that are not backward compatible. If you want one, I can start a thread on [email protected]. #### Which issue(s) this PR fixes: Fixes https://github.com/apache/apisix/issues/14213 ### Checklist - [x] I have explained the need for this PR and the problem it solves - [x] I have explained the changes or the new features added to this PR - [x] I have added tests corresponding to this change - [x] I have updated the documentation to reflect this change - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first) -- 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]
