Skip to content

Commit

Permalink
Merge pull request #2705 from locustio/only-write-hostname-instead-of…
Browse files Browse the repository at this point in the history
…-fqdn-to-logs

Logging: Only print hostname instead of FQDN
  • Loading branch information
cyberw authored May 8, 2024
2 parents 4be0a7e + c87be93 commit ed91d32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
27 changes: 12 additions & 15 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
DEFAULT_CONFIG_FILES = ("~/.locust.conf", "locust.conf", "pyproject.toml")


# Clean up downloaded locustfile on exit
def exit_handler(filename) -> None:
try:
os.remove(filename)
except FileNotFoundError:
pass # when multiple workers are running on the same machine, another one may already have deleted it
except PermissionError:
pass # this happens occasionally on windows on GH, maybe for the same reason?


class LocustArgumentParser(configargparse.ArgumentParser):
"""Drop-in replacement for `configargparse.ArgumentParser` that adds support for
optionally exclude arguments from the UI.
Expand Down Expand Up @@ -170,14 +180,7 @@ def download_locustfile_from_url(url: str) -> str:
with open(os.path.join(tempfile.gettempdir(), url.rsplit("/", 1)[-1]), "w") as locustfile:
locustfile.write(response.text)

# Clean up downloaded files on exit
def exit_handler():
try:
os.remove(locustfile.name)
except FileNotFoundError:
pass # this is normal when multiple workers are running on the same machine

atexit.register(exit_handler)
atexit.register(exit_handler, locustfile.name)
return locustfile.name


Expand Down Expand Up @@ -263,13 +266,7 @@ def wait_for_reply():
with open(os.path.join(tempfile.gettempdir(), filename), "w", encoding="utf-8") as locustfile:
locustfile.write(msg.data["contents"])

def exit_handler():
try:
os.remove(locustfile.name)
except FileNotFoundError:
pass # this is normal when multiple workers are running on the same machine

atexit.register(exit_handler)
atexit.register(exit_handler, locustfile.name)

tempclient.close()
return locustfile.name
Expand Down
3 changes: 2 additions & 1 deletion locust/log.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import logging.config
import re
import socket

HOSTNAME = socket.gethostname()
HOSTNAME = re.sub(r"\..*", "", socket.gethostname())

# Global flag that we set to True if any unhandled exception occurs in a greenlet
# Used by main.py to set the process return code to non-zero
Expand Down

0 comments on commit ed91d32

Please sign in to comment.