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

Add support for logging to Loki (and others) #1401

Closed
wants to merge 34 commits into from

Conversation

lithorus
Copy link
Collaborator

@lithorus lithorus commented Jul 1, 2024

Summarize your change.

Have introduces a new module and class for RQD which deals with writing the process log file.

This is to abstract file writing which gives the ability to support non-file based logging (eg. loki, elasticsearch)

I have not been able to test the code changes on Windows and Mac

It depends on #1416 since the loki python module is not compaible with python 2.x

Still work-in-progress and comments on the implementation are welcome...

RQDLogger

A new python module (rqlogging) with the new class RQDLogger has been added to RQD to abstract any process logging. It's supposed to be a drop in replacement for a file object with some extra functions (like waiting for the file to be created). It also checks if it's using a "protocol" and will instantiate a sub-class for the appropriate protocol.
This makes it easy to centralize the logging logic and also adds the ability to extend with more logging backends.

How to use it

---- Cuebot configuraton ----

Cuebot provides the path to the root of logs, so this is where RQD is configured for logging.
It can either be configured using the environment variable CUE_FRAME_LOG_DIR or using the log.frame-log-root.default_os propterty in the config file.

This is also what's used to determine whether or not to use loki (at job submission time) instead of plain file logging. Only if the "protocol" is defined, it will not log straight to files. (however still using the wrapper)

To confgure for loki, a path like this can be used :
loki://internal/shows
loki being the protocol
internal is refering to the server instance
/shows is refering to prefixed path on the server

The server instance variable is not the actual address. but a reference to a server definition in RQD's config

---- RQD configuration ----

in rqd.conf :

[Loki]
internal=http://127.0.0.1:3100/loki

internal is the server reference name
http://127.0.0.1:3100/loki is the actual address used for submitting logs to the server

---- Cuegui configuration ----

in cuegui.yaml :

loki.servers:
  internal: http://127.0.0.1:3100/loki

internal is the server reference name
http://127.0.0.1:3100/loki is the actual address used for pulling logs from the server

When reading a log file in cuegui it looks like this :
image

---- Limitation ----
Currently it does not support multiple logs from the same frame in CueGui. (for non-file based logging)
Does not yet support authentication and "X-Scope-OrgID" is hardcoded to "1" (when using Loki)

@lithorus
Copy link
Collaborator Author

lithorus commented Jul 1, 2024

I should also mention that I've replaced the pipe_to_file with a MUCH simpler method that "should" be cross-platform.

@lithorus
Copy link
Collaborator Author

lithorus commented Jul 8, 2024

It should be noted that I cannot re-produce the error in the "Python Unit Tests (CY2023)" locally (in the docker container).

lithorus and others added 2 commits July 16, 2024 23:13
@lithorus
Copy link
Collaborator Author

I'm afraid I had to undo the changes from #1335 since this changes how things are logged. Hopefully it should be easier to re-implement again.

@ramonfigueiredo
Copy link
Collaborator

I'm afraid I had to undo the changes from #1335 since this changes how things are logged. Hopefully it should be easier to re-implement again.

Hi @lithorus

Ok, I see.

How does your solution with Loki handle non-ASCII characters in the logs?

What happens with RQD when logs contain characters like these: 영화, café?

Does RQD crash with non-ASCII characters in the logs?

Additionally, I think it would be beneficial to provide a logging solution using Loki that can be enabled or disabled. This way, we can revert to the previous default logging methods if Loki logs are disabled.

So for me, this current solution should be kept if the Loki logs are disabled.

@lithorus
Copy link
Collaborator Author

lithorus commented Jul 17, 2024

I'm afraid I had to undo the changes from #1335 since this changes how things are logged. Hopefully it should be easier to re-implement again.

Hi @lithorus

Ok, I see.

How does your solution with Loki handle non-ASCII characters in the logs?

What happens with RQD when logs contain characters like these: 영화, café?

Does RQD crash with non-ASCII characters in the logs?

Additionally, I think it would be beneficial to provide a logging solution using Loki that can be enabled or disabled. This way, we can revert to the previous default logging methods if Loki logs are disabled.

So for me, this current solution should be kept if the Loki logs are disabled.

You're right, it would crash if it got non-ascii characters. I tested it out with cat /usr/bin/ps in the render command and it would crash. I've now implemented a generic way to convert (although I settled for utf-8 instead).

I will wrote the details on how Loki is enabled/disabled in the summary of this PR.

@ramonfigueiredo
Copy link
Collaborator

I'm afraid I had to undo the changes from #1335 since this changes how things are logged. Hopefully it should be easier to re-implement again.

Hi @lithorus
Ok, I see.
How does your solution with Loki handle non-ASCII characters in the logs?
What happens with RQD when logs contain characters like these: 영화, café?
Does RQD crash with non-ASCII characters in the logs?
Additionally, I think it would be beneficial to provide a logging solution using Loki that can be enabled or disabled. This way, we can revert to the previous default logging methods if Loki logs are disabled.
So for me, this current solution should be kept if the Loki logs are disabled.

You're right, it would crash if it got non-ascii characters. I tested it out with cat /usr/bin/ps in the render command and it would crash. I've now implemented a generic way to convert (although I settled for utf-8 instead).

I will wrote the details on how Loki is enabled/disabled in the summary of this PR.

Great, thanks @lithorus !

@lithorus
Copy link
Collaborator Author

I'm afraid I had to undo the changes from #1335 since this changes how things are logged. Hopefully it should be easier to re-implement again.

Hi @lithorus
Ok, I see.
How does your solution with Loki handle non-ASCII characters in the logs?
What happens with RQD when logs contain characters like these: 영화, café?
Does RQD crash with non-ASCII characters in the logs?
Additionally, I think it would be beneficial to provide a logging solution using Loki that can be enabled or disabled. This way, we can revert to the previous default logging methods if Loki logs are disabled.
So for me, this current solution should be kept if the Loki logs are disabled.

You're right, it would crash if it got non-ascii characters. I tested it out with cat /usr/bin/ps in the render command and it would crash. I've now implemented a generic way to convert (although I settled for utf-8 instead).
I will wrote the details on how Loki is enabled/disabled in the summary of this PR.

Great, thanks @lithorus !

Have added some more details on it now.

Comment on lines +341 to +346
while True:
output = frameInfo.forkedCommand.stdout.readline()
if not output and frameInfo.forkedCommand.poll() is not None:
break
if output:
self.rqlog.write(output, prependTimestamp=rqd.rqconstants.RQD_PREPEND_TIMESTAMP)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic doesn't seem to have the same problems of the previous logic when RQD_PREPEND_TIMESTAMP=False (See #1426 ) but one think I'm not quite sure I understand is how stderr is being parsed.

The logic from pipe_to_file that got removed allows parsing both stdout and stderr into a single output without blocking on waiting on one of the pipes. Probably something similar will be required if we want both stdout and stderr content to be sent to Loki.

Copy link
Collaborator Author

@lithorus lithorus Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I remember both STDOUT and STDERR is being piped and thus end out the same way. I'm almost certain I tested exactly for that. Let me double check it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both STDOUT and STDERR works (tested it with the file output, but should be the same for loki)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, will it be ok to have the loki part still being beta/experimental? This PR changes alot more than just adding support for loki.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I remember how it was done. stderr is sent to stdout, of course there won't be any distinguish between the 2, which might be good to have in loki as seperate tags.

stderr=subprocess.STDOUT,

@lithorus
Copy link
Collaborator Author

@DiegoTavares I've created another PR with only the log abstraction and without the Loki part. There was still missing a few bits and pieces on that part before it was ready for production and would like to explore a few ideas on how to make it more modular.

@DiegoTavares
Copy link
Collaborator

@DiegoTavares I've created another PR with only the log abstraction and without the Loki part. There was still missing a few bits and pieces on that part before it was ready for production and would like to explore a few ideas on how to make it more modular.

Great, I have it on my list to be reviewed soon.

As this change adds a new feature, it will require changes to the documentation on opencue.io's Other Guides section. This website is maintained in this repo.

@lithorus
Copy link
Collaborator Author

Will re-do the implementation.

@lithorus lithorus closed this Jul 31, 2024
DiegoTavares pushed a commit that referenced this pull request Aug 1, 2024
**Link the Issue(s) this Pull Request is related to.**
#1401 #1427 

**Summarize your change.**
This abstracts the reading of logs and writing log files. This makes it
simpler to do things like supporting other logging types and conversions
(eg. make sure things are ASCII) in a single class across all platforms.
This is a smaller version of #1401 with just the file logging
abstracted. It also implements the changes from #1427

Co-authored by @ramonfigueiredo and @lithorus

---------

Signed-off-by: Jimmy Christensen <[email protected]>
Co-authored-by: Ramon Figueiredo <[email protected]>
KernAttila pushed a commit to Wolf-Pipeline/OpenCue that referenced this pull request Aug 8, 2024
…demySoftwareFoundation#1429)

**Link the Issue(s) this Pull Request is related to.**
AcademySoftwareFoundation#1401 AcademySoftwareFoundation#1427 

**Summarize your change.**
This abstracts the reading of logs and writing log files. This makes it
simpler to do things like supporting other logging types and conversions
(eg. make sure things are ASCII) in a single class across all platforms.
This is a smaller version of AcademySoftwareFoundation#1401 with just the file logging
abstracted. It also implements the changes from AcademySoftwareFoundation#1427

Co-authored by @ramonfigueiredo and @lithorus

---------

Signed-off-by: Jimmy Christensen <[email protected]>
Co-authored-by: Ramon Figueiredo <[email protected]>
KernAttila pushed a commit to Wolf-Pipeline/OpenCue that referenced this pull request Aug 15, 2024
…demySoftwareFoundation#1429)

**Link the Issue(s) this Pull Request is related to.**
AcademySoftwareFoundation#1401 AcademySoftwareFoundation#1427 

**Summarize your change.**
This abstracts the reading of logs and writing log files. This makes it
simpler to do things like supporting other logging types and conversions
(eg. make sure things are ASCII) in a single class across all platforms.
This is a smaller version of AcademySoftwareFoundation#1401 with just the file logging
abstracted. It also implements the changes from AcademySoftwareFoundation#1427

Co-authored by @ramonfigueiredo and @lithorus

---------

Signed-off-by: Jimmy Christensen <[email protected]>
Co-authored-by: Ramon Figueiredo <[email protected]>
@lithorus lithorus deleted the loki-logger branch September 19, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants