Skip to content
Closed
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
10 changes: 10 additions & 0 deletions src/robusta/runner/process_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from functools import lru_cache
from robusta.core.model.env_vars import RUN_AS_SUBPROCESS

JSON_LOGGING = os.environ.get("ROBUSTA_JSON_LOGGING", "").lower() in ("true", "1", "yes")


def process_setup():
# Cache getLogger calls as we are seeing kubernetes-client locking on logging causing event processing to be extremely delayed
Expand All @@ -13,6 +15,14 @@ def process_setup():
# Inspiration from Yelp - https://github.com/Yelp/Tron/blob/36337d92fa92bba3da8c5fcc65235697d009eb36/tron/trondaemon.py#L58
logging.getLogger = lru_cache(maxsize=None)(logging.getLogger)

if JSON_LOGGING:
from pythonjsonlogger import jsonlogger
root_logger = logging.getLogger()
handler = logging.StreamHandler()
formatter = jsonlogger.JsonFormatter()
handler.setFormatter(formatter)
root_logger.handlers = [handler]

if RUN_AS_SUBPROCESS:
if os.fork():
# Parent process, pid 1 in our deployment scenario. Wait (blocking - doesn't
Expand Down