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

Fix log collector date command #1048

Merged
merged 2 commits into from
Sep 9, 2022
Merged
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
11 changes: 9 additions & 2 deletions utils/log-collector
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ done

# CloudWatch stores the creationTime as milliseconds since epoch UTC.
# Since macOS doesn't support calculating the time since epoch in milliseconds, we don't have perfect accuracy on this, but it should be as close to 24 hours as possible
# while still being inclusive to all platforms that might run the script
# We'll check to see if we're running on a macOS-based OS and adjust appropriately, otherwise use the standard date command

# Currently only collects the last 24h of logs, but it might be good to be able to specify a different value for this.
logAge=$(date -v-1d "+%s000")

# check if we're running on a macOS based system, otherwise use the GNU-based date syntax
if [[ $OSTYPE == 'darwin'* ]]; then
logAge=$(date -v-1d "+%s000")
else
logAge=$(date --date="1day" "+%s000")
fi

# Collect some information about the Lambda function and associated log groups
lambdaFunction=$(aws cloudformation describe-stack-resources --stack-name "$stackName" --logical-resource-id Autoscaling --query "StackResources[*].PhysicalResourceId" --output text | sed -nr 's/.*stack\/(.*)\/.*/\1/p')
Expand All @@ -81,6 +87,7 @@ logStreams=$(aws logs describe-log-streams --log-group-name "$lambdaLogGroup" --

# Iterate through all of the log streams we collected from the lambda log group
echo "Collecting Lambda logs for $lambdaFunction"

for i in $logStreams
do
fileName=$(echo "$i" | sed -r 's/\//-/g')
Expand Down