-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[extension/memorylimiter] add memory limiter extension, a copy of memorylimiter processor #8964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
212ef66
d77c51e
3d75ecd
c95893a
0150410
f684f11
dc504ec
858c33f
8a7e9b8
8a27c37
e57ba03
3dd4816
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
component: extension/memory_limiter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Introduce a `memory_limiter` extension which receivers can use to reject incoming requests when collector doesn't have enough memory | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [8632] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: The extension has the same configuration interface and behavior as the existing `memory_limiter` processor, which potentially can be deprecated and removed in the future | ||
|
||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Memory Limiter Extension | ||
|
||
> [!WARNING] | ||
> The memory_limiter extension cannot be used if the deprecated memory_ballast extension is enabled. | ||
|
||
<!-- status autogenerated section --> | ||
dmitryax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Status | | | ||
| ------------- |-----------| | ||
| Stability | [development] | | ||
| Distributions | [] | | ||
| Issues | [](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fmemorylimiter) [](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fmemorylimiter) | | ||
|
||
[development]: https://github.com/open-telemetry/opentelemetry-collector#development | ||
<!-- end autogenerated section --> | ||
|
||
The memory limiter extension is used to prevent out of memory situations on | ||
the collector. The extension will potentially replace the Memory Limiter Processor. | ||
It provides better guarantees from running out of memory as it will be used by the | ||
receivers to reject requests before converting them into OTLP. All the configurations | ||
are the same as Memory Limiter Processor. The extension is under development and does nothing. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add what's the strategy for the future? How would this extension interact with the pipeline? Would receivers need to do anything at all to take advantage of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jpkrohling, this is not well-defined yet. I have some ideas. I can put them in a doc or an issue and bring it for discussion. I believe this can be done as a follow-up and we can merge this PR to make it available for playing. The new component is in development stability and is not expected to be used in prod anyway. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the information I'm looking for is already part of the github issue, but I think the design should be clear by looking at the component alone (readme and examples). That said, it's certainly OK to have it done in a follow-up PR. |
||
|
||
see [memorylimiterprocessor](../../processor/memorylimiterprocessor/README.md) for additional details |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package memorylimiterextension // import "go.opentelemetry.io/collector/extension/memorylimiterextension" | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/internal/memorylimiter" | ||
) | ||
|
||
type Config = memorylimiter.Config |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package memorylimiterextension // import "go.opentelemetry.io/collector/extension/memorylimiterextension" | ||
|
||
dmitryax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//go:generate mdatagen metadata.yaml | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/extension" | ||
"go.opentelemetry.io/collector/extension/memorylimiterextension/internal/metadata" | ||
) | ||
|
||
// NewFactory returns a new factory for the Memory Limiter extension. | ||
func NewFactory() extension.Factory { | ||
return extension.NewFactory( | ||
metadata.Type, | ||
createDefaultConfig, | ||
createExtension, | ||
metadata.ExtensionStability) | ||
} | ||
|
||
// CreateDefaultConfig creates the default configuration for extension. Notice | ||
// that the default configuration is expected to fail for this extension. | ||
func createDefaultConfig() component.Config { | ||
return &Config{} | ||
} | ||
|
||
func createExtension(_ context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) { | ||
return newMemoryLimiter(cfg.(*Config), set.TelemetrySettings.Logger) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package memorylimiterextension | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/extension/extensiontest" | ||
"go.opentelemetry.io/collector/internal/memorylimiter" | ||
) | ||
|
||
func TestCreateDefaultConfig(t *testing.T) { | ||
factory := NewFactory() | ||
require.NotNil(t, factory) | ||
|
||
cfg := factory.CreateDefaultConfig() | ||
assert.NotNil(t, cfg, "failed to create default config") | ||
assert.NoError(t, componenttest.CheckConfigStruct(cfg)) | ||
} | ||
|
||
func TestCreateExtension(t *testing.T) { | ||
factory := NewFactory() | ||
require.NotNil(t, factory) | ||
|
||
cfg := factory.CreateDefaultConfig() | ||
|
||
// Create extension with a valid config. | ||
pCfg := cfg.(*Config) | ||
pCfg.MemoryLimitMiB = 5722 | ||
pCfg.MemorySpikeLimitMiB = 1907 | ||
pCfg.CheckInterval = 100 * time.Millisecond | ||
|
||
tp, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, tp) | ||
// test if we can shutdown a monitoring routine that has not started | ||
assert.ErrorIs(t, tp.Shutdown(context.Background()), memorylimiter.ErrShutdownNotStarted) | ||
assert.NoError(t, tp.Start(context.Background(), componenttest.NewNopHost())) | ||
|
||
assert.NoError(t, tp.Shutdown(context.Background())) | ||
// verify that no monitoring routine is running | ||
assert.ErrorIs(t, tp.Shutdown(context.Background()), memorylimiter.ErrShutdownNotStarted) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module go.opentelemetry.io/collector/extension/memorylimiterextension | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/stretchr/testify v1.8.4 | ||
go.opentelemetry.io/collector v0.92.0 | ||
go.opentelemetry.io/collector/component v0.92.0 | ||
go.opentelemetry.io/collector/extension v0.92.0 | ||
go.opentelemetry.io/otel/metric v1.22.0 | ||
go.opentelemetry.io/otel/trace v1.22.0 | ||
go.uber.org/zap v1.26.0 | ||
) | ||
|
||
require ( | ||
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/go-kit/log v0.2.1 // indirect | ||
github.com/go-logfmt/logfmt v0.5.1 // 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/groupcache v0.0.0-20210331224755-41bb18bfe9da // 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/prometheus/statsd_exporter v0.22.7 // 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.opencensus.io v0.24.0 // indirect | ||
go.opentelemetry.io/collector/config/configtelemetry v0.92.0 // indirect | ||
go.opentelemetry.io/collector/confmap v0.92.0 // indirect | ||
go.opentelemetry.io/collector/featuregate v1.0.1 // indirect | ||
go.opentelemetry.io/collector/pdata v1.0.1 // indirect | ||
go.opentelemetry.io/otel v1.22.0 // indirect | ||
go.opentelemetry.io/otel/exporters/prometheus v0.44.1-0.20231201153405-6027c1ae76f2 // indirect | ||
go.opentelemetry.io/otel/sdk v1.22.0 // indirect | ||
go.opentelemetry.io/otel/sdk/metric v1.22.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
golang.org/x/net v0.20.0 // indirect | ||
golang.org/x/sys v0.16.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect | ||
google.golang.org/grpc v1.60.1 // indirect | ||
google.golang.org/protobuf v1.32.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) | ||
|
||
replace go.opentelemetry.io/collector => ../../ | ||
|
||
replace go.opentelemetry.io/collector/component => ../../component | ||
|
||
replace go.opentelemetry.io/collector/confmap => ../../confmap | ||
|
||
replace go.opentelemetry.io/collector/extension => ../../extension | ||
|
||
replace go.opentelemetry.io/collector/featuregate => ../../featuregate | ||
|
||
replace go.opentelemetry.io/collector/pdata => ../../pdata | ||
|
||
replace go.opentelemetry.io/collector/consumer => ../../consumer | ||
|
||
replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry |
Uh oh!
There was an error while loading. Please reload this page.