-
Notifications
You must be signed in to change notification settings - Fork 203
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
[rqd] Fix non ASCII chars #1335
Changes from all commits
fe618e3
8fdfc93
20d5864
31e1402
2e1ece4
75f9236
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,17 +318,13 @@ def runLinux(self): | |
else: | ||
tempCommand += [self._createCommandFile(runFrame.command)] | ||
|
||
if rqd.rqconstants.RQD_PREPEND_TIMESTAMP: | ||
file_descriptor = subprocess.PIPE | ||
else: | ||
file_descriptor = self.rqlog | ||
# pylint: disable=subprocess-popen-preexec-fn | ||
frameInfo.forkedCommand = subprocess.Popen(tempCommand, | ||
env=self.frameEnv, | ||
cwd=self.rqCore.machine.getTempPath(), | ||
stdin=subprocess.PIPE, | ||
stdout=file_descriptor, | ||
stderr=file_descriptor, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
close_fds=True, | ||
preexec_fn=os.setsid) | ||
finally: | ||
|
@@ -343,6 +339,16 @@ def runLinux(self): | |
|
||
if rqd.rqconstants.RQD_PREPEND_TIMESTAMP: | ||
pipe_to_file(frameInfo.forkedCommand.stdout, frameInfo.forkedCommand.stderr, self.rqlog) | ||
else: | ||
with open(self.rqlog, 'a') as f: | ||
# Convert to ASCII while discarding characters that can not be encoded | ||
for line in frameInfo.forkedCommand.stdout: | ||
line = line.encode('ascii', 'ignore') | ||
f.write(line.decode('ascii') + '\n') | ||
for line in frameInfo.forkedCommand.stderr: | ||
line = line.encode('ascii', 'ignore') | ||
f.write(line.decode('ascii') + '\n') | ||
|
||
returncode = frameInfo.forkedCommand.wait() | ||
|
||
# Find exitStatus and exitSignal | ||
|
@@ -1222,6 +1228,8 @@ def print_and_flush_ln(fd, last_timestamp): | |
|
||
remainder = lines[-1] | ||
for line in lines[0:-1]: | ||
# Convert to ASCII while discarding characters that can not be encoded | ||
line = line.encode('ascii', 'ignore') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ramonfigueiredo Thank you for the PR and the detailed write up. The detail makes it nice and easy to review with the proper context. So, this error occurs when we intercept output in order to prepend a timestamp. What is logged to the file when My sense is that the output which is logged when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dear @bcipriano , Sorry for the delay in answering your question. Thank you for your thorough review and the positive feedback on the PR and write-up. Regarding your comment, the Here is how the output differs based on the value of RQD_PREPEND_TIMESTAMP:
To ensure the outputs are as similar as possible, aside from the timestamp, I can adjust our approach to handle encoding more gracefully. Instead of discarding non-ASCII characters, I can consider other strategies, such as escaping them or converting them to a specific placeholder. However, given the current solution, the primary goal was to prevent crashes due to If maintaining non-ASCII characters is critical, I can explore additional strategies to handle encoding more gracefully without discarding valuable information. I am open to suggestions and further discussion on the best approach to balance robustness and information retention. Thank you again for your review and insights. I look forward to your feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @bcipriano FYI ... The updated logic to ensure consistent handling of non-ASCII characters in logs with RQD_PREPEND_TIMESTAMP = True or RQD_PREPEND_TIMESTAMP = False. |
||
print("[%s] %s" % (curr_line_timestamp, line), file=outfile) | ||
outfile.flush() | ||
os.fsync(outfile) | ||
|
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.
It looks like this broke file logging.
self.rqlog
is a file object and not a string.(When not using
RQD_PREPEND_TIMESTAMP=True
)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'll take a look and fix that soon!
Thanks!
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 should note that #1401 changes alot of this logic anyway (if it gets merged)
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.
Hi @lithorus
FYI ...
I changed the code to prevent crashes due to TypeError and fixed the broken file logging. Thanks!
This is the new PR: #1417 . PR was merged into the master!
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.
Hi @lithorus ,
Let me know when your PR #1401 is ready for review. For now, it is on draft and some checks/pipelines are falling.
For sure it is a nice feature. Since Loki offers efficient, scalable log aggregation, cost savings, seamless Prometheus/Grafana integration, and strong community support. Thanks!
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.
Yes, I will write some examples and documentation on how it's used after #1416 is merged (some of the loki stuff is not compatible with python 2.x)
Also, seeing the recent sentry support in cuebot, it would be interesting to also add support for that aswell.
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.
Great. Thanks!