netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
16.36k stars 2.6k forks source link

Move logging from BaseScript into JobRunner #17281

Open alehaa opened 3 months ago

alehaa commented 3 months ago

NetBox version

v4.1-beta1

Feature type

Change to existing functionality

Proposed functionality

Use case

With the JobRunner framework, plugins have the ability to define jobs in a standard way. However, communication to the user is still limited to free-form data and exception logging. Adding logging to general jobs would allow plugins to provide additional information about what's been done during job execution.

Database changes

None

External dependencies

None.

If accepted, this could make #15983 obsolete. As all jobs would have logs, no dedicated link to script logs is required anymore.

alehaa commented 2 months ago

I volunteer to work on this myself.

jeremystretch commented 2 months ago

I'm not sure I understand the intent here. Logging methods like log_info() are intended to be called by the script itself within its run() method to log output from its operations. @alehaa could you elaborate a bit on the specific change(s) being proposed?

alehaa commented 2 months ago

My intention when introducing the JobRunner framework was to provide a standard way to handle jobs. Previously there were some different implementations in NetBox and also some plugins. With NetBox v4.1 it is now possible to access this standard interface and e.g. show which background jobs are running along with other jobs like scripts or data source syncs.

With this FR I'd like to introduce the next evolution of the framework and give it the ability to communicate information to users and administrators in a standard way. Currently, scripts, the blueprint of the JobRunner framework, have a standardized way to communicate messages using logging methods. Now I'd like to make logging available to the JobRunner class as well. This would allow background jobs and housekeeping tasks to document what they've done, e.g. which VMs were synchronized or skipped, just like scripts do.

To avoid reinventing the wheel, I suggest moving the existing methods from the BaseScript class to JobRunner or a common base class (to be introduced). The JobRunner class has been designed to keep extensions like this in mind, so one would call log_info() from run() like in scripts. The UI log views also need to be moved from scripts to jobs.

alehaa commented 1 month ago

@jeremystretch do you need some additional information? It's unclear to me whether this issue is in the state needs owner or revisions needed.

alehaa commented 4 days ago

I am still happy to work on this feature. Since there won't be any model changes, there shouldn't be any significant changes to the existing functionality, just making it available to other NetBox internal and external code.