Skip to content

Commit

Permalink
[service] Remove getBallastSize from service (#10696)
Browse files Browse the repository at this point in the history
#### Description

This PR removes all ballast logic from service. This effectively
deprecates the ballastextension as including the extension with this
service would do nothing.

Related to
#10671

#### Link to tracking issue
Closes
#8342

#### Testing
Unit tests.
  • Loading branch information
TylerHelmuth committed Jul 23, 2024
1 parent c239e73 commit 4e44e32
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 195 deletions.
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 @@ type MemoryLimiter struct {
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 @@ type MemoryLimiter struct {
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) startMonitoring() {
}
}

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 {
ml.startMonitoring()
return nil
}
Expand Down Expand Up @@ -168,16 +159,6 @@ func getMemUsageChecker(cfg *Config, logger *zap.Logger) (*memUsageChecker, erro
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 {
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

0 comments on commit 4e44e32

Please sign in to comment.