Skip to content

[18.0] Expose jobrunner metrics - #1029

Draft
yvaucher wants to merge 3 commits into
OCA:18.0from
acsone:18.0-metrics-sbi-ypt
Draft

yvaucher wants to merge 3 commits into
OCA:18.0from
acsone:18.0-metrics-sbi-ypt

Conversation

@yvaucher

@yvaucher yvaucher commented Nov 4, 2026

Copy link
Copy Markdown
Member

This is based on #976

This turns out to be fairly simple. A few things worth noting:

  • The http server runs in the same thread and event loop as listen/notify job events, so there are no concurrency issues while accessing the channels stats
  • I added the set of jobs waiting for dependencies on each channel for completeness and convenient access to that stat, similar to what is done for failed jobs.
  • I used the prometheus-client external library. It's currently required even if the metrics server is not configured. This could be improved by mocking the lib and making it mandatory only for users enabling the metrics server. Or make it a required dependency (which is my preference, for simplicity).
  • This still needs tests and docs.

Test by setting ODOO_QUEUE_JOB_METRICS_PORT=8080 before running Odoo then watch curl -s http://localhost:8080.

@oca-cla-bot

oca-cla-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @guewen, @sbidoul,
some modules you are maintaining are being modified, check this out!

@sbidoul sbidoul left a comment

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.

Thanks! A few thoughts after a first read.

Comment thread queue_job/jobrunner/channels.py Resolved
Comment thread queue_job/jobrunner/runner.py Resolved
Comment thread queue_job/jobrunner/channels.py Outdated
"""Register gauges for a specific database in this channel."""
self._unregister_metrics()
self._metrics_labels = {
"db": self.db_name,

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.

Note to self: I think self.db_name can be None if this is the global ChannelManager. Test that this works.

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.

It renders db="None". Not ideal. So maybe __all__?

Comment thread queue_job/jobrunner/channels.py Resolved
Comment thread queue_job/jobrunner/channels.py Resolved
Comment thread queue_job/jobrunner/channels.py Resolved
Comment thread queue_job/jobrunner/channels.py Resolved

def _capacity_gauge(self) -> float:
if self.capacity is None:
return math.inf

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.

Note to self: test that prometheus client renders math.inf correctly

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.

It renders +Inf. Now need to see what prometheus and grafana do with that.

Comment thread queue_job/jobrunner/runner.py Resolved
Comment thread queue_job/jobrunner/channels.py Resolved
@sbidoul sbidoul mentioned this pull request Nov 4, 2026
@yvaucher
yvaucher force-pushed the 18.0-metrics-sbi-ypt branch 2 times, most recently from 3ddb459 to 672ba4d Compare November 5, 2026 10:37
Comment thread queue_job/jobrunner/channels.py Resolved
Comment thread queue_job/jobrunner/runner.py Resolved
@yvaucher
yvaucher force-pushed the 18.0-metrics-sbi-ypt branch from 672ba4d to 09e5a53 Compare November 5, 2026 11:21
Comment thread queue_job/jobrunner/runner.py Outdated
self._channel_manager_by_db[db_name] = channel_manager
self._channel_managers = [self._server_wide_channel_manager]
self._notify_existing_jobs(db, channel_manager)
self.register_metrics()

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.

This one should not be here. Because the server wide channel manager is a singleton without db_name, we don't need to re-register metrics for each db. It should move somewhere near the creation of the server wide ChannelManager

@sbidoul

sbidoul commented Nov 5, 2026

Copy link
Copy Markdown
Member

Can you also add prometheus-client to the manifest external deps?

@yvaucher
yvaucher force-pushed the 18.0-metrics-sbi-ypt branch from 09e5a53 to d77f62e Compare November 5, 2026 11:55
@sbidoul sbidoul changed the title [18.0][BACKPORT] Expose jobrunner metrics [18.0] Expose jobrunner metrics Nov 5, 2026
@yvaucher
yvaucher force-pushed the 18.0-metrics-sbi-ypt branch from d77f62e to 35ce9a2 Compare November 5, 2026 12:16
@amh-mw

amh-mw commented Nov 5, 2026

Copy link
Copy Markdown
Member

Can you also add prometheus-client to the manifest external deps?

Late to the party here and not familiar with prometheus, but is it appropriate to hardcode a metrics collection agent and additional python dependencies into the main queue_job module? I'm running on AWS, won't use this, and would prefer not to install a python package that won't get used at best, and will steal CPU cycles at worst.

@amh-mw

amh-mw commented Nov 5, 2026

Copy link
Copy Markdown
Member

Late to the party here and not familiar with prometheus, but is it appropriate to hardcode a metrics collection agent and additional python dependencies into the main queue_job module? I'm running on AWS, won't use this, and would prefer not to install a python package that won't get used at best, and will steal CPU cycles at worst.

It looks like Prometheus metrics collected by the CloudWatch agent, so that removes some decent portion of my argument against.

@yvaucher
yvaucher force-pushed the 18.0-metrics-sbi-ypt branch from 35ce9a2 to 4a6a3c7 Compare November 5, 2026 12:24
Comment thread queue_job/readme/CONFIGURE.md Resolved
Comment thread queue_job/jobrunner/channels.py Resolved
@yvaucher

yvaucher commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

@amh-mw on our wish list we have the extraction of the metrics in a separate module and the possibility to plug other observability tools such as opentelemetry.

The state of this PR is still in draft. Your input are welcome nevertheless, and I agree with you that we might not want to enforce the usage of Prometheus.

@yvaucher
yvaucher force-pushed the 18.0-metrics-sbi-ypt branch 6 times, most recently from fbf36a8 to 0ce8156 Compare November 5, 2026 18:02
@sbidoul
sbidoul force-pushed the 18.0-metrics-sbi-ypt branch from abf7848 to 761804b Compare November 5, 2026 18:15
@yvaucher
yvaucher force-pushed the 18.0-metrics-sbi-ypt branch from b11e72d to e4c8ec6 Compare November 5, 2026 18:28
sbidoul and others added 3 commits November 5, 2026 19:43
This adds a 'db' label to channel gauges to track which databases
have jobs in each channel. This allows for better monitoring when
multiple databases share the same channel structure.
Not sure that's useful. Let's wait for the actual use case.
@sbidoul
sbidoul force-pushed the 18.0-metrics-sbi-ypt branch from e4c8ec6 to d094cf6 Compare November 5, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants