Skip to content

Commit

Permalink
[chore] Remove use of confighttp.ClientConfig.RoundTripper (#33371)
Browse files Browse the repository at this point in the history
**Description:**

* lokiexporter and sumologicexporter: Neither need to use this field for
their tests, it can be replaced without loss of functionality with
another config field.
* oauth2clientextension: This should directly rely on the `http.Client`
interface.
* ecstaskobserver docs: I don't think there was ever a way to unmarshal
this field, so there shouldn't be a doc for how to configure it.

**Link to tracking Issue:**

Soft required for
open-telemetry/opentelemetry-collector#10310 so
we don't use deprecated APIs.
  • Loading branch information
evan-bradley authored Jun 5, 2024
1 parent d5ca873 commit 17f57e4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 67 deletions.
9 changes: 5 additions & 4 deletions exporter/lokiexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ package lokiexporter

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

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtls"
)

const (
Expand Down Expand Up @@ -47,8 +46,10 @@ func TestExporter_startReturnsErrorWhenInvalidHttpClientSettings(t *testing.T) {
config := &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "",
CustomRoundTripper: func(_ http.RoundTripper) (http.RoundTripper, error) {
return nil, fmt.Errorf("this causes ClientConfig.ToClient() to error")
TLSSetting: configtls.ClientConfig{
Config: configtls.Config{
MinVersion: "invalid",
},
},
},
}
Expand Down
9 changes: 6 additions & 3 deletions exporter/sumologicexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -246,15 +247,17 @@ func TestInvalidHTTPCLient(t *testing.T) {
exp := initExporter(&Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "test_endpoint",
CustomRoundTripper: func(_ http.RoundTripper) (http.RoundTripper, error) {
return nil, errors.New("roundTripperException")
TLSSetting: configtls.ClientConfig{
Config: configtls.Config{
MinVersion: "invalid",
},
},
},
}, createExporterCreateSettings())

assert.EqualError(t,
exp.start(context.Background(), componenttest.NewNopHost()),
"failed to create HTTP Client: roundTripperException",
"failed to create HTTP Client: failed to load TLS config: invalid TLS min_version: unsupported TLS version: \"invalid\"",
)
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/sumologicexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
go.opentelemetry.io/collector/config/configcompression v1.9.0
go.opentelemetry.io/collector/config/confighttp v0.102.0
go.opentelemetry.io/collector/config/configretry v0.102.0
go.opentelemetry.io/collector/config/configtls v0.102.0
go.opentelemetry.io/collector/confmap v0.102.0
go.opentelemetry.io/collector/consumer v0.102.0
go.opentelemetry.io/collector/exporter v0.102.0
Expand Down Expand Up @@ -65,7 +66,6 @@ require (
go.opentelemetry.io/collector v0.102.0 // indirect
go.opentelemetry.io/collector/config/configopaque v1.9.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.102.0 // indirect
go.opentelemetry.io/collector/config/configtls v0.102.0 // indirect
go.opentelemetry.io/collector/config/internal v0.102.0 // indirect
go.opentelemetry.io/collector/extension v0.102.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.102.0 // indirect
Expand Down
27 changes: 13 additions & 14 deletions extension/oauth2clientauthextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confighttp"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -282,34 +281,34 @@ func TestFailContactingOAuth(t *testing.T) {
defer server.Close()

serverURL, err := url.Parse(server.URL)
assert.NoError(t, err)
require.NoError(t, err)

oauth2Authenticator, err := newClientAuthenticator(&Config{
ClientID: "dummy",
ClientSecret: "ABC",
TokenURL: serverURL.String(),
}, zap.NewNop())
assert.NoError(t, err)
require.NoError(t, err)

// Test for gRPC connections
credential, err := oauth2Authenticator.perRPCCredentials()
assert.NoError(t, err)
require.NoError(t, err)

_, err = credential.GetRequestMetadata(context.Background())
assert.ErrorIs(t, err, errFailedToGetSecurityToken)
assert.Contains(t, err.Error(), serverURL.String())

// Test for HTTP connections
setting := confighttp.ClientConfig{
Endpoint: "http://example.com/",
CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) {
return oauth2Authenticator.roundTripper(next)
},
transport := http.DefaultTransport.(*http.Transport).Clone()
baseRoundTripper := (http.RoundTripper)(transport)
roundTripper, err := oauth2Authenticator.roundTripper(baseRoundTripper)
require.NoError(t, err)

client := &http.Client{
Transport: roundTripper,
}

client, _ := setting.ToClient(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
req, err := http.NewRequest("POST", setting.Endpoint, nil)
assert.NoError(t, err)
req, err := http.NewRequest("POST", "http://example.com/", nil)
require.NoError(t, err)
_, err = client.Do(req)
assert.ErrorIs(t, err, errFailedToGetSecurityToken)
assert.Contains(t, err.Error(), serverURL.String())
Expand Down
12 changes: 0 additions & 12 deletions extension/oauth2clientauthextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21.0
require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.102.0
go.opentelemetry.io/collector/config/confighttp v0.102.0
go.opentelemetry.io/collector/config/configopaque v1.9.0
go.opentelemetry.io/collector/config/configtls v0.102.0
go.opentelemetry.io/collector/confmap v0.102.0
Expand All @@ -25,16 +24,12 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
Expand All @@ -45,15 +40,8 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
github.com/rs/cors v1.10.1 // indirect
go.opentelemetry.io/collector v0.102.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.102.0 // indirect
go.opentelemetry.io/collector/config/configcompression v1.9.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.102.0 // indirect
go.opentelemetry.io/collector/config/internal v0.102.0 // indirect
go.opentelemetry.io/collector/featuregate v1.9.0 // indirect
go.opentelemetry.io/collector/pdata v1.9.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
Expand Down
32 changes: 0 additions & 32 deletions extension/oauth2clientauthextension/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion extension/observer/ecstaskobserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ All fields are optional.
| write_buffer_size |int| <no value> | WriteBufferSize for HTTP client. See http.Transport.WriteBufferSize. |
| timeout |[time-Duration](#time-duration)| <no value> | Timeout parameter configures `http.Client.Timeout`. |
| headers |map[string]string| <no value> | Additional headers attached to each HTTP request sent by the client. Existing header values are overwritten if collision happens. |
| customroundtripper |func(http.RoundTripper) (http.RoundTripper, error)| <no value> | Custom Round Tripper to allow for individual components to intercept HTTP requests |
| auth |[Authentication]| <no value> | Auth configuration for outgoing HTTP calls. |
| refresh_interval |[time-Duration](#time-duration)| 30s | RefreshInterval determines the frequency at which the observer needs to poll for collecting new information about task containers. |
| port_labels |[]string| `[ECS_TASK_OBSERVER_PORT]` | PortLabels is a list of container Docker labels from which to obtain the observed Endpoint port. The first label with valid port found will be used. If no PortLabels provided, default of ECS_TASK_OBSERVER_PORT will be used. |
Expand Down

0 comments on commit 17f57e4

Please sign in to comment.