Skip to content

Commit ce229d2

Browse files
Use IgnoreCommas in default config options (#4436)
* use IgnoreCommas in default config options * add config line * add notice * add changelog * change test to make output more helpful
1 parent 0dc98db commit ce229d2

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: feature
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: ucfg-parser-fix
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
description: Fix config unpacking when config strings contain list-like passages
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: elastic-agent
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/4436
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

internal/pkg/config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var DefaultOptions = []interface{}{
3838
ucfg.ResolveEnv,
3939
ucfg.VarExp,
4040
VarSkipKeys("inputs"),
41+
ucfg.IgnoreCommas,
4142
}
4243

4344
// Config custom type over a ucfg.Config to add new methods on the object.
@@ -155,9 +156,8 @@ func (c *Config) ToMapStr(opts ...interface{}) (map[string]interface{}, error) {
155156
}
156157
ucfgOpts, local, err := getOptions(opts...)
157158
if err != nil {
158-
return nil, fmt.Errorf("error unpacking logs: %w", err)
159+
return nil, fmt.Errorf("error unpacking config: %w", err)
159160
}
160-
161161
// remove and unpack each skip keys into its own map with no resolve
162162
// so that variables are not substituted
163163
skippedKeys := map[string]interface{}{}

internal/pkg/config/config_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ func testToMapStr(t *testing.T) {
7878
assert.True(t, reflect.DeepEqual(m, nm))
7979
}
8080

81+
func TestCommaParsing(t *testing.T) {
82+
_ = os.Setenv("testname", "motmot")
83+
// test to make sure that we don't blow up the parsers when we have a `,` in a string
84+
inMap := map[string]interface{}{
85+
"test": "startsWith('${testname}','motmot')",
86+
}
87+
outMap := map[string]interface{}{
88+
"test": "startsWith('motmot','motmot')",
89+
}
90+
c := MustNewConfigFrom(inMap)
91+
parsedMap, err := c.ToMapStr()
92+
require.NoError(t, err)
93+
t.Logf("got :%#v", parsedMap)
94+
require.Equal(t, outMap, parsedMap)
95+
}
96+
8197
func testLoadFiles(t *testing.T) {
8298
tmp, err := os.MkdirTemp("", "watch")
8399
require.NoError(t, err)

0 commit comments

Comments
 (0)