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

[Serverless] Allow some keys to be option in serverless integration tests. #14827

Merged
merged 2 commits into from
Dec 21, 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
45 changes: 38 additions & 7 deletions test/integration/serverless/log_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def normalize_logs(stage):
replace(stage, 'XXXXXX'),
replace(r'(architecture:)(x86_64|arm64)', r'\1XXX'),
sort_by(lambda log: log["message"]["message"]),
# ignore a Lambda error that occurs sporadically for log-csharp see here for more info:
# https://repost.aws/questions/QUq2OfIFUNTCyCKsChfJLr5w/lambda-function-working-locally-but-crashing-on-aws
# TODO
# perl -n -e "print unless /LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint/ or \
# /An error occurred while attempting to execute your code.: LambdaException/ or \
# /terminate called after throwing an instance of 'std::logic_error'/ or \
# /basic_string::_M_construct null not valid/" |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our tests are passing without this change. So I removed it.

# TODO: these messages may be an indication of a real problem and
# should be investigated
rm_item(
lambda log: log["message"]["message"]
in (
"TIMESTAMP UTC | DD_EXTENSION | ERROR | could not forward the request context canceled\n",
"TIMESTAMP http: proxy error: context canceled\n",
)
),
]


Expand Down Expand Up @@ -79,6 +81,9 @@ def normalize_traces(stage):


def replace(pattern, repl):
"""
Replace all substrings matching regex pattern with given replacement string
"""
comp = re.compile(pattern, flags=re.DOTALL)

def _replace(log):
Expand All @@ -88,10 +93,16 @@ def _replace(log):


def exclude(pattern):
"""
Remove all substrings matching regex pattern
"""
return replace(pattern, '')


def require(pattern):
"""
Remove all substrings that don't match the given regex pattern
"""
comp = re.compile(pattern, flags=re.DOTALL)

def _require(log):
Expand All @@ -104,6 +115,11 @@ def _require(log):


def sort_by(key):
"""
Sort the json entries using the given key function, requires the log string
to be proper json and to be a list
"""

def _sort(log):
log_json = json.loads(log, strict=False)
log_sorted = sorted(log_json, key=key)
Expand All @@ -112,6 +128,21 @@ def _sort(log):
return _sort


def rm_item(key):
"""
Delete json entries from the log string using the given key function, key
takes an item from the json list and must return boolean which is True when
the item is to be removed and False if it is to be kept
"""

def _rm_item(log):
log_json = json.loads(log, strict=False)
new_logs = [i for i in log_json if not key(i)]
return json.dumps(new_logs)

return _rm_item


###################
# END NORMALIZERS #
###################
Expand Down
30 changes: 0 additions & 30 deletions test/integration/serverless/snapshots/log-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,5 @@
"service": "integration-tests-service",
"ddsource": "lambda",
"ddtags": "account_id:425362996713,architecture:XXX,aws_account:425362996713,dd_extension_version:123,env:integration-tests-env,function_arn:arn:aws:lambda:eu-west-1:425362996713:function:integration-tests-extension-XXXXXX-log-proxy,functionname:integration-tests-extension-XXXXXX-log-proxy,memorysize:1024,region:eu-west-1,resource:integration-tests-extension-XXXXXX-log-proxy,runtime:nodejs14.x,service:integration-tests-service,taga:valuea,tagb:valueb,tagc:valuec,tagd:valued,version:integration-tests-version"
},
{
"message": {
"message": "TIMESTAMP UTC | DD_EXTENSION | ERROR | could not forward the request context canceled\n",
"lambda": {
"arn": "arn:aws:lambda:eu-west-1:425362996713:function:integration-tests-extension-XXXXXX-log-proxy",
"request_id": "XXX"
}
},
"status": "info",
"timestamp": "XXX",
"hostname": "arn:aws:lambda:eu-west-1:425362996713:function:integration-tests-extension-XXXXXX-log-proxy",
"service": "integration-tests-service",
"ddsource": "lambda",
"ddtags": "account_id:425362996713,architecture:XXX,aws_account:425362996713,dd_extension_version:123,env:integration-tests-env,function_arn:arn:aws:lambda:eu-west-1:425362996713:function:integration-tests-extension-XXXXXX-log-proxy,functionname:integration-tests-extension-XXXXXX-log-proxy,memorysize:1024,region:eu-west-1,resource:integration-tests-extension-XXXXXX-log-proxy,runtime:nodejs14.x,service:integration-tests-service,taga:valuea,tagb:valueb,tagc:valuec,tagd:valued,version:integration-tests-version"
},
{
"message": {
"message": "TIMESTAMP http: proxy error: context canceled\n",
"lambda": {
"arn": "arn:aws:lambda:eu-west-1:425362996713:function:integration-tests-extension-XXXXXX-log-proxy",
"request_id": "XXX"
}
},
"status": "info",
"timestamp": "XXX",
"hostname": "arn:aws:lambda:eu-west-1:425362996713:function:integration-tests-extension-XXXXXX-log-proxy",
"service": "integration-tests-service",
"ddsource": "lambda",
"ddtags": "account_id:425362996713,architecture:XXX,aws_account:425362996713,dd_extension_version:123,env:integration-tests-env,function_arn:arn:aws:lambda:eu-west-1:425362996713:function:integration-tests-extension-XXXXXX-log-proxy,functionname:integration-tests-extension-XXXXXX-log-proxy,memorysize:1024,region:eu-west-1,resource:integration-tests-extension-XXXXXX-log-proxy,runtime:nodejs14.x,service:integration-tests-service,taga:valuea,tagb:valueb,tagc:valuec,tagd:valued,version:integration-tests-version"
}
]