-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(injector: builtin: net-http-client): treat 4XX as errors, not 5XXs (
#426) Signed-off-by: Eliott Bouhana <[email protected]> Co-authored-by: Romain Marcadier <[email protected]>
- Loading branch information
1 parent
f0c5d95
commit 64b5659
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2023-present Datadog, Inc. | ||
|
||
package nethttp | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"datadoghq.dev/orchestrion/_integration-tests/utils" | ||
"datadoghq.dev/orchestrion/_integration-tests/validator/trace" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestCaseClientError checks of the net/http client instrumentation handles creates error if the returned status code is 4xx. | ||
type TestCaseClientError struct { | ||
srv *http.Server | ||
handler http.Handler | ||
} | ||
|
||
func (b *TestCaseClientError) Setup(t *testing.T) { | ||
b.srv = &http.Server{ | ||
Addr: "127.0.0.1:" + utils.GetFreePort(t), | ||
ReadTimeout: 5 * time.Second, | ||
WriteTimeout: 10 * time.Second, | ||
} | ||
b.srv.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
w.WriteHeader(http.StatusTeapot) | ||
}) | ||
|
||
go func() { assert.ErrorIs(t, b.srv.ListenAndServe(), http.ErrServerClosed) }() | ||
t.Cleanup(func() { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
assert.NoError(t, b.srv.Shutdown(ctx)) | ||
}) | ||
} | ||
|
||
func (b *TestCaseClientError) Run(t *testing.T) { | ||
resp, err := http.Get(fmt.Sprintf("http://%s/", b.srv.Addr)) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusTeapot, resp.StatusCode) | ||
} | ||
|
||
func (*TestCaseClientError) ExpectedTraces() trace.Traces { | ||
return trace.Traces{ | ||
{ | ||
Tags: map[string]any{ | ||
"name": "http.request", | ||
"resource": "GET /", | ||
"type": "http", | ||
}, | ||
Meta: map[string]string{ | ||
"component": "net/http", | ||
"span.kind": "client", | ||
"http.errors": "418 I'm a teapot", | ||
"http.status_code": "418", | ||
}, | ||
}, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters