Skip to content

Commit

Permalink
Merge pull request #130 from wguanicedew/master
Browse files Browse the repository at this point in the history
add loki realtime logging
  • Loading branch information
PalNilsson authored Jun 11, 2024
2 parents e9530a3 + c18a348 commit 58519b2
Showing 1 changed file with 37 additions and 1 deletion.
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

0 comments on commit 58519b2

Please sign in to comment.