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 loki realtime logging #130

Merged
merged 2 commits into from
Jun 11, 2024
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
38 changes: 37 additions & 1 deletion pilot/util/realtimelogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def __init__(self, args, info_dic, workdir, secrets, level=INFO):
transport=transport,
database_path='logstash_test.db'
)

elif logtype == 'loki':
_handler = self.setup_loki_handler()
else:
logger.warning(f'unknown logtype: {logtype}')
_handler = None
Expand All @@ -194,6 +195,41 @@ def __init__(self, args, info_dic, workdir, secrets, level=INFO):
RealTimeLogger.glogger = None
del self

def setup_loki_handler(self):
from loki_logger_handler.loki_logger_handler import LokiLoggerHandler

loki_labels = {'application': 'PanDA_Pilot', 'envirnment': 'Production'}
try:
labels = os.environ.get('LOKI_LABELS', {})
if labels:
labels = json.loads(labels)
loki_labels = labels
except Exception as ex:
logger.warning(f'failed to load LOKI_LABELS from environment: {ex}')

loki_labelkeys = ['application', 'environment']
try:
labelkeys = os.environ.get('LOKI_LABELKEYS', {})
if labelkeys:
labelkeys = json.loads(labelkeys)
loki_labelkeys = labelkeys
except Exception as ex:
logger.warning(f'failed to load LOKI_LABELKEYS from environment: {ex}')

try:
loki_period = int(os.environ.get('LOKI_PERIOD', 30))
except Exception as ex:
logger.warning(f'failed to load LOKI_PERIOD from environment: {ex}')
loki_period = 30

_handler = LokiLoggerHandler(
url=os.environ["LOKI_URL"],
labels=loki_labels,
labelKeys=loki_labelkeys,
timeout=loki_period
)
return _handler

def cleanup(self):
"""
Clean-up.
Expand Down
Loading