Skip to content

Commit db7ec15

Browse files
committed
Refactor sed calls for better readability
1 parent 583bd56 commit db7ec15

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

scripts/run_integration_tests.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# Usage:
44
# To check if new changes to the layer cause changes to any snapshots:
5-
# BUILD_LAYERS=true DD_API_KEY=XXXX aws-vault exec sandbox-account-admin -- ./scripts/run_integration_tests
5+
# BUILD_LAYERS=true DD_API_KEY=XXXX aws-vault exec sandbox-account-admin -- ./scripts/run_integration_tests
66
# To regenerate snapshots:
7-
# UPDATE_SNAPSHOTS=true DD_API_KEY=XXXX aws-vault exec sandbox-account-admin -- ./scripts/run_integration_tests
7+
# UPDATE_SNAPSHOTS=true DD_API_KEY=XXXX aws-vault exec sandbox-account-admin -- ./scripts/run_integration_tests
88

99
set -e
1010

@@ -85,22 +85,22 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
8585
function_snapshot_path="./snapshots/$function_name.logs"
8686

8787
# Fetch logs with serverless cli
88-
logs=$(serverless logs -f $function_name --startTime $script_start_time)
89-
90-
# Filter serverless cli errors
91-
logs=$(echo "$logs" | sed '/Serverless: Recoverable error occurred/d')
88+
raw_logs=$(serverless logs -f $function_name --startTime $script_start_time)
9289

9390
# Replace invocation-specific data like timestamps and IDs with XXXX to normalize logs across executions
94-
# Normalize Lambda runtime report logs
95-
logs=$(echo "$logs" | sed -E 's/(RequestId|TraceId|SegmentId|Duration|Memory Used|"e"): [a-z0-9\.\-]+/\1: XXXX/g')
96-
# Normalize DD APM headers
97-
logs=$(echo "$logs" | sed -E "s/(x-datadog-parent-id:|x-datadog-trace-id:)[0-9]+/\1XXXX/g")
98-
# Normalize timestamps in datapoints POSTed to DD
99-
logs=$(echo "$logs" | sed -E 's/"points": \[\[[0-9\.]+,/"points": \[\[XXXX,/g')
100-
# # Normalize invocation IDs used in requests to the Lambda runtime
101-
# logs=$(echo "$logs" | sed -E 's/\/2018-06-01\/runtime\/invocation\/[a-z0-9-]+/\/2018-06-01\/runtime\/invocation\/XXXX/g')
102-
# Strip API key from logged requests
103-
logs=$(echo "$logs" | sed -E "s/(api_key=|'api_key': ')[a-z0-9\.\-]+/\1XXXX/g")
91+
logs=$(
92+
echo "$raw_logs" |
93+
# Filter serverless cli errors
94+
sed '/Serverless: Recoverable error occurred/d' |
95+
# Normalize Lambda runtime report logs
96+
sed -E 's/(RequestId|TraceId|SegmentId|Duration|Memory Used|"e"): [a-z0-9\.\-]+/\1: XXXX/g' |
97+
# Normalize DD APM headers
98+
sed -E "s/(x-datadog-parent-id:|x-datadog-trace-id:)[0-9]+/\1XXXX/g" |
99+
# Normalize timestamps in datapoints POSTed to DD
100+
sed -E 's/"points": \[\[[0-9\.]+,/"points": \[\[XXXX,/g' |
101+
# Strip API key from logged requests
102+
sed -E "s/(api_key=|'api_key': ')[a-z0-9\.\-]+/\1XXXX/g"
103+
)
104104

105105
if [ -n "$UPDATE_SNAPSHOTS" ] || [ ! -f $function_snapshot_path ]; then
106106
# If $UPDATE_SNAPSHOTS is set to true write the new logs over the current snapshot

0 commit comments

Comments
 (0)