Skip to content

Commit

Permalink
Add .NET handlers and tests (#37)
Browse files Browse the repository at this point in the history
* add csharp handler and test

* remove unused line in gitignore
  • Loading branch information
jcstorms1 authored Nov 9, 2021
1 parent 7973f5a commit ed89375
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ integration_tests/recorder-extension/ext.zip
integration_tests/.DS_Store
integration_tests/bootstrap
integration_tests/src/bin
integration_tests/src/csharp-tests/bin
integration_tests/src/csharp-tests/obj
.DS_Store
.layers
extensions
scripts/.cache
scripts/.src
scripts/.layers
23 changes: 16 additions & 7 deletions integration_tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ cd src
for go_dir in "${go_test_dirs[@]}"; do
env GOOS=linux go build -ldflags="-s -w" -o bin/"$go_dir" go-tests/"$go_dir"/main.go
done
cd ..

#build .NET function
cd csharp-tests
dotnet restore
set +e #set this so we don't exit if the tools are already installed
dotnet tool install -g Amazon.Lambda.Tools --framework netcoreapp3.1
dotnet lambda package --configuration Release --framework netcoreapp3.1 --output-package bin/Release/netcoreapp3.1/handler.zip
set -e
cd ../../

if [ -z "$NODE_LAYER_VERSION" ]; then
echo "NODE_LAYER_VERSION not found, using the default"
Expand Down Expand Up @@ -79,12 +87,13 @@ NODE_LAYER_VERSION=${NODE_LAYER_VERSION} \
serverless deploy --stage ${stage}

# invoke functions
python_node_function_names=("enhanced-metric-node" "enhanced-metric-python" "no-enhanced-metric-node" "no-enhanced-metric-python" "timeout-python" "timeout-node" "error-node" "error-python")
python_node_log_function_names=("log-node" "log-python")
metric_function_names=("enhanced-metric-node" "enhanced-metric-python" "metric-csharp" "no-enhanced-metric-node" "no-enhanced-metric-python" "timeout-python" "timeout-node")
log_function_names=("log-node" "log-python" "log-csharp")

go_function_names=("with-ddlambda-go" "without-ddlambda-go" "timeout-go")
trace_function_names=("simple-trace-node" "simple-trace-python" "simple-trace-go")

all_functions=("${python_node_function_names[@]}" "${python_node_log_function_names[@]}" "${go_function_names[@]}" "${trace_function_names[@]}")
all_functions=("${metric_function_names[@]}" "${log_function_names[@]}" "${go_function_names[@]}" "${trace_function_names[@]}")

set +e # Don't exit this script if an invocation fails or there's a diff

Expand Down Expand Up @@ -123,7 +132,7 @@ for function_name in "${all_functions[@]}"; do
done

# Replace invocation-specific data like timestamps and IDs with XXX to normalize across executions
if [[ " ${python_node_function_names[@]} " =~ " ${function_name} " ]]; then
if [[ " ${metric_function_names[*]} " =~ " ${function_name} " ]]; then
# Normalize metrics
logs=$(
echo "$raw_logs" |
Expand All @@ -142,7 +151,7 @@ for function_name in "${all_functions[@]}"; do
perl -p -e "s/$stage/XXXXXX/g" |
sort
)
elif [[ " ${python_node_log_function_names[@]} " =~ " ${function_name} " ]]; then
elif [[ " ${log_function_names[*]} " =~ " ${function_name} " ]]; then
# Normalize logs
logs=$(
echo "$raw_logs" |
Expand All @@ -155,7 +164,7 @@ for function_name in "${all_functions[@]}"; do
perl -p -e "s/(\"message\":\").*(XXX LOG)/\1\2\3/g" |
grep XXX
)
elif [[ " ${go_function_names[@]} " =~ " ${function_name} " ]]; then
elif [[ " ${go_function_names[*]} " =~ " ${function_name} " ]]; then
logs=$(
echo "$raw_logs" |
grep -E "\[sketch\]|\[log\]" |
Expand Down
32 changes: 32 additions & 0 deletions integration_tests/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,35 @@ functions:
DD_EXTRA_TAGS: tagC:valueC tagD:valueD
DD_TRACE_ENABLED: true
DD_APM_DD_URL: http://127.0.0.1:3333

metric-csharp:
runtime: dotnetcore3.1
handler: CsharpHandlers::AwsDotnetCsharp.Handler::Hello
package:
individually: true
artifact: src/csharp-tests/bin/Release/netcoreapp3.1/handler.zip
layers:
- { Ref: RecorderExtensionLambdaLayer }
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
environment:
DD_TAGS: tagA:valueA tagB:valueB
DD_EXTRA_TAGS: tagC:valueC tagD:valueD
DD_LOGS_ENABLED: true
DD_SERVERLESS_LOGS_ENABLED: true
DD_LOGS_INJECTION: true

log-csharp:
runtime: dotnetcore3.1
handler: CsharpHandlers::AwsDotnetCsharp.Handler::Logs
package:
individually: true
artifact: src/csharp-tests/bin/Release/netcoreapp3.1/handler.zip
layers:
- { Ref: RecorderExtensionLambdaLayer }
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
environment:
DD_TAGS: tagA:valueA tagB:valueB
DD_EXTRA_TAGS: tagC:valueC tagD:valueD
DD_LOGS_ENABLED: true
DD_SERVERLESS_LOGS_ENABLED: true
DD_LOGS_INJECTION: true
4 changes: 4 additions & 0 deletions integration_tests/snapshots/log-csharp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[log] {"message":{"message":"START XXX"}}
[log] {"message":{"message":"XXX Log 0 XXX\n","lambda":{"arn":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp"}},"status":"info","timestamp":TIMESTAMP,"hostname":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp","service":"integration-tests-service","ddsource":"lambda","ddtags":"account_id:601427279990,account_id:601427279990,account_id:601427279990,architecture:x86_64,architecture:x86_64,architecture:x86_64,aws_account:601427279990,aws_account:601427279990,aws_account:601427279990,dd_extension_version:123,dd_extension_version:123,dd_extension_version:123,env:integration-tests-env,env:integration-tests-env,env:integration-tests-env,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,memorysize:1024,memorysize:1024,memorysize:1024,region:sa-east-1,region:sa-east-1,region:sa-east-1,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,service:integration-tests-service,service:integration-tests-service,service:integration-tests-service,taga:valuea,taga:valuea,taga:valuea,tagb:valueb,tagb:valueb,tagb:valueb,tagc:valuec,tagc:valuec,tagc:valuec,tagd:valued,tagd:valued,tagd:valued,version:integration-tests-version,version:integration-tests-version,version:integration-tests-version"}
[log] {"message":{"message":"XXX Log 1 XXX\n","lambda":{"arn":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp"}},"status":"info","timestamp":TIMESTAMP,"hostname":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp","service":"integration-tests-service","ddsource":"lambda","ddtags":"account_id:601427279990,account_id:601427279990,account_id:601427279990,architecture:x86_64,architecture:x86_64,architecture:x86_64,aws_account:601427279990,aws_account:601427279990,aws_account:601427279990,dd_extension_version:123,dd_extension_version:123,dd_extension_version:123,env:integration-tests-env,env:integration-tests-env,env:integration-tests-env,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,memorysize:1024,memorysize:1024,memorysize:1024,region:sa-east-1,region:sa-east-1,region:sa-east-1,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,service:integration-tests-service,service:integration-tests-service,service:integration-tests-service,taga:valuea,taga:valuea,taga:valuea,tagb:valueb,tagb:valueb,tagb:valueb,tagc:valuec,tagc:valuec,tagc:valuec,tagd:valued,tagd:valued,tagd:valued,version:integration-tests-version,version:integration-tests-version,version:integration-tests-version"}
[log] {"message":{"message":"XXX Log 2 XXX\n","lambda":{"arn":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp"}},"status":"info","timestamp":TIMESTAMP,"hostname":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp","service":"integration-tests-service","ddsource":"lambda","ddtags":"account_id:601427279990,account_id:601427279990,account_id:601427279990,architecture:x86_64,architecture:x86_64,architecture:x86_64,aws_account:601427279990,aws_account:601427279990,aws_account:601427279990,dd_extension_version:123,dd_extension_version:123,dd_extension_version:123,env:integration-tests-env,env:integration-tests-env,env:integration-tests-env,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,memorysize:1024,memorysize:1024,memorysize:1024,region:sa-east-1,region:sa-east-1,region:sa-east-1,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,service:integration-tests-service,service:integration-tests-service,service:integration-tests-service,taga:valuea,taga:valuea,taga:valuea,tagb:valueb,tagb:valueb,tagb:valueb,tagc:valuec,tagc:valuec,tagc:valuec,tagd:valued,tagd:valued,tagd:valued,version:integration-tests-version,version:integration-tests-version,version:integration-tests-version"}
2 changes: 2 additions & 0 deletions integration_tests/snapshots/metric-csharp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[sketch] {"metric":"aws.lambda.enhanced.runtime_duration","distributions":null,"tags":["account_id:601427279990","architecture:x86_64","aws_account:601427279990","cold_start:true","dd_extension_version:123","env:integration-tests-env","function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-XXXXXX-metric-csharp","functionname:integration-tests-extension-XXXXXX-metric-csharp","memorysize:1024","region:sa-east-1","resource:integration-tests-extension-XXXXXX-metric-csharp","service:integration-tests-service","taga:valuea","tagb:valueb","tagc:valuec","tagd:valued","version:integration-tests-version"],"dogsketches":[{"ts":XXX,"cnt":1,"min":XXX,"max":XXX,"avg":XXX,"sum":XXX,"k":[XXX],"n":[1]}]}
[sketch] {"metric":"aws.lambda.enhanced.runtime_duration","distributions":null,"tags":["account_id:601427279990","architecture:x86_64","aws_account:601427279990","cold_start:true","dd_extension_version:123","env:integration-tests-env","function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-XXXXXX-metric-csharp","functionname:integration-tests-extension-XXXXXX-metric-csharp","memorysize:1024","region:sa-east-1","resource:integration-tests-extension-XXXXXX-metric-csharp","service:integration-tests-service","taga:valuea","tagb:valueb","tagc:valuec","tagd:valued","version:integration-tests-version"],"dogsketches":[{"ts":XXX,"cnt":1,"min":XXX,"max":XXX,"avg":XXX,"sum":XXX,"k":[XXX],"n":[1]}]}
15 changes: 15 additions & 0 deletions integration_tests/src/csharp-tests/csharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>CsharpHandlers</AssemblyName>
<PackageId>aws-csharp</PackageId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.0.1" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions integration_tests/src/csharp-tests/handler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Amazon.Lambda.Core;
using System;

[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace AwsDotnetCsharp

{
public class Handler
{
public Response Hello()
{
return new Response(200, "ok");
}

public Response Logs()
{
Console.WriteLine("XXX Log 0 XXX");
Console.WriteLine("XXX Log 1 XXX");
Console.WriteLine("XXX Log 2 XXX");
return new Response(200, "ok");
}
}
public class Response
{
public int statusCode {get; set;}
public string body {get; set;}

public Response(int code, string message){
statusCode = code;
body = message;
}
}

}

0 comments on commit ed89375

Please sign in to comment.