[18.0] Expose jobrunner metrics #1029
All commit authors signed the Contributor License Agreement.
<!-- CLA BOT SIGNING COMMENT DO NOT EDIT -->
Hi @guewen, @sbidoul,
some modules you are maintaining are being modified, check this out!
this new constant seems unrelated to this PR
jobs_to_do can be a per ChannelManager gauge with a db label, so we have granular per db data and the sum can be obtained downstream with queries in the metrics database.
Note to self: I think self.db_name can be None if this is the global ChannelManager. Test that this works.
unrelated change?
Is that part necessary since we iterate on all channels of the ChannelManager?
Any particular reason to use an empty dict rather than None?
self._metrics_labels = None
Note to self: test that prometheus client renders math.inf correctly
Should we rather do this for each ChannelManager, in _configure_db, and when creating the server_wide_channel_manager?
We can keep this, but it's probably safer to do it also at deterministic points, in _configure_db when a ChannelManager for a db is replaced.
Thanks! A few thoughts after a first read.
Should indeed not be necessary, I'll test without it.
I was hesitant to put it in initalize_database as for me we do this setup once the db are set and it is not in the scope of initializing the database. But if you find it more convenient I will move it to _configure_db and server_wide_channel_manager
Good idea the overall to do gauge is not very helpful.
With the new per db config, the ChannelManager of a db is re-created when a channel config changes, so we need to reset the metrics at the point too. Look for RELOAD_PAYLOAD to see how it works. It ends up calling _configure_db when, say, the parent or capacity of a channel is changed in db.
Changed back to None, it was to be explicit on the type but a initialized dict is probably a bad idea.
metrics.jobs_to_do.labels(db=self.db_name).set_function(
self._jobs_to_do_gauge
)
This gauge must be present for the server wide ChannelManager too, like other channel metrics, and that one has no db. So that's relates to the other comment to test what happens when db_name is None.
def _configure_db(self, db):
"""Build the channel manager for a database and reload its jobs"""
db_name = db.db_name
channel_manager = self._build_channel_manager(db)
if db_name in self._channel_manager_by_db:
self._channel_manager_by_db[db_name].unregister_metrics()
self._channel_manager_by_db[db_name] = channel_manager
channel_manager.register_metrics()
self._channel_managers = list(self._channel_manager_by_db.values())
self._notify_existing_jobs(db, channel_manager)
_logger.info("channels configuration loaded for db %s", db_name)
I was thinking of something like this. What do you think?
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
Can you also add prometheus-client to the manifest external deps?
Ok, I'll add an unregister on the channel manager.
However, it seems we need the register_metrics after _notify_existing_jobs to initialize correctly the metrics, as notify_existing_jobs initialize the jobs and thus fills in the categories based on state. The gauge would be only valid on first update otherwise.
It should not be a problem because the labels only depend on the channels config, and the values of the gauges can't be queried before _notify_existing_jobs because all this happens in the same thread.
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.
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.
- `ODOO_QUEUE_JOB_METRICS_LISTEN_ADDRESS=127.0.0.1`, default 127.0.0.1
It renders db="None". Not ideal. So maybe __all__?
I'm afraid we can't use self.db_name here because the server wide ChannelManager does not have a db_name.
So yeah, storing db_name on the ChannelManager is fine but we probably can't use it anywhere except as a metrics label.
@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.
Reverted the store of db_name on ChannelManager it is only stored on Channel as the server_wide manager can be used for multiple database.
It renders +Inf. Now need to see what prometheus and grafana do with that.
sbidoul
yvaucher
This is based on #976