Skip to content

fix(prometheus): disable features when prometheus plugin is turned off#11117

Merged
moonming merged 11 commits into
apache:masterfrom
shreemaan-abhishek:fix/prometheus-disable-perf-problem
Apr 10, 2024
Merged

fix(prometheus): disable features when prometheus plugin is turned off#11117
moonming merged 11 commits into
apache:masterfrom
shreemaan-abhishek:fix/prometheus-disable-perf-problem

Conversation

@shreemaan-abhishek

@shreemaan-abhishek shreemaan-abhishek commented Apr 3, 2024

Copy link
Copy Markdown
Contributor

Description

This PR allows disabling the export server when prometheus is removed from plugins list in config.yaml and then the plugin reload api is called.

Fixes #11046

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • 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 first)

@shreemaan-abhishek
shreemaan-abhishek force-pushed the fix/prometheus-disable-perf-problem branch from 86d0e0e to eab64d3 Compare April 6, 2024 16:51
@shreemaan-abhishek
shreemaan-abhishek marked this pull request as ready for review April 7, 2024 17:14
Comment thread t/cli/test_prometheus_reload.sh Outdated
Comment thread apisix/plugins/prometheus/exporter.lua Outdated
Comment thread apisix/plugin.lua
end

local enabled = core.table.array_find(http_plugin_names, "prometheus") ~= nil
local active = exporter.get_prometheus() ~= nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to get the active status.
Since the exporter.destroy is harmless.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And so do line355 ~ line357

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no I think the second if check needs the active status. Consider this case:

  • apisix is running with prometheus active and enabled
  • hit plugin reload

In this case enabled == true and active == true. But we need not call http_init() in prometheus because it is already running during this operation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

Comment thread t/plugin/prometheus4.t Outdated
Comment thread t/plugin/prometheus4.t Outdated
Comment thread t/plugin/prometheus4.t
@moonming moonming changed the title fix: disable features when plugin is turned off fix(prometheus): disable features when prometheus plugin is turned off Apr 9, 2024

function _M.destroy()
if prometheus ~= nil then
prometheus_bkp = core.table.deepcopy(prometheus)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use deepcopy? Using the original object directly should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Disable All Prometheus-related Features When Prometheus Plugin is Turned Off

4 participants