Skip to content

Commit

Permalink
Upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tianchu authored and peterdeme committed Jul 10, 2024
1 parent 52bd050 commit 0a4e875
Show file tree
Hide file tree
Showing 20 changed files with 940 additions and 945 deletions.
93 changes: 48 additions & 45 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v3
with:
go-version: '1.21'

- name: golangci-lint
uses: golangci/golangci-lint-action@v3

Expand All @@ -23,53 +23,56 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v3
with:
go-version: '1.21'

- name: Run tests
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...

# integration-test:
# runs-on: ubuntu-latest

# steps:
# - name: Checkout
# uses: actions/checkout@v4

# - name: Set up Node 14
# uses: actions/setup-node@v3
# with:
# node-version: 14

# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: '1.21'

# - name: Cache Node modules
# id: cache-node-modules
# uses: actions/cache@v3
# with:
# path: "**/node_modules"
# key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

# - name: Install Serverless Framework
# run: sudo yarn global add serverless --prefix /usr/local

# - name: Install dependencies
# if: steps.cache-node-modules.outputs.cache-hit != 'true'
# working-directory: tests/integration_tests/
# run: yarn install

# - name: Run tests
# env:
# BUILD_LAYERS: true
# DD_API_KEY: ${{ secrets.DD_API_KEY }}
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# working-directory: tests/integration_tests/
# run: ./run_integration_tests.sh
- name: Upload code coverage report
run: bash <(curl -s https://codecov.io/bash)

integration-test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node 14
uses: actions/setup-node@v3
with:
node-version: 14

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'

- name: Cache Node modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Install Serverless Framework
run: sudo yarn global add serverless@^3.38.0 --prefix /usr/local

- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: tests/integration_tests/
run: yarn install

- name: Run tests
env:
BUILD_LAYERS: true
DD_API_KEY: ${{ secrets.DD_API_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
working-directory: tests/integration_tests/
run: ./run_integration_tests.sh
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
25 changes: 19 additions & 6 deletions ddlambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const (
MergeXrayTracesEnvVar = "DD_MERGE_XRAY_TRACES"
// UniversalInstrumentation is the environment variable that enables universal instrumentation with the DD Extension
UniversalInstrumentation = "DD_UNIVERSAL_INSTRUMENTATION"
// Initialize otel tracer provider if enabled
OtelTracerEnabled = "DD_TRACE_OTEL_ENABLED"

// DefaultSite to send API messages to.
DefaultSite = "datadoghq.com"
Expand Down Expand Up @@ -206,9 +208,10 @@ func InvokeDryRun(callback func(ctx context.Context), cfg *Config) (interface{},

func (cfg *Config) toTraceConfig() trace.Config {
traceConfig := trace.Config{
DDTraceEnabled: false,
DDTraceEnabled: true,
MergeXrayTraces: false,
UniversalInstrumentation: false,
UniversalInstrumentation: true,
OtelTracerEnabled: false,
}

if cfg != nil {
Expand All @@ -222,16 +225,22 @@ func (cfg *Config) toTraceConfig() trace.Config {
traceConfig.TraceContextExtractor = trace.DefaultTraceExtractor
}

if !traceConfig.DDTraceEnabled {
traceConfig.DDTraceEnabled, _ = strconv.ParseBool(os.Getenv(DatadogTraceEnabledEnvVar))
if tracingEnabled, err := strconv.ParseBool(os.Getenv(DatadogTraceEnabledEnvVar)); err == nil {
traceConfig.DDTraceEnabled = tracingEnabled
// Only read the OTEL env var if DD tracing is disabled
if tracingEnabled {
if otelTracerEnabled, err := strconv.ParseBool(os.Getenv(OtelTracerEnabled)); err == nil {
traceConfig.OtelTracerEnabled = otelTracerEnabled
}
}
}

if !traceConfig.MergeXrayTraces {
traceConfig.MergeXrayTraces, _ = strconv.ParseBool(os.Getenv(MergeXrayTracesEnvVar))
}

if !traceConfig.UniversalInstrumentation {
traceConfig.UniversalInstrumentation, _ = strconv.ParseBool(os.Getenv(UniversalInstrumentation))
if universalInstrumentation, err := strconv.ParseBool(os.Getenv(UniversalInstrumentation)); err == nil {
traceConfig.UniversalInstrumentation = universalInstrumentation
}

return traceConfig
Expand Down Expand Up @@ -309,6 +318,10 @@ func (cfg *Config) toMetricsConfig(isExtensionRunning bool) metrics.Config {
mc.EnhancedMetrics = strings.EqualFold(enhancedMetrics, "true")
}

if localTest := os.Getenv("DD_LOCAL_TEST"); localTest == "1" || strings.ToLower(localTest) == "true" {
mc.LocalTest = true
}

return mc
}

Expand Down
56 changes: 56 additions & 0 deletions ddlambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ package ddlambda

import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestInvokeDryRun(t *testing.T) {
t.Setenv(UniversalInstrumentation, "false")
t.Setenv(DatadogTraceEnabledEnvVar, "false")

called := false
_, err := InvokeDryRun(func(ctx context.Context) {
called = true
Expand Down Expand Up @@ -48,3 +53,54 @@ func TestMetricsSubmitWithWrapper(t *testing.T) {
assert.NoError(t, err)
assert.True(t, called)
}

func TestToMetricConfigLocalTest(t *testing.T) {
testcases := []struct {
envs map[string]string
cval bool
}{
{
envs: map[string]string{"DD_LOCAL_TEST": "True"},
cval: true,
},
{
envs: map[string]string{"DD_LOCAL_TEST": "true"},
cval: true,
},
{
envs: map[string]string{"DD_LOCAL_TEST": "1"},
cval: true,
},
{
envs: map[string]string{"DD_LOCAL_TEST": "False"},
cval: false,
},
{
envs: map[string]string{"DD_LOCAL_TEST": "false"},
cval: false,
},
{
envs: map[string]string{"DD_LOCAL_TEST": "0"},
cval: false,
},
{
envs: map[string]string{"DD_LOCAL_TEST": ""},
cval: false,
},
{
envs: map[string]string{},
cval: false,
},
}

cfg := Config{}
for _, tc := range testcases {
t.Run(fmt.Sprintf("%#v", tc.envs), func(t *testing.T) {
for k, v := range tc.envs {
os.Setenv(k, v)
}
mc := cfg.toMetricsConfig(true)
assert.Equal(t, tc.cval, mc.LocalTest)
})
}
}
95 changes: 50 additions & 45 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,69 +1,74 @@
module github.com/DataDog/datadog-lambda-go

go 1.20
go 1.21

require (
github.com/DataDog/datadog-go/v5 v5.3.0
github.com/aws/aws-lambda-go v1.41.0
github.com/aws/aws-sdk-go-v2/config v1.23.0
github.com/aws/aws-sdk-go-v2/service/kms v1.26.1
github.com/aws/aws-xray-sdk-go v1.8.2
github.com/DataDog/datadog-go/v5 v5.5.0
github.com/aws/aws-lambda-go v1.46.0
github.com/aws/aws-sdk-go-v2/config v1.26.6
github.com/aws/aws-sdk-go-v2/service/kms v1.27.9
github.com/aws/aws-xray-sdk-go v1.8.3
github.com/cenkalti/backoff/v4 v4.2.1
github.com/sony/gobreaker v0.5.0
github.com/stretchr/testify v1.8.4
gopkg.in/DataDog/dd-trace-go.v1 v1.57.0
go.opentelemetry.io/otel v1.24.0
gopkg.in/DataDog/dd-trace-go.v1 v1.65.1
)

require go.uber.org/atomic v1.11.0 // indirect

require (
github.com/DataDog/appsec-internal-go v1.0.0 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.48.0 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.1 // indirect
github.com/DataDog/go-libddwaf v1.5.0 // indirect
github.com/DataDog/appsec-internal-go v1.6.0 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.50.2 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.50.2 // indirect
github.com/DataDog/go-libddwaf/v3 v3.2.1 // indirect
github.com/DataDog/go-sqllexer v0.0.10 // indirect
github.com/DataDog/go-tuf v1.0.2-0.5.2 // indirect
github.com/DataDog/sketches-go v1.4.2 // indirect
github.com/DataDog/sketches-go v1.4.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/aws/aws-sdk-go v1.44.327 // indirect
github.com/aws/aws-sdk-go-v2 v1.22.2 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.6.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.17.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.25.1 // indirect
github.com/aws/smithy-go v1.16.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.50.9 // indirect
github.com/aws/aws-sdk-go-v2 v1.24.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.16.16 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect
github.com/aws/smithy-go v1.19.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.5.0-alpha.1 // indirect
github.com/ebitengine/purego v0.6.0-alpha.5 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/klauspost/compress v1.17.5 // indirect
github.com/outcaste-io/ristretto v0.2.3 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect
github.com/tinylib/msgp v1.1.9 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.50.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go4.org/intern v0.0.0-20230525184215-6c62f75575cb // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect
)
Loading

0 comments on commit 0a4e875

Please sign in to comment.