-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove memory_limiter ballast_size_mib key from config if it exists.
Also remove adding ballast extension from the PR.
- Loading branch information
Showing
9 changed files
with
146 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
internal/configprovider/mem_limit_ballast_remover_parser_provider.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package configprovider | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"regexp" | ||
|
||
"go.opentelemetry.io/collector/config/configparser" | ||
"go.opentelemetry.io/collector/service/parserprovider" | ||
) | ||
|
||
var ballastKeyRegexp *regexp.Regexp | ||
|
||
func init() { | ||
const expr = "processors::memory_limiter(/\\w+)?::ballast_size_mib" | ||
ballastKeyRegexp, _ = regexp.Compile(expr) | ||
} | ||
|
||
// memLimitBallastRemoverParserProvider implements ParserProvider, wraps a | ||
// ParserProvider, and removes any ballast_size_mib key from the memory_limiter | ||
// processor, if one exists, from the wrapped config. This is to ensure that the | ||
// Collector will still start when support for this key gets removed. | ||
type memLimitBallastRemoverParserProvider struct { | ||
pp parserprovider.ParserProvider | ||
} | ||
|
||
var _ parserprovider.ParserProvider = (*memLimitBallastRemoverParserProvider)(nil) | ||
|
||
func NewMemLimitRemoverParserProvider(pp parserprovider.ParserProvider) parserprovider.ParserProvider { | ||
return &memLimitBallastRemoverParserProvider{pp: pp} | ||
} | ||
|
||
func (mpp memLimitBallastRemoverParserProvider) Get() (*configparser.ConfigMap, error) { | ||
cfgMap, err := mpp.pp.Get() | ||
if err != nil { | ||
return nil, fmt.Errorf("memLimitBallastRemoverParserProvider.Get(): %w", err) | ||
} | ||
out := configparser.NewParser() | ||
for _, k := range cfgMap.AllKeys() { | ||
if isMemLimitBallastKey(k) { | ||
log.Println("Deprecated memory_limiter processor `ballast_size_mib` key found. Removing from config.") | ||
} else { | ||
out.Set(k, cfgMap.Get(k)) | ||
} | ||
} | ||
return out, nil | ||
} | ||
|
||
func isMemLimitBallastKey(k string) bool { | ||
return ballastKeyRegexp.MatchString(k) | ||
} |
58 changes: 58 additions & 0 deletions
58
internal/configprovider/mem_limit_ballast_remover_parser_provider_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package configprovider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsMemLimitBallastKey(t *testing.T) { | ||
assert.False(t, isMemLimitBallastKey("processors::ballast_size_mib")) | ||
assert.True(t, isMemLimitBallastKey("processors::memory_limiter::ballast_size_mib")) | ||
assert.True(t, isMemLimitBallastKey("processors::memory_limiter/foo::ballast_size_mib")) | ||
} | ||
|
||
func TestMemLimitBallastRemoverPP(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fname string | ||
key string | ||
}{ | ||
{ | ||
name: "default", | ||
fname: "testdata/ballast_mem_limiter.yaml", | ||
key: "processors::memory_limiter::ballast_size_mib", | ||
}, | ||
{ | ||
name: "custom", | ||
fname: "testdata/ballast_mem_limiter_custom.yaml", | ||
key: "processors::memory_limiter/foo::ballast_size_mib", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
pp := &memLimitBallastRemoverParserProvider{ | ||
&fileParserProvider{FileName: test.fname}, | ||
} | ||
cfgMap, err := pp.Get() | ||
require.NoError(t, err) | ||
b := cfgMap.IsSet(test.key) | ||
assert.False(t, b) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.