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

Logs fields are saved as int or float instead of text #59

Merged
merged 2 commits into from
Mar 24, 2022
Merged
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
8 changes: 7 additions & 1 deletion spot/logs/aws_log_retriever.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import boto3
from spot.db.db import DBClient
from spot.constants import *
import re


class AWSLogRetriever:
Expand Down Expand Up @@ -38,7 +39,12 @@ def get_logs(self):
for message_section in message_sections[1:-1]:
field_name = message_section.split(":")[0]
value = message_section.split(":")[1][1:].split(" ")[0]
log[field_name] = value
if re.match(r"^[0-9]+\.[0-9]+$", value):
log[field_name] = float(value)
elif re.match(r"^[0-9]+$", value):
log[field_name] = int(value)
else:
log[field_name] = value
log[REQUEST_ID] = requestId

# add log to db
Expand Down
13 changes: 7 additions & 6 deletions tests/log_test/test_aws_log_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def mock_get_log(self, logGroupName, logStreamName):
"events": [
{
"timestamp": 100,
"message": f"REPORT RequestId: {logStreamName} Duration: 1.50 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 39 MB Init Duration: 113.44 ms",
"message": f"REPORT RequestId: {logStreamName} Duration: 1.50 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 39 MB Init Duration: 113.44 ms ",
"ingestionTime": 123,
},
]
Expand All @@ -56,18 +56,19 @@ def test_get_logs(self, mockBoto3) -> None:
logContent = {
"timestamp": 100,
"ingestionTime": 123,
"Duration": "1.50",
"Billed Duration": "2",
"Memory Size": "128",
"Max Memory Used": "39",
"Duration": 1.50,
"Billed Duration": 2,
"Memory Size": 128,
"Max Memory Used": 39,
"Init Duration": 113.44,
}

for s in stream["logStreams"]:
logTemp = logContent
name = s["logStreamName"]
logTemp[
"message"
] = f"REPORT RequestId: {name}\tDuration: 1.50 ms\tBilled Duration: 2 ms\tMemory Size: 128 MB\tMax Memory Used: 39 MB\tInit Duration: 113.44 ms"
] = f"REPORT RequestId: {name}\tDuration: 1.50 ms\tBilled Duration: 2 ms\tMemory Size: 128 MB\tMax Memory Used: 39 MB\tInit Duration: 113.44 ms\t"
logTemp["RequestId"] = name
callTemp = call(
self.function,
Expand Down