Skip to content

Commit aaa4b88

Browse files
committed
Disable mem-ballast-size-mib from command line option
1 parent 6cce422 commit aaa4b88

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
## Unreleased
44

55
## 🛑 Breaking changes 🛑
6-
76
- Remove Resize() from pdata slice APIs (#3675)
7+
- Remove `mem-ballast-size-mib` option in command line (#3626)
8+
- Use [`ballast extension`](./extension/ballastextension/README.md) to set memory ballast instead.
89

10+
911
## v0.30.0 Beta
1012

1113
## 🛑 Breaking changes 🛑
@@ -39,7 +41,6 @@
3941

4042
- `scraperhelper`: Include the scraper name in log messages (#3487)
4143
- `scraperhelper`: fix case when returned pdata is empty (#3520)
42-
- `otlpexporter`: Allow endpoint to be configured with a scheme of `http` or `https` (#3575)
4344
- Record the correct number of points not metrics in Kafka receiver (#3553)
4445
- Validate the Prometheus configuration (#3589)
4546

service/collector.go

+26-17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"go.opentelemetry.io/collector/config/configtelemetry"
3636
"go.opentelemetry.io/collector/config/experimental/configsource"
3737
"go.opentelemetry.io/collector/consumer/consumererror"
38+
"go.opentelemetry.io/collector/extension/ballastextension"
3839
"go.opentelemetry.io/collector/internal/collector/telemetry"
3940
"go.opentelemetry.io/collector/service/internal/builder"
4041
"go.opentelemetry.io/collector/service/parserprovider"
@@ -286,30 +287,37 @@ func (col *Collector) execute(ctx context.Context) error {
286287
)
287288
col.stateChannel <- Starting
288289

289-
// Set memory ballast
290-
ballast, ballastSizeBytes := col.createMemoryBallast()
290+
// Add `mem-ballast-size-mib` warning message if it is still enabled
291+
// TODO: will remove all `mem-ballast-size-mib` footprints after some baking time.
292+
if builder.MemBallastSize() > 0 {
293+
col.logger.Warn("`mem-ballast-size-mib` command line option has been deprecated. Please use `ballast extension` instead!")
294+
}
291295

292296
col.asyncErrorChannel = make(chan error)
293297

294-
// Setup everything.
295-
err := col.setupTelemetry(ballastSizeBytes)
298+
err := col.setupConfigurationComponents(ctx)
296299
if err != nil {
297300
return err
298301
}
299302

300-
err = col.setupConfigurationComponents(ctx)
303+
// Get ballastSizeBytes if ballast extension is enabled
304+
ballastSizeBytes := col.getBallastSize()
305+
306+
// Setup Telemetry.
307+
err = col.setupTelemetry(ballastSizeBytes)
301308
if err != nil {
302309
return err
303310
}
304311

312+
col.service.GetExtensions()
313+
305314
// Everything is ready, now run until an event requiring shutdown happens.
306315
col.runAndWaitForShutdownEvent()
307316

308317
// Accumulate errors and proceed with shutting down remaining components.
309318
var errs []error
310319

311320
// Begin shutdown sequence.
312-
runtime.KeepAlive(ballast)
313321
col.logger.Info("Starting shutdown...")
314322

315323
if closable, ok := col.parserProvider.(parserprovider.Closeable); ok {
@@ -335,17 +343,6 @@ func (col *Collector) execute(ctx context.Context) error {
335343
return consumererror.Combine(errs)
336344
}
337345

338-
func (col *Collector) createMemoryBallast() ([]byte, uint64) {
339-
ballastSizeMiB := builder.MemBallastSize()
340-
if ballastSizeMiB > 0 {
341-
ballastSizeBytes := uint64(ballastSizeMiB) * 1024 * 1024
342-
ballast := make([]byte, ballastSizeBytes)
343-
col.logger.Info("Using memory ballast", zap.Int("MiBs", ballastSizeMiB))
344-
return ballast, ballastSizeBytes
345-
}
346-
return nil, 0
347-
}
348-
349346
// reloadService shutdowns the current col.service and setups a new one according
350347
// to the latest configuration. It requires that col.parserProvider and col.factories
351348
// are properly populated to finish successfully.
@@ -370,3 +367,15 @@ func (col *Collector) reloadService(ctx context.Context) error {
370367

371368
return nil
372369
}
370+
371+
func (col *Collector) getBallastSize() uint64 {
372+
var ballastSize uint64
373+
extensions := col.service.GetExtensions()
374+
for _, extension := range extensions {
375+
if ext, ok := extension.(*ballastextension.MemoryBallast); ok {
376+
ballastSize = ext.GetBallastSize()
377+
break
378+
}
379+
}
380+
return ballastSize
381+
}

service/internal/builder/builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
)
3737

3838
// Flags adds flags related to basic building of the collector server to the given flagset.
39+
// Deprecated: keep this flag for preventing the breaking change. Use `ballast extension` instead.
3940
func Flags(flags *flag.FlagSet) {
4041
memBallastSize = flags.Uint(memBallastFlag, 0,
4142
fmt.Sprintf("Flag to specify size of memory (MiB) ballast to set. Ballast is not used when this is not specified. "+

service/internal/telemetry/process_telemetry.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ var viewRSSMemory = &view.View{
111111
func NewProcessMetricsViews(ballastSizeBytes uint64) (*ProcessMetricsViews, error) {
112112
pmv := &ProcessMetricsViews{
113113
prevTimeUnixNano: time.Now().UnixNano(),
114-
ballastSizeBytes: ballastSizeBytes,
115114
views: []*view.View{viewProcessUptime, viewAllocMem, viewTotalAllocMem, viewSysMem, viewCPUSeconds, viewRSSMemory},
115+
ballastSizeBytes: ballastSizeBytes,
116116
done: make(chan struct{}),
117117
}
118118

@@ -176,8 +176,10 @@ func (pmv *ProcessMetricsViews) updateViews() {
176176

177177
func (pmv *ProcessMetricsViews) readMemStats(ms *runtime.MemStats) {
178178
runtime.ReadMemStats(ms)
179-
ms.Alloc -= pmv.ballastSizeBytes
180-
ms.HeapAlloc -= pmv.ballastSizeBytes
181-
ms.HeapSys -= pmv.ballastSizeBytes
182-
ms.HeapInuse -= pmv.ballastSizeBytes
179+
if pmv.ballastSizeBytes > 0 {
180+
ms.Alloc -= pmv.ballastSizeBytes
181+
ms.HeapAlloc -= pmv.ballastSizeBytes
182+
ms.HeapSys -= pmv.ballastSizeBytes
183+
ms.HeapInuse -= pmv.ballastSizeBytes
184+
}
183185
}

service/internal/telemetry/process_telemetry_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
func TestProcessTelemetry(t *testing.T) {
2727
const ballastSizeBytes uint64 = 0
28-
2928
pmv, err := NewProcessMetricsViews(ballastSizeBytes)
3029
require.NoError(t, err)
3130
assert.NotNil(t, pmv)

0 commit comments

Comments
 (0)