-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed memory_ballast and making sure soft memory is set (#4404)
- Loading branch information
Samiur Arif
authored
Mar 25, 2024
1 parent
5cde966
commit 397a374
Showing
22 changed files
with
284 additions
and
78 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
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
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
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,69 @@ | ||
// 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 ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"regexp" | ||
|
||
"go.opentelemetry.io/collector/confmap" | ||
) | ||
|
||
// RemoveMemoryBallastKey is a MapConverter that removes a memory_ballast on a | ||
// extension config if it exists. | ||
type RemoveMemoryBallastKey struct{} | ||
|
||
func removeMemoryBallastStrElementFromSlice(strList []interface{}) []interface{} { | ||
ret := make([]interface{}, 0) | ||
for i, v := range strList { | ||
if v == "memory_ballast" { | ||
ret = append(ret, strList[:i]...) | ||
return append(ret, strList[i+1:]...) | ||
} | ||
} | ||
return strList | ||
} | ||
|
||
func (RemoveMemoryBallastKey) Convert(_ context.Context, cfgMap *confmap.Conf) error { | ||
if cfgMap == nil { | ||
return fmt.Errorf("cannot RemoveMemoryBallastKey on nil *confmap.Conf") | ||
} | ||
|
||
const firstExp = "extensions::memory_ballast.*" | ||
firstRegExp := regexp.MustCompile(firstExp) | ||
const secondExp = "service::extensions" | ||
secondRegExp := regexp.MustCompile(secondExp) | ||
|
||
out := map[string]any{} | ||
for _, k := range cfgMap.AllKeys() { | ||
if firstRegExp.MatchString(k) { | ||
log.Println("[WARNING] `memory_ballast` parameter in extensions is deprecated. Please remove it from your configuration.") | ||
continue | ||
} | ||
if secondRegExp.MatchString(k) { | ||
out[k] = cfgMap.Get(k) | ||
if extSlice, ok := out[k].([]any); ok { | ||
ret := removeMemoryBallastStrElementFromSlice(extSlice) | ||
out[k] = ret | ||
} | ||
continue | ||
} | ||
out[k] = cfgMap.Get(k) | ||
} | ||
*cfgMap = *confmap.NewFromStringMap(out) | ||
return nil | ||
} |
76 changes: 76 additions & 0 deletions
76
internal/configconverter/remove_memory_ballast_key_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,76 @@ | ||
// 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. | ||
|
||
// Taken from https://github.com/open-telemetry/opentelemetry-collector/blob/v0.66.0/confmap/converter/overwritepropertiesconverter/properties_test.go | ||
// to prevent breaking changes. | ||
package configconverter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/confmap" | ||
"go.opentelemetry.io/collector/confmap/confmaptest" | ||
) | ||
|
||
func TestRemoveMemoryBallastConverter_Empty(t *testing.T) { | ||
pmp := RemoveMemoryBallastKey{} | ||
conf := confmap.NewFromStringMap(map[string]interface{}{"foo": "bar"}) | ||
assert.NoError(t, pmp.Convert(context.Background(), conf)) | ||
assert.Equal(t, map[string]interface{}{"foo": "bar"}, conf.ToStringMap()) | ||
} | ||
|
||
func TestRemoveMemoryBallastConverter_With_Memory_Ballast(t *testing.T) { | ||
cfgMap, err := confmaptest.LoadConf("testdata/with_memory_ballast.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
pmp := RemoveMemoryBallastKey{} | ||
assert.NoError(t, pmp.Convert(context.Background(), cfgMap)) | ||
cfgMapExpected, err := confmaptest.LoadConf("testdata/with_memory_ballast_config_expected.yaml") | ||
require.NoError(t, err) | ||
assert.Equal(t, cfgMapExpected.ToStringMap(), cfgMap.ToStringMap()) | ||
} | ||
|
||
func TestMemoryBallastConverter_Without_Memory_Ballast(t *testing.T) { | ||
cfgMap, err := confmaptest.LoadConf("testdata/without_memory_ballast_config.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
pmp := RemoveMemoryBallastKey{} | ||
assert.NoError(t, pmp.Convert(context.Background(), cfgMap)) | ||
assert.Equal(t, cfgMap.ToStringMap(), cfgMap.ToStringMap()) | ||
} | ||
|
||
func TestRemoveMemoryBallastStrElementFromSlice(t *testing.T) { | ||
originalSlice := []interface{}{"foo", "bar", "memory_ballast", "item2"} | ||
actual := removeMemoryBallastStrElementFromSlice(originalSlice) | ||
expected := []interface{}{"foo", "bar", "item2"} | ||
assert.Equal(t, actual, expected) | ||
|
||
originalSlice1 := []interface{}{"foo", "bar", "foobar", "foobar1"} | ||
actual = removeMemoryBallastStrElementFromSlice(originalSlice1) | ||
assert.Equal(t, actual, originalSlice1) | ||
} | ||
|
||
func TestRemoveMemoryBallastConverter_With_Only_MemoryBallast_Value(t *testing.T) { | ||
cfgMap, err := confmaptest.LoadConf("testdata/with_memory_ballast_only.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
pmp := RemoveMemoryBallastKey{} | ||
assert.NoError(t, pmp.Convert(context.Background(), cfgMap)) | ||
cfgMapExpected, err := confmaptest.LoadConf("testdata/with_memory_ballast_only_expected.yaml") | ||
require.NoError(t, err) | ||
assert.Equal(t, cfgMapExpected.ToStringMap(), cfgMap.ToStringMap()) | ||
} |
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
15 changes: 15 additions & 0 deletions
15
internal/configconverter/testdata/with_memory_ballast.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,15 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
|
||
extensions: | ||
memory_ballast: | ||
size_mib: 120 | ||
|
||
service: | ||
extensions: [health_check, http_forwarder, zpages, memory_ballast, smartagent] | ||
pipelines: | ||
metrics: | ||
receivers: [otlp] |
11 changes: 11 additions & 0 deletions
11
internal/configconverter/testdata/with_memory_ballast_config_expected.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,11 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
|
||
service: | ||
extensions: [health_check, http_forwarder, zpages, smartagent] | ||
pipelines: | ||
metrics: | ||
receivers: [otlp] |
Oops, something went wrong.