Skip to content
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

[service] Remove getBallastSize from service #10696

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/service-remove-ballast-deps-2.yaml
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: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: processor/memorylimiter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The memory limiter processor will no longer account for ballast size.

# One or more tracking issues or pull requests related to the change
issues: [10696]

# (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: If you are already using GOMEMLIMIT instead of the ballast extension this does not affect you.

# 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: []
25 changes: 25 additions & 0 deletions .chloggen/service-remove-ballast-deps-3.yaml
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: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: extension/memorylimiter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The memory limiter extension will no longer account for ballast size.

# One or more tracking issues or pull requests related to the change
issues: [10696]

# (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: If you are already using GOMEMLIMIT instead of the ballast extension this does not affect you.

# 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: []
25 changes: 25 additions & 0 deletions .chloggen/service-remove-ballast-deps.yaml
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: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The service will no longer be able to get a ballast size from the deprecated ballast extension.

# One or more tracking issues or pull requests related to the change
issues: [10696]

# (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: If you are already using GOMEMLIMIT instead of the ballast extension this does not affect you.

# 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: []
23 changes: 2 additions & 21 deletions internal/memorylimiter/memorylimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
usageChecker memUsageChecker

memCheckWait time.Duration
ballastSize uint64

// mustRefuse is used to indicate when data should be refused.
mustRefuse *atomic.Bool
Expand All @@ -58,8 +57,7 @@
readMemStatsFn func(m *runtime.MemStats)

// Fields used for logging.
logger *zap.Logger
configMismatchedLogged bool
logger *zap.Logger

refCounterLock sync.Mutex
refCounter int
Expand Down Expand Up @@ -114,14 +112,7 @@
}
}

func (ml *MemoryLimiter) Start(_ context.Context, host component.Host) error {
extensions := host.GetExtensions()
for _, extension := range extensions {
if ext, ok := extension.(interface{ GetBallastSize() uint64 }); ok {
ml.ballastSize = ext.GetBallastSize()
break
}
}
func (ml *MemoryLimiter) Start(_ context.Context, _ component.Host) error {

Check warning on line 115 in internal/memorylimiter/memorylimiter.go

View check run for this annotation

Codecov / codecov/patch

internal/memorylimiter/memorylimiter.go#L115

Added line #L115 was not covered by tests
ml.startMonitoring()
return nil
}
Expand Down Expand Up @@ -168,16 +159,6 @@
func (ml *MemoryLimiter) readMemStats() *runtime.MemStats {
ms := &runtime.MemStats{}
ml.readMemStatsFn(ms)
// If proper configured ms.Alloc should be at least ml.ballastSize but since
// a misconfiguration is possible check for that here.
if ms.Alloc >= ml.ballastSize {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a separate changelog entry for this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added one for each memory limiter

ms.Alloc -= ml.ballastSize
} else if !ml.configMismatchedLogged {
// This indicates misconfiguration. Log it once.
ml.configMismatchedLogged = true
ml.logger.Warn(`"size_mib" in ballast extension is likely incorrectly configured.`)
}

return ms
}

Expand Down
54 changes: 0 additions & 54 deletions internal/memorylimiter/memorylimiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
package memorylimiter

import (
"context"
"runtime"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/internal/iruntime"
)

Expand Down Expand Up @@ -43,22 +40,6 @@ func TestMemoryPressureResponse(t *testing.T) {
ml.CheckMemLimits()
assert.True(t, ml.MustRefuse())

// Check ballast effect
ml.ballastSize = 1000

// Below memAllocLimit accounting for ballast.
currentMemAlloc = 800 + ml.ballastSize
ml.CheckMemLimits()
assert.False(t, ml.MustRefuse())

// Above memAllocLimit even accounting for ballast.
currentMemAlloc = 1800 + ml.ballastSize
ml.CheckMemLimits()
assert.True(t, ml.MustRefuse())

// Restore ballast to default.
ml.ballastSize = 0

// Check spike limit
ml.usageChecker.memSpikeLimit = 512

Expand Down Expand Up @@ -151,38 +132,3 @@ func TestRefuseDecision(t *testing.T) {
})
}
}

func TestBallastSize(t *testing.T) {
cfg := &Config{
CheckInterval: 10 * time.Second,
MemoryLimitMiB: 1024,
}
got, err := NewMemoryLimiter(cfg, zap.NewNop())
require.NoError(t, err)

got.startMonitoring()
require.NoError(t, got.Start(context.Background(), &host{ballastSize: 113}))
assert.Equal(t, uint64(113), got.ballastSize)
require.NoError(t, got.Shutdown(context.Background()))
}

type host struct {
ballastSize uint64
component.Host
}

func (h *host) GetExtensions() map[component.ID]component.Component {
ret := make(map[component.ID]component.Component)
ret[component.MustNewID("ballast")] = &ballastExtension{ballastSize: h.ballastSize}
return ret
}

type ballastExtension struct {
ballastSize uint64
component.StartFunc
component.ShutdownFunc
}

func (be *ballastExtension) GetBallastSize() uint64 {
return be.ballastSize
}
Loading
Loading