Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/hive_cli/libs/common_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import io
import signal
import subprocess
import threading
import time

import psutil
import requests

GCR_SANDBOX_BUCKET = "hi-sandbox"
Expand Down Expand Up @@ -55,7 +53,7 @@ def run_command(
raise FunctionExecutionError(error_code_to_string(-process.returncode))
if process.returncode != 0:
raise FunctionExecutionError(f"Error: {stderr}")
return stdout
return stdout.strip().splitlines()[-1] # Return only the last line of output

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Always take the last line of the output as metrics as one solution as we discussed last Friday, WDYT? @brp-hiverge

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it always going to be only one line?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From my experience, we always use the last line of the output. And for json.dumps(), it's always one line.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that json.dumps() indeed returns one line, but what if we have a field in the json that contains a multiline content (e.g. feedback)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually the newline is escaped as \n, rather than an actual line break. So what you propose makes a lot of sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The \n in json.dumps() will not lead to a new line.

except subprocess.TimeoutExpired as exc:
process.kill()
raise FunctionExecutionError("Timeout") from exc
Expand Down
Loading