Skip to content

Commit a5061c2

Browse files
committed
Removed unecessary comments and fix a typo
1 parent 108e893 commit a5061c2

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

aws/logs_monitoring/lambda_function.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
# http specific
6666
DD_USE_HTTP = True
67-
DD_BATCH_SIZE = "10"
67+
DD_BATCH_SIZE = 10
6868

6969
# Pass custom tags as environment variable, ensure comma separated, no trailing comma in envvar!
7070
DD_TAGS = os.environ.get("DD_TAGS", "")
@@ -143,13 +143,13 @@ class DatadogHTTPClient(object):
143143
_POST = "POST"
144144
_HEADERS = {"Content-type": "application/json"}
145145

146-
def __init__(self, host, apiKey, timeout=1, max_retries=1, backoff=0.5):
146+
def __init__(self, host, apiKey, timeout=10, max_retries=1, backoff=0.5):
147147
self._url = "https://{}/v1/input/{}".format(host, apiKey)
148148
self._session = requests.Session()
149149
self._session.headers.update(self._HEADERS)
150-
self._timeout = timeout if timeout > 0 else 1
151-
self._max_retries = max_retries if max_retries >= 0 else 1
152-
self._backoff = backoff if backoff > 0 else 0.5
150+
self._timeout = timeout
151+
self._max_retries = max_retries
152+
self._backoff = backoff
153153

154154
def send(self, batch, metadata=None):
155155
"""
@@ -159,23 +159,16 @@ def send(self, batch, metadata=None):
159159
body = json.dumps(batch)
160160
for retry in range(1 + self._max_retries):
161161
if retry > 0:
162-
print("Retrying, retry: {}, max: {}".format(retry, self._max_retries))
163162
time.sleep(self._backoff)
164163
try:
165164
resp = self._session.post(
166165
self._url, data=body, params=metadata, timeout=self._timeout
167166
)
168167
except Exception as e:
169168
# most likely a network error
170-
print("Unexpected exception: {}".format(str(e)))
171169
continue
172170
if resp.status_code >= 500:
173171
# server error
174-
print(
175-
"Server error, status {}, reason: {}".format(
176-
resp.status_code, resp.reason
177-
)
178-
)
179172
continue
180173
elif resp.status_code >= 400:
181174
# client error
@@ -207,10 +200,7 @@ def batch(self, logs):
207200
each batch contains at most max_size logs.
208201
"""
209202
batches = []
210-
if len(logs) % self._max_size != 0:
211-
nb_batchs = int(len(logs) / self._max_size) + 1
212-
else:
213-
nb_batchs = int(len(logs) / self._max_size)
203+
nb_batchs = int(len(logs) / self._max_size) + 1
214204
for i in range(0, nb_batchs):
215205
l = i * self._max_size
216206
r = (i + 1) * self._max_size

0 commit comments

Comments
 (0)