-
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.
Handle backwards compatibility of internal ballast removal (#759)
* Remove memory_limiter ballast_size_mib key from config if it exists.]\ * Generalize config converter * Add no-convert-config flag
- Loading branch information
Pablo Collins
committed
Sep 22, 2021
1 parent
5401dbb
commit 938df81
Showing
7 changed files
with
257 additions
and
7 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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 configconverter | ||
|
||
import ( | ||
"log" | ||
"regexp" | ||
|
||
"go.opentelemetry.io/collector/config/configparser" | ||
) | ||
|
||
// RemoveBallastKey is a CfgMapFunc that removes a ballast_size_mib on a | ||
// memory_limiter processor config if it exists. This config key will go away at | ||
// some point (or already has) at which point its presence in a config will | ||
// prevent the Collector from starting. | ||
func RemoveBallastKey(cfgMap *configparser.ConfigMap) *configparser.ConfigMap { | ||
const expr = "processors::memory_limiter(/\\w+)?::ballast_size_mib" | ||
ballastKeyRegexp, _ := regexp.Compile(expr) | ||
|
||
out := configparser.NewParser() | ||
for _, k := range cfgMap.AllKeys() { | ||
if ballastKeyRegexp.MatchString(k) { | ||
log.Println("Deprecated memory_limiter processor `ballast_size_mib` key found. Removing from config.") | ||
} else { | ||
out.Set(k, cfgMap.Get(k)) | ||
} | ||
} | ||
return out | ||
} |
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,55 @@ | ||
// 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 configconverter | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/config/configparser" | ||
"go.opentelemetry.io/collector/service/parserprovider" | ||
) | ||
|
||
// converterProvider wraps a ParserProvider and accepts a list of functions that | ||
// convert ConfigMaps. The idea is for this type to conform to the open-closed | ||
// principle. | ||
type converterProvider struct { | ||
wrapped parserprovider.ParserProvider | ||
cfgMapFuncs []CfgMapFunc | ||
} | ||
|
||
type CfgMapFunc func(*configparser.ConfigMap) *configparser.ConfigMap | ||
|
||
var _ parserprovider.ParserProvider = (*converterProvider)(nil) | ||
|
||
func ParserProvider(wrapped parserprovider.ParserProvider, funcs ...CfgMapFunc) parserprovider.ParserProvider { | ||
return &converterProvider{wrapped: wrapped, cfgMapFuncs: funcs} | ||
} | ||
|
||
func (p converterProvider) Get() (*configparser.ConfigMap, error) { | ||
cfgMap, err := p.wrapped.Get() | ||
if err != nil { | ||
return nil, fmt.Errorf("converterProvider.Get(): %w", err) | ||
} | ||
|
||
for _, cfgMapFunc := range p.cfgMapFuncs { | ||
cfgMap = cfgMapFunc(cfgMap) | ||
} | ||
|
||
out := configparser.NewParser() | ||
for _, k := range cfgMap.AllKeys() { | ||
out.Set(k, cfgMap.Get(k)) | ||
} | ||
return out, nil | ||
} |
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,62 @@ | ||
// 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 configconverter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/config/configparser" | ||
) | ||
|
||
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 := &converterProvider{ | ||
wrapped: &fileParserProvider{fileName: test.fname}, | ||
cfgMapFuncs: []CfgMapFunc{RemoveBallastKey}, | ||
} | ||
cfgMap, err := pp.Get() | ||
require.NoError(t, err) | ||
b := cfgMap.IsSet(test.key) | ||
assert.False(t, b) | ||
}) | ||
} | ||
} | ||
|
||
type fileParserProvider struct { | ||
fileName string | ||
} | ||
|
||
func (fpp fileParserProvider) Get() (*configparser.ConfigMap, error) { | ||
return configparser.NewParserFromFile(fpp.fileName) | ||
} |
30 changes: 30 additions & 0 deletions
30
internal/configconverter/testdata/ballast_mem_limiter.yaml
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,30 @@ | ||
extensions: | ||
memory_ballast: | ||
size_mib: 64 | ||
receivers: | ||
hostmetrics: | ||
collection_interval: 1s | ||
scrapers: | ||
cpu: | ||
processors: | ||
memory_limiter: | ||
check_interval: 1s | ||
limit_mib: 4000 | ||
spike_limit_mib: 800 | ||
ballast_size_mib: 64 | ||
exporters: | ||
logging: | ||
loglevel: info | ||
sampling_initial: 2 | ||
sampling_thereafter: 500 | ||
service: | ||
pipelines: | ||
metrics: | ||
receivers: | ||
- hostmetrics | ||
processors: | ||
- memory_limiter | ||
exporters: | ||
- logging | ||
extensions: | ||
- memory_ballast |
30 changes: 30 additions & 0 deletions
30
internal/configconverter/testdata/ballast_mem_limiter_custom.yaml
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,30 @@ | ||
extensions: | ||
memory_ballast: | ||
size_mib: 64 | ||
receivers: | ||
hostmetrics: | ||
collection_interval: 1s | ||
scrapers: | ||
cpu: | ||
processors: | ||
memory_limiter/foo: | ||
check_interval: 1s | ||
limit_mib: 4000 | ||
spike_limit_mib: 800 | ||
ballast_size_mib: 64 | ||
exporters: | ||
logging: | ||
loglevel: info | ||
sampling_initial: 2 | ||
sampling_thereafter: 500 | ||
service: | ||
pipelines: | ||
metrics: | ||
receivers: | ||
- hostmetrics | ||
processors: | ||
- memory_limiter/foo | ||
exporters: | ||
- logging | ||
extensions: | ||
- memory_ballast |