Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/hashicorp/g…
Browse files Browse the repository at this point in the history
…o-retryablehttp-0.7.7
  • Loading branch information
nsrip-dd authored Jun 28, 2024
2 parents 14ae408 + bdc072c commit 82a7f43
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
matrix:
# TODO: cross-compilation from/to different hardware architectures once
# github provides native ARM runners.
go: [ "1.21", "1.22" ]
go: [ "1.21", "1.22", "1.23-rc" ]
build-env: [ alpine, bookworm, bullseye ]
build-with-cgo: [ 0, 1 ]
deployment-env: [ alpine, debian11, debian12, al2, al2023, busybox, scratch ]
Expand Down
38 changes: 14 additions & 24 deletions .gitlab/macrobenchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ variables:
GO_PROF_APP_BUILD_VARIANT: "candidate"
DD_TRACE_GO_VERSION: "latest"

LOAD_TESTS: io-bound,cpu-bound,cgo-cpu-bound,cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

# Workaround: Currently we're not running the benchmarks on every PR, but GitHub still shows them as pending.
# By marking the benchmarks as allow_failure, this should go away. (This workaround should be removed once the
# benchmarks get changed to run on every PR)
allow_failure: true

go122-baseline:
extends: .benchmarks
variables:
Expand All @@ -44,8 +47,7 @@ go122-baseline:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-only-trace:
extends: .benchmarks
variables:
Expand All @@ -55,8 +57,7 @@ go122-only-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-only-profile:
extends: .benchmarks
variables:
Expand All @@ -66,8 +67,7 @@ go122-only-profile:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-profile-trace:
extends: .benchmarks
variables:
Expand All @@ -77,8 +77,7 @@ go122-profile-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -88,8 +87,7 @@ go122-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-profile-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -99,8 +97,7 @@ go122-profile-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-baseline:
extends: .benchmarks
variables:
Expand All @@ -110,8 +107,7 @@ go120-baseline:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-only-trace:
extends: .benchmarks
variables:
Expand All @@ -121,8 +117,7 @@ go120-only-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-only-profile:
extends: .benchmarks
variables:
Expand All @@ -132,8 +127,7 @@ go120-only-profile:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-profile-trace:
extends: .benchmarks
variables:
Expand All @@ -143,8 +137,7 @@ go120-profile-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -154,8 +147,7 @@ go120-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-profile-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -165,5 +157,3 @@ go120-profile-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"
23 changes: 20 additions & 3 deletions contrib/99designs/gqlgen/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
const defaultServiceName = "graphql"

type config struct {
serviceName string
analyticsRate float64
tags map[string]interface{}
serviceName string
analyticsRate float64
withoutTraceIntrospectionQuery bool
withoutTraceTrivialResolvedFields bool
tags map[string]interface{}
}

// An Option configures the gqlgen integration.
Expand Down Expand Up @@ -51,6 +53,21 @@ func WithServiceName(name string) Option {
}
}

// WithoutTraceIntrospectionQuery skips creating spans for fields when the operation name is IntrospectionQuery.
func WithoutTraceIntrospectionQuery() Option {
return func(cfg *config) {
cfg.withoutTraceIntrospectionQuery = true
}
}

// WithoutTraceTrivialResolvedFields skips creating spans for fields that have a trivial resolver.
// For example, a field resolved from an object w/o requiring a custom method is considered trivial.
func WithoutTraceTrivialResolvedFields() Option {
return func(cfg *config) {
cfg.withoutTraceTrivialResolvedFields = true
}
}

// WithCustomTag will attach the value to the span tagged by the key.
func WithCustomTag(key string, value interface{}) Option {
return func(cfg *config) {
Expand Down
16 changes: 15 additions & 1 deletion contrib/99designs/gqlgen/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ func (t *gqlTracer) InterceptOperation(ctx context.Context, next graphql.Operati

func (t *gqlTracer) InterceptField(ctx context.Context, next graphql.Resolver) (res any, err error) {
opCtx := graphql.GetOperationContext(ctx)
if t.cfg.withoutTraceIntrospectionQuery && opCtx.OperationName == "IntrospectionQuery" {
res, err = next(ctx)
return
}

fieldCtx := graphql.GetFieldContext(ctx)
isTrivial := !(fieldCtx.IsMethod || fieldCtx.IsResolver)
if t.cfg.withoutTraceTrivialResolvedFields && isTrivial {
res, err = next(ctx)
return
}

opts := make([]tracer.StartSpanOption, 0, 6+len(t.cfg.tags))
for k, v := range t.cfg.tags {
opts = append(opts, tracer.Tag(k, v))
Expand All @@ -153,15 +164,18 @@ func (t *gqlTracer) InterceptField(ctx context.Context, next graphql.Resolver) (
if !math.IsNaN(t.cfg.analyticsRate) {
opts = append(opts, tracer.Tag(ext.EventSampleRate, t.cfg.analyticsRate))
}

span, ctx := tracer.StartSpanFromContext(ctx, fieldOp, opts...)
defer func() { span.Finish(tracer.WithError(err)) }()

ctx, op := graphqlsec.StartResolveOperation(ctx, graphqlsec.FromContext[*types.ExecutionOperation](ctx), span, types.ResolveOperationArgs{
Arguments: fieldCtx.Args,
TypeName: fieldCtx.Object,
FieldName: fieldCtx.Field.Name,
Trivial: !(fieldCtx.IsMethod || fieldCtx.IsResolver), // TODO: Is this accurate?
Trivial: isTrivial,
})
defer func() { op.Finish(types.ResolveOperationRes{Data: res, Error: err}) }()

res, err = next(ctx)
return
}
Expand Down
62 changes: 53 additions & 9 deletions contrib/99designs/gqlgen/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func TestOptions(t *testing.T) {
query := `{ name }`
for name, tt := range map[string]struct {
tracerOpts []Option
test func(assert *assert.Assertions, root mocktracer.Span)
test func(assert *assert.Assertions, root mocktracer.Span, spans []mocktracer.Span)
}{
"default": {
test: func(assert *assert.Assertions, root mocktracer.Span) {
test: func(assert *assert.Assertions, root mocktracer.Span, _ []mocktracer.Span) {
assert.Equal("graphql.query", root.OperationName())
assert.Equal(query, root.Tag(ext.ResourceName))
assert.Equal(defaultServiceName, root.Tag(ext.ServiceName))
Expand All @@ -43,34 +43,47 @@ func TestOptions(t *testing.T) {
},
"WithServiceName": {
tracerOpts: []Option{WithServiceName("TestServer")},
test: func(assert *assert.Assertions, root mocktracer.Span) {
test: func(assert *assert.Assertions, root mocktracer.Span, _ []mocktracer.Span) {
assert.Equal("TestServer", root.Tag(ext.ServiceName))
},
},
"WithAnalytics/true": {
tracerOpts: []Option{WithAnalytics(true)},
test: func(assert *assert.Assertions, root mocktracer.Span) {
test: func(assert *assert.Assertions, root mocktracer.Span, _ []mocktracer.Span) {
assert.Equal(1.0, root.Tag(ext.EventSampleRate))
},
},
"WithAnalytics/false": {
tracerOpts: []Option{WithAnalytics(false)},
test: func(assert *assert.Assertions, root mocktracer.Span) {
test: func(assert *assert.Assertions, root mocktracer.Span, _ []mocktracer.Span) {
assert.Nil(root.Tag(ext.EventSampleRate))
},
},
"WithAnalyticsRate": {
tracerOpts: []Option{WithAnalyticsRate(0.5)},
test: func(assert *assert.Assertions, root mocktracer.Span) {
test: func(assert *assert.Assertions, root mocktracer.Span, _ []mocktracer.Span) {
assert.Equal(0.5, root.Tag(ext.EventSampleRate))
},
},
"WithoutTraceTrivialResolvedFields": {
tracerOpts: []Option{WithoutTraceTrivialResolvedFields()},
test: func(assert *assert.Assertions, _ mocktracer.Span, spans []mocktracer.Span) {
var hasFieldOperation bool
for _, span := range spans {
if span.OperationName() == fieldOp {
hasFieldOperation = true
break
}
}
assert.Equal(false, hasFieldOperation)
},
},
"WithCustomTag": {
tracerOpts: []Option{
WithCustomTag("customTag1", "customValue1"),
WithCustomTag("customTag2", "customValue2"),
},
test: func(assert *assert.Assertions, root mocktracer.Span) {
test: func(assert *assert.Assertions, root mocktracer.Span, _ []mocktracer.Span) {
assert.Equal("customValue1", root.Tag("customTag1"))
assert.Equal("customValue2", root.Tag("customTag2"))
},
Expand All @@ -82,17 +95,48 @@ func TestOptions(t *testing.T) {
defer mt.Stop()
c := newTestClient(t, testserver.New(), NewTracer(tt.tracerOpts...))
c.MustPost(query, &testServerResponse{})
spans := mt.FinishedSpans()
var root mocktracer.Span
for _, span := range mt.FinishedSpans() {
for _, span := range spans {
if span.ParentID() == 0 {
root = span
}
}
assert.NotNil(root)
tt.test(assert, root)
tt.test(assert, root, spans)
assert.Nil(root.Tag(ext.Error))
})
}

// WithoutTraceIntrospectionQuery tested here since we are specifically checking against an IntrosepctionQuery operation.
query = `query IntrospectionQuery { __schema { queryType { name } } }`
for name, tt := range map[string]struct {
tracerOpts []Option
test func(assert *assert.Assertions, spans []mocktracer.Span)
}{
"WithoutTraceIntrospectionQuery": {
tracerOpts: []Option{WithoutTraceIntrospectionQuery()},
test: func(assert *assert.Assertions, spans []mocktracer.Span) {
var hasFieldSpan bool
for _, span := range spans {
if span.OperationName() == fieldOp {
hasFieldSpan = true
break
}
}
assert.Equal(false, hasFieldSpan)
},
},
} {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
mt := mocktracer.Start()
defer mt.Stop()
c := newTestClient(t, testserver.New(), NewTracer(tt.tracerOpts...))
c.MustPost(query, &testServerResponse{}, client.Operation("IntrospectionQuery"))
tt.test(assert, mt.FinishedSpans())
})
}
}

func TestError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/mocktracer/mocktracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newMockTracer() *mocktracer {
client := &http.Client{
Transport: t.dsmTransport,
}
t.dsmProcessor = datastreams.NewProcessor(&statsd.NoOpClient{}, "env", "service", "v1", &url.URL{Scheme: "http", Host: "agent-address"}, client, func() bool { return true })
t.dsmProcessor = datastreams.NewProcessor(&statsd.NoOpClient{}, "env", "service", "v1", &url.URL{Scheme: "http", Host: "agent-address"}, client)
t.dsmProcessor.Start()
t.dsmProcessor.Flush()
return &t
Expand Down
Loading

0 comments on commit 82a7f43

Please sign in to comment.