Skip to content

Commit

Permalink
remove dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
timannguyen committed Feb 5, 2024
1 parent bd99a34 commit 664ddc2
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 219 deletions.
18 changes: 15 additions & 3 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/config/internal"
"go.opentelemetry.io/collector/extension/auth"
"go.opentelemetry.io/collector/extension/memorylimiterextension"
)

const headerContentEncoding = "Content-Encoding"
Expand Down Expand Up @@ -350,7 +349,7 @@ func (hss *ServerConfig) ToServer(host component.Host, settings component.Teleme
}

if hss.MemoryLimiter != nil {
ml, err := memorylimiterextension.GetLimiterExtension(hss.MemoryLimiter, host.GetExtensions())
ml, err := getMemoryLimiterExtension(hss.MemoryLimiter, host.GetExtensions())
if err != nil {
return nil, err
}

Check warning on line 355 in config/confighttp/confighttp.go

View check run for this annotation

Codecov / codecov/patch

config/confighttp/confighttp.go#L354-L355

Added lines #L354 - L355 were not covered by tests
Expand Down Expand Up @@ -472,7 +471,7 @@ func maxRequestBodySizeInterceptor(next http.Handler, maxRecvSize int64) http.Ha
})
}

func memoryLimiterInterceptor(next http.Handler, ml memorylimiterextension.LimiterExtension) http.Handler {
func memoryLimiterInterceptor(next http.Handler, ml memoryLimiterExtension) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if ml.MustRefuse() {
http.Error(w, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
Expand All @@ -481,3 +480,16 @@ func memoryLimiterInterceptor(next http.Handler, ml memorylimiterextension.Limit
next.ServeHTTP(w, r)
})
}

type memoryLimiterExtension = interface{ MustRefuse() bool }

func getMemoryLimiterExtension(extID *component.ID, extensions map[component.ID]component.Component) (memoryLimiterExtension, error) {
if ext, found := extensions[*extID]; found {
if server, ok := ext.(memoryLimiterExtension); ok {
return server, nil
}
return nil, fmt.Errorf("requested MemoryLimiter, %s, is not a memoryLimiterExtension", extID)
}

return nil, fmt.Errorf("failed to resolve memoryLimiterExtension %q: %s", extID, "memory limiter extension not found")
}
29 changes: 28 additions & 1 deletion config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/extension/auth"
"go.opentelemetry.io/collector/extension/auth/authtest"
"go.opentelemetry.io/collector/extension/extensiontest"
)

type customRoundTripper struct {
Expand Down Expand Up @@ -1277,7 +1278,7 @@ func TestMemoryLimiterInterceptor(t *testing.T) {
},
}

hss := HTTPServerConfig{
hss := ServerConfig{
Endpoint: "localhost:0",
MemoryLimiter: &mlID,
}
Expand Down Expand Up @@ -1305,6 +1306,32 @@ func TestMemoryLimiterInterceptor(t *testing.T) {
assert.Equal(t, http.StatusOK, response.Result().StatusCode)
}

func TestGetMemoryLimiterExtension(t *testing.T) {
mle := &mockMemoryLimiterExtension{}
nopExt, err := extensiontest.NewNopFactory().CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), CORSConfig{})
assert.NoError(t, err)

extList := map[component.ID]component.Component{
component.NewID("memoryLimiter"): mle,
component.NewID("memoryLimiterFake"): nopExt,
}

// valid extension
comID := component.NewID("memoryLimiter")
_, err = getMemoryLimiterExtension(&comID, extList)
assert.NoError(t, err)

// invalid extension
comID = component.NewID("memoryLimiterFake")
_, err = getMemoryLimiterExtension(&comID, extList)
assert.EqualError(t, err, "requested MemoryLimiter, memoryLimiterFake, is not a memoryLimiterExtension")

// not found
comID = component.NewID("notfound")
_, err = getMemoryLimiterExtension(&comID, extList)
assert.EqualError(t, err, "failed to resolve memoryLimiterExtension \"notfound\": memory limiter extension not found")
}

type mockHost struct {
component.Host
ext map[component.ID]component.Component
Expand Down
12 changes: 1 addition & 11 deletions config/confighttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ require (
go.opentelemetry.io/collector/config/configtelemetry v0.93.0
go.opentelemetry.io/collector/config/configtls v0.93.0
go.opentelemetry.io/collector/config/internal v0.93.0
go.opentelemetry.io/collector/extension v0.93.0
go.opentelemetry.io/collector/extension/auth v0.93.0
go.opentelemetry.io/collector/extension/memorylimiterextension v0.93.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0
go.opentelemetry.io/otel v1.22.0
go.uber.org/goleak v1.3.0
Expand All @@ -32,29 +32,21 @@ require (
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-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-version v1.6.0 // 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.0.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/collector/confmap v0.93.0 // indirect
go.opentelemetry.io/collector/extension v0.93.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.1 // indirect
go.opentelemetry.io/collector/pdata v1.0.1 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.0 // indirect
Expand Down Expand Up @@ -89,8 +81,6 @@ replace go.opentelemetry.io/collector/extension => ../../extension

replace go.opentelemetry.io/collector/extension/auth => ../../extension/auth

replace go.opentelemetry.io/collector/extension/memorylimiterextension => ../../extension/memorylimiterextension

replace go.opentelemetry.io/collector/confmap => ../../confmap

replace go.opentelemetry.io/collector/featuregate => ../../featuregate
Expand Down
31 changes: 0 additions & 31 deletions config/confighttp/go.sum

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

10 changes: 0 additions & 10 deletions exporter/otlphttpexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
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-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand All @@ -44,29 +43,22 @@ require (
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.0.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/collector/config/configauth v0.93.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.93.0 // indirect
go.opentelemetry.io/collector/config/internal v0.93.0 // indirect
go.opentelemetry.io/collector/extension v0.93.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.93.0 // indirect
go.opentelemetry.io/collector/extension/memorylimiterextension v0.93.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.1 // indirect
go.opentelemetry.io/collector/receiver v0.93.0 // indirect
go.opentelemetry.io/contrib/config v0.2.0 // indirect
Expand Down Expand Up @@ -114,8 +106,6 @@ replace go.opentelemetry.io/collector/extension => ../../extension

replace go.opentelemetry.io/collector/extension/auth => ../../extension/auth

replace go.opentelemetry.io/collector/extension/memorylimiterextension => ../../extension/memorylimiterextension

replace go.opentelemetry.io/collector/featuregate => ../../featuregate

replace go.opentelemetry.io/collector/pdata => ../../pdata
Expand Down
Loading

0 comments on commit 664ddc2

Please sign in to comment.