Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 11 additions & 4 deletions awslogs_sd/awslogs_sd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import argparse
import json
import os
import time
import itertools
import logging
Expand All @@ -25,7 +26,7 @@

# cloudwatch doesn't allow batch spans larger than 24h
MAX_BATCH_TIME_SPAN = timedelta(hours=24)
MAX_BATCH_ITEMS = 100
MAX_BATCH_ITEMS = int(os.getenv('AWSLOGS_SD_MAX_BATCH_ITEMS', 100))
BATCH_TIMEOUT_S = 1.0
MAX_QUEUE_SIZE = 100000

Expand Down Expand Up @@ -72,7 +73,8 @@
'local7': 23,
}


loglevel = os.getenv('AWSLOGS_SD_LOGLEVEL', logging.WARNING)
logging.basicConfig(level=loglevel)
logger = logging.getLogger('awslogs')


Expand Down Expand Up @@ -299,7 +301,7 @@ def push_records(client, records, unit_conf, state):
'logEvents': [
{
'timestamp': int(r.date.timestamp() * 1000),
'message': r.message
'message': r.message[0:1024]
}
for r in records
],
Expand Down Expand Up @@ -410,8 +412,13 @@ def create_log_streams(conf):
for unit_conf in conf.units:
group = unit_conf.log_group_name
name = unit_conf.log_stream_name
all_streams = []
resp = client.describe_log_streams(logGroupName=group)
matches = [g for g in resp['logStreams'] if g['logStreamName'] == name]
all_streams += resp['logStreams']
while 'nextToken' in resp:
resp = client.describe_log_streams(logGroupName=group, nextToken=resp['nextToken'])
all_streams += resp['logStreams']
matches = [g for g in all_streams if g['logStreamName'] == name]
if not matches:
logger.info('Creating log stream: %s', name)
client.create_log_stream(logGroupName=group, logStreamName=name)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
'awscli-cwlogs',
'boto3',
'gevent',
'pyyaml',
'PyYAML==5.3.1',
'requests',
'retrying',
'systemd-python',
'python-dateutil<2.8.1'
],
entry_points={
'console_scripts': [
Expand Down