Skip to content
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

Jobs Overhaul: Improve Logging Utilities #2331

Open
3 tasks
Tracked by #765
itdependsnetworks opened this issue Aug 29, 2022 · 14 comments · Fixed by #3799
Open
3 tasks
Tracked by #765

Jobs Overhaul: Improve Logging Utilities #2331

itdependsnetworks opened this issue Aug 29, 2022 · 14 comments · Fixed by #3799
Assignees
Labels
type: feature Introduction of new or enhanced functionality to the application
Milestone

Comments

@itdependsnetworks
Copy link
Contributor

itdependsnetworks commented Aug 29, 2022

As ...

Patti - Platform Admin

I want ...

The ability to view all of the logs for a lob, not just the ones that are shown in the logging facility (e.g. self.log_success() )

So that ...

so that I can see full stacktraces and similar issues that I may not otherwise have easy access to.

I know this is done when...

There is a UI and API that provides feedback that is the same as I would see on the console of a worker in debug mode.

Optional - Feature groups this request pertains to.

  • Automation
  • Circuits
  • DCIM
  • IPAM
  • Misc (including Data Sources)
  • Organization
  • Plugins (and other Extensibility)
  • Security (Secrets, etc)
  • Image Management
  • UI/UX
  • Documentation
  • Other (not directly a platform feature)

Database Changes

unknown

External Dependencies

No response


Tasks

Considerations

  • We don't need log levels outside the standard Python ones above
  • stdout/stderr are redirected by default: https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-worker_redirect_stdouts so may "just work" but making them work should not be considered in-scope for this
    • The default behavior redirects to a new celery.get_logger instance which does not implement our custom task database handler. Will probably need to use the task_prerun signal to implement the sys.stdout/sys.stderr redirect.
  • Structlog support is a stretch goal and a separate issue
    • If we can use the stdlib logger to keep the log_object field functionality, structlog support can be pushed back to a 2.x or beyond feature request (maybe use the extra kwarg in the stdlib logger methods to pass the object)
  • Controlling emitted log-levels is in scope for Jobs Overhaul: Allow setting a log level on a per job basis #2071
@itdependsnetworks itdependsnetworks added the type: feature Introduction of new or enhanced functionality to the application label Aug 29, 2022
@itdependsnetworks itdependsnetworks changed the title Log Logging Jog Logging Aug 29, 2022
@glennmatthews
Copy link
Contributor

I'd love to get rid of the bespoke logging API for Jobs and just let them use stdlib logging in all cases.

@itdependsnetworks
Copy link
Contributor Author

itdependsnetworks commented Aug 29, 2022

Seems logical. My only request is a convention to still have the same thing. E.g. If you log your system, something like:

LOGGER.debug("NAUTOBOT_OBJ: <uuid>  NAUTOBOT_DEBUG: Serial number data validation failed on the given object.")

You will get the same view that you currently have, in addition to the generic logging

@glennmatthews
Copy link
Contributor

That would be the tradeoff. Unless we want to use something like structlog - I do not want to go in the direction of having Nautobot be responsible for parsing free-text logging messages to infer structure and semantics.

@itdependsnetworks
Copy link
Contributor Author

In the interest of clarity, I am all for using structlog or similar to provide the same functionality, and it becomes an "opt-in" type thing.

@glennmatthews
Copy link
Contributor

Worth considering as part of #765

@glennmatthews glennmatthews mentioned this issue Oct 4, 2022
9 tasks
@glennmatthews glennmatthews changed the title Jog Logging Jog Logging - capture standard logging or structlog entries Oct 13, 2022
@glennmatthews
Copy link
Contributor

Need to consider how this intersects with #765 (comment) - the request there as I understand it would be to also have an option for jobs to not capture logs (or at least, not to store them to the database).

@glennmatthews glennmatthews changed the title Jog Logging - capture standard logging or structlog entries Job Logging - capture standard logging or structlog entries Oct 13, 2022
@glennmatthews glennmatthews changed the title Job Logging - capture standard logging or structlog entries Job Logging - capture stdout/stderr, standard logging, and/or structlog entries Oct 13, 2022
@bryanculver bryanculver added this to the v2.0.0 milestone Nov 3, 2022
@chadell
Copy link
Contributor

chadell commented Nov 17, 2022

Don't know if it's already covered in some of the related issues, but it would be great to offer, off the shelf, a logging level option, matching the log level messages.
This way, if as a user, I want to get only > WARNING message, I could select the WARNING level.
Today, every Job reinvents the wheel for DEBUG messages, with a boolean input and multiple if statements.
Supporting the level filtering by default would simplify logging management.

@bryanculver
Copy link
Member

Worth considering: will #1622 be able to address this with standard available tools (see: https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-logging)

Let's discuss a spike after more of #1622 is completed.

@bryanculver bryanculver added the status: blocked Another issue or external requirement is preventing implementation label Jan 23, 2023
@bryanculver bryanculver changed the title Job Logging - capture stdout/stderr, standard logging, and/or structlog entries Jobs Overhaul: Capture stdout/stderr, standard logging, and/or structlog entries Mar 22, 2023
@bryanculver bryanculver removed the status: blocked Another issue or external requirement is preventing implementation label Apr 3, 2023
@bryanculver
Copy link
Member

bryanculver commented Apr 4, 2023

Don't know if it's already covered in some of the related issues, but it would be great to offer, off the shelf, a logging level option, matching the log level messages.
This way, if as a user, I want to get only > WARNING message, I could select the WARNING level.
Today, every Job reinvents the wheel for DEBUG messages, with a boolean input and multiple if statements.
Supporting the level filtering by default would simplify logging management.

This will be addressed in: #2071

@bryanculver bryanculver changed the title Jobs Overhaul: Capture stdout/stderr, standard logging, and/or structlog entries Jobs Overhaul: Improve Logging Utilities Apr 4, 2023
@gsnider2195
Copy link
Contributor

If we don't achieve the stretch goal do we need to make the JobLogEntry.log_object field a JSONField for job authors that need to log debug messaging with more complex data structures?

@glennmatthews
Copy link
Contributor

Yes, or more generally we need to solve the problem of the existing non-message fields on JobLogEntry and figure out how to accommodate those in the updated logging API we use.

@gsnider2195 gsnider2195 mentioned this issue Apr 5, 2023
17 tasks
@gsnider2195
Copy link
Contributor

The active_test job property should go away as part of this issue as well and potentially use the JobResult.status if that's something that still needs to be tracked in the job's logs.

@gsnider2195 gsnider2195 mentioned this issue May 23, 2023
7 tasks
@bryanculver bryanculver linked a pull request May 24, 2023 that will close this issue
7 tasks
@bryanculver
Copy link
Member

Closed with #3799

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2023
@itdependsnetworks
Copy link
Contributor Author

Have spoke with Nautobot core since this was initially closed, but the core of this issue has not addressed as of yet, which is:

There is a UI and API that provides feedback that is the same as I would see on the console of a worker in debug mode.

I understand there has been adjustments made to the logging facility, but the challenge is always the same, we do not know own the logging for non-Nautobot packages, so if Python requests has an error, we do not control that. The only constant I have found is what has been mentioned in the request of the issue, which is the console of a worker logs (at the time it said debug mode as that was a thing in Nautobot 1.x).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature Introduction of new or enhanced functionality to the application
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants