Skip to content

Commit

Permalink
add loki realtime logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wguanicedew committed Jun 10, 2024
1 parent 666430e commit 6a0c9a9
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pilot/util/realtimelogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,39 @@ def __init__(self, args, info_dic, workdir, secrets, level=INFO):
transport=transport,
database_path='logstash_test.db'
)

elif logtype == 'loki':
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
)
else:
logger.warning(f'unknown logtype: {logtype}')
_handler = None
Expand Down

0 comments on commit 6a0c9a9

Please sign in to comment.