New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Job Log Model #1030
Job Log Model #1030
Conversation
This adds the JobLogEntry and migrations to convert existing logs from JobResult to the new Model.
This also removed duplicate views. Ensured that existing functionality was kept between the views.
Since the deletion of git repositories happens outside of the worker, the job_logs db was not able to find the job_resutl. Since this does not run in transaction.atomic, we don't need the job_logs db.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work! Thanks for taking this on.
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Can you please do some testing with this changeset and the |
Of course! |
# Conflicts: # nautobot/extras/tables.py # nautobot/extras/tests/test_models.py
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
This will only happen when including the extras/inc/jobresult.html from within a plugin and not providing the table. This will help plugins such as the Nautobot SSOT with the transition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great!
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! This is a complicated set of page templates, appreciate you putting in the effort here! I think there's room for some refinement in how the extras/jobresult.html
and extras/inc/jobresult.html
pages intersect, happy to spend some time pairing on this tomorrow if you'd like.
I would appreciate the time. It is a big change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks for seeing this through.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be a thorn in the 11th hour, but there are some concerns about query performance I would like to be discussed before we merge this.
@@ -132,6 +132,10 @@ def _configure_settings(config): | |||
if settings.METRICS_ENABLED and "postgres" in settings.DATABASES["default"]["ENGINE"]: | |||
settings.DATABASES["default"]["ENGINE"] = "django_prometheus.db.backends.postgresql" | |||
|
|||
# Create fake db for job logs. This uses the default db, but allows us to save logs within | |||
# transaction.atomic(). | |||
settings.DATABASES["job_logs"] = settings.DATABASES["default"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worries me in that it is a magic setting that we're trying to move away from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if we move away from running jobs in Atomic Transactions then this can go away as well. This is not meant to be modified, so that is why we stuck it here.
groups = set(JobLogEntry.objects.filter(job_result=job_result).values_list("grouping", flat=True)) | ||
for group in sorted(groups): | ||
logs = JobLogEntry.objects.filter(job_result__pk=job_result.pk, grouping=group) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This smells like possible bad query performance to me. Have you considered the following?
- Ordering the query by
grouping
to eliminate the need to usesorted(groups)
? - Using
prefetch_related
onjob_result
to get all of these objects in a single query, instead of round trips to the database for each group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was asked to add sorting to as a set does not have an order. I could change the filter, but it would still be in an unordered set. @glennmatthews was concerned about the sorting.
I will look at the prefetch_related
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also to note, that this is only for running the jobs from the CLI, which I would think is rare.
) | ||
) | ||
|
||
for log_entry in attrs["log"]: | ||
status = log_entry[1] | ||
for log_entry in logs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using logs.iterator()
here since these are single-use instances that you're not mutating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will look into iterator, but this is only used when running jobs through management commands, which has limited use as they can't take arguments.
Co-authored-by: Jathan McCollum <jathan@gmail.com>
Co-authored-by: Jathan McCollum <jathan@gmail.com>
Co-authored-by: Jathan McCollum <jathan@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bother, this should have been retargeted into |
* Create JobLogEntry and migrations. This adds the JobLogEntry and migrations to convert existing logs from JobResult to the new Model. * Remove functions and documentation that is no longer relevent. * Fix tests and allow JobLogEntries to be created outside transaction.atomic * Convert views to use generic.objectview and django-tables2. This also removed duplicate views. Ensured that existing functionality was kept between the views. * Correct git repository deletion bug. Since the deletion of git repositories happens outside of the worker, the job_logs db was not able to find the job_resutl. Since this does not run in transaction.atomic, we don't need the job_logs db. * Update nautobot/docs/additional-features/jobs.md Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Update nautobot/docs/models/extras/jobresult.md Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Update nautobot/docs/additional-features/jobs.md Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Update nautobot/extras/datasources/git.py Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Address page span issue with Additonal Data. * Add truncating of object strings to the JobLogEntry. * Address the rest of the feedback. * Remove unused imports. * Updating Migration order after upstream changes. * Address feedback from PR. * Black recent changes. * Update nautobot/docs/models/extras/jobresult.md Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Update nautobot/extras/models/models.py Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Update nautobot/extras/models/models.py Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Make additional changes recommended by peer review. * Display error message if the job log table is not available. This will only happen when including the extras/inc/jobresult.html from within a plugin and not providing the table. This will help plugins such as the Nautobot SSOT with the transition. * Update nautobot/extras/templates/extras/jobresult.html Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Update nautobot/extras/tests/test_models.py Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> * Address hanging div's and add back active_tab. * Update nautobot/docs/models/extras/joblogentry.md Co-authored-by: Jathan McCollum <jathan@gmail.com> * Update nautobot/docs/models/extras/jobresult.md Co-authored-by: Jathan McCollum <jathan@gmail.com> * Update nautobot/docs/models/extras/joblogentry.md Co-authored-by: Jathan McCollum <jathan@gmail.com> * Prepend constants with JOB_LOG_ * Black Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com> Co-authored-by: Jathan McCollum <jathan@gmail.com>
Fixes #992, fixes #864, fixes #650, fixes #453
This adds a new model called JobLogEntry to store log messages from jobs. For #650 it removes the conditional rendering, but does not change the JS. I might be able to fix that before the review is complete though.
Here are some screenshots of the changes: