Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
timannguyen committed Mar 5, 2024
1 parent 4fbc7a5 commit 960c5a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions config/confighttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ will not be enabled.
- `max_request_body_size`: configures the maximum allowed body size in bytes for a single request. Default: `0` (no restriction)
- [`tls`](../configtls/README.md)
- [`auth`](../configauth/README.md)

`memory_limiter`: [Memory limiter extension](../../extension/memorylimiterextension/README.md) that will reject incoming requests once the memory utilization grows above configured limits.
- [`memory_limiter`](../../extension/memorylimiterextension/README.md) that will reject incoming requests once the memory utilization grows above configured limits.

You can enable [`attribute processor`][attribute-processor] to append any http header to span's attribute using custom key. You also need to enable the "include_metadata"

Expand Down
17 changes: 15 additions & 2 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,13 +1341,19 @@ func TestMemoryLimiterInterceptor(t *testing.T) {
}

func TestGetMemoryLimiterExtension(t *testing.T) {
fakeID := component.NewID("memoryLimiterFake")
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,
component.NewID("memoryLimiter"): mle,
fakeID: nopExt,
}

hss := ServerConfig{
Endpoint: "localhost:0",
MemoryLimiter: &fakeID,
}

// valid extension
Expand All @@ -1360,10 +1366,17 @@ func TestGetMemoryLimiterExtension(t *testing.T) {
_, err = getMemoryLimiterExtension(&comID, extList)
assert.EqualError(t, err, "requested MemoryLimiter, memoryLimiterFake, is not a memoryLimiterExtension")

// invalid through toServer
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
host := &mockHost{ext: extList}
_, err = hss.ToServer(host, componenttest.NewNopTelemetrySettings(), handler)
require.Error(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 {
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
go.opentelemetry.io/collector/config/configtelemetry v0.96.0
go.opentelemetry.io/collector/config/configtls v0.96.0
go.opentelemetry.io/collector/config/internal v0.96.0
go.opentelemetry.io/collector/extension v0.96.0
go.opentelemetry.io/collector/extension/auth v0.96.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
go.opentelemetry.io/otel v1.24.0
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector/confmap v0.96.0 // indirect
go.opentelemetry.io/collector/extension v0.96.0 // indirect
go.opentelemetry.io/collector/featuregate v1.3.0 // indirect
go.opentelemetry.io/collector/pdata v1.3.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.46.0 // indirect
Expand Down

0 comments on commit 960c5a2

Please sign in to comment.