Skip to content

Commit

Permalink
Local testing with Go (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio-Guerra authored Nov 9, 2022
1 parent c9fb363 commit 5e06603
Show file tree
Hide file tree
Showing 5 changed files with 368 additions and 18 deletions.
33 changes: 33 additions & 0 deletions local_tests/Dockerfile.Go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM golang AS builder
WORKDIR /app
COPY golang .
RUN go build -v -o app .

FROM public.ecr.aws/lambda/go:1

# Add Datadog library
COPY --from=builder /app/app ${LAMBDA_TASK_ROOT}

# Copy both the datadog extension and the recorder one
RUN mkdir -p /opt/extensions
COPY recorder-extension /opt/extensions/
COPY datadog-agent /opt/extensions/

# Make sure that the extension will send the payload to the man in the middle
# (recorder extension is listenning on 3333)
ENV DD_API_KEY=NO_NEED_TO_BE_VALID
ENV DD_APM_DD_URL=http://127.0.0.1:3333
ENV DD_DD_URL=http://127.0.0.1:3333
ENV DD_LAMBDA_HANDLER=func.hello
ENV DD_LOGS_CONFIG_LOGS_DD_URL=127.0.0.1:3333
ENV DD_LOGS_CONFIG_LOGS_NO_SSL=true
ENV DD_LOGS_ENABLED=false
ENV DD_LOG_LEVEL=DEBUG
ENV DD_MERGE_XRAY_TRACES=false
ENV DD_SERVERLESS_LOGS_ENABLED=false
ENV DD_SERVICE=integration-test-service
ENV DD_TRACE_ENABLED=true
ENV DD_LOCAL_TEST=1
ENV DD_UNIVERSAL_INSTRUMENTATION=true

CMD [ "app" ]
47 changes: 29 additions & 18 deletions local_tests/build-docker-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@ if [ -z $RUNTIME ]; then
fi

# Determine architecture, M1 requires arm64 while Intel chip requires amd64
if [ `uname -m` == "arm64" ]; then
ARCHITECTURE=arm64
else
ARCHITECTURE=amd64
if [ -z "$ARCHITECTURE" ]; then
if [ `uname -m` == "arm64" ]; then
ARCHITECTURE=arm64
else
ARCHITECTURE=amd64
fi
fi

if [ "$RUNTIME" == "python" ]; then
if [ "$ARCHITECTURE" == "amd64" ]; then
LAYER_NAME=Datadog-Python39-ARM
else
LAYER_NAME=Datadog-Python39
fi
DOCKERFILE=Dockerfile.Python
else
LAYER_NAME=Datadog-Node16-x
DOCKERFILE=Dockerfile.Node
fi
case "$RUNTIME" in
python)
if [ "$ARCHITECTURE" == "amd64" ]; then
LAYER_NAME=Datadog-Python39-ARM
else
LAYER_NAME=Datadog-Python39
fi
DOCKERFILE=Dockerfile.Python
;;

go)
DOCKERFILE=Dockerfile.Go
;;

node)
LAYER_NAME=Datadog-Node16-x
DOCKERFILE=Dockerfile.Node
;;
esac

# Save the current path
CURRENT_PATH=$(pwd)
Expand All @@ -42,7 +52,7 @@ cp ../.layers/datadog_extension-$ARCHITECTURE/extensions/datadog-agent .
cd ../../datadog-agent/test/integration/serverless/recorder-extension
GOOS=linux GOARCH=$ARCHITECTURE go build -o "$CURRENT_PATH/local_tests/recorder-extension" main.go
cd "$CURRENT_PATH/local_tests"
if [ -z "$LAYER_PATH" ]; then
if [ -z "$LAYER_PATH" ] && [ -n "$LAYER_NAME" ]; then
# Get the latest available version
LATEST_AVAILABLE_VERSION=$(aws-vault exec sandbox-account-admin \
-- aws lambda list-layer-versions --layer-name $LAYER_NAME --region sa-east-1 --max-items 1 \
Expand All @@ -63,13 +73,14 @@ if [ -z "$LAYER_PATH" ]; then
rm -rf $CURRENT_PATH/local_tests/python
unzip "$LAYER"
fi
else
elif [ -n "$LAYER_PATH" ]; then
echo "Using $LAYER_PATH instead of fetching from AWS"
if test -d "$CURRENT_PATH/local_tests/$RUNTIME"; then
echo "Removing and rebuilding from local path"
rm -rf $CURRENT_PATH/local_tests/$RUNTIME
fi
unzip $LAYER_PATH -d $CURRENT_PATH/local_tests/
fi

# Build the image
docker build -t datadog/extension-local-tests --no-cache -f $DOCKERFILE .
docker build --platform=linux/$ARCHITECTURE -t datadog/extension-local-tests --no-cache -f $DOCKERFILE .
62 changes: 62 additions & 0 deletions local_tests/golang/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module app

go 1.18

require (
github.com/DataDog/datadog-lambda-go v1.8.0
github.com/aws/aws-lambda-go v1.34.1
gopkg.in/DataDog/dd-trace-go.v1 v1.43.1
)

require (
github.com/DataDog/datadog-agent/pkg/obfuscate v0.40.0 // indirect
github.com/DataDog/datadog-go v4.8.3+incompatible // indirect
github.com/DataDog/datadog-go/v5 v5.1.1 // indirect
github.com/DataDog/sketches-go v1.4.1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/aws/aws-sdk-go v1.44.133 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.17.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.23 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.26 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.19 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.18.15 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.25 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.17.1 // indirect
github.com/aws/aws-xray-sdk-go v1.7.1 // indirect
github.com/aws/smithy-go v1.13.4 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sony/gobreaker v0.5.0 // indirect
github.com/tinylib/msgp v1.1.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.41.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go4.org/intern v0.0.0-20220617035311-6925f38cc365 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.2.0 // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20221107162902-2d387536bcdd // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 // indirect
)
Loading

0 comments on commit 5e06603

Please sign in to comment.