8000 bugfix(otelcol-config): quote tag names by echlebek · Pull Request #1661 · SumoLogic/sumologic-otel-collector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

bugfix(otelcol-config): quote tag names #1661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/tools/otelcol-config/add_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func AddTagAction(ctx *actionContext) error {
doc := conf.ConfD[docName]

const (
keyFmt = ".extensions.sumologic.collector_fields.%s = %s"
quoteKeyFmt = ".extensions.sumologic.collector_fields.%s = %q"
keyFmt = ".extensions.sumologic.collector_fields.%q = %s"
quoteKeyFmt = ".extensions.sumologic.collector_fields.%q = %q"
)

for tagName, tag := range ctx.Flags.AddTags {
Expand Down
6 changes: 6 additions & 0 deletions pkg/tools/otelcol-config/add_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func TestAddTagAction(t *testing.T) {
Flags: []string{"--add-tag", `foo=[1,2,3,4]`, "--override"},
ExpWrite: []byte("extensions:\n sumologic:\n collector_fields:\n foo:\n - 1\n - 2\n - 3\n - 4\n"),
},
{
Name: "dot in tag name",
Conf: fstest.MapFS{},
Flags: []string{"--add-tag", "foo.bar=baz"},
ExpWrite: []byte("extensions:\n sumologic:\n collector_fields:\n foo.bar: baz\n"),
},
}

for _, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/otelcol-config/delete_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func deleteTagOverride(ctx *actionContext, conf ConfDir) error {
encoder := yqlib.YamlFormat.EncoderFactory()
decoder := yqlib.YamlFormat.DecoderFactory()
for _, tagName := range ctx.Flags.DeleteTags {
key := fmt.Sprintf(".extensions.sumologic.collector_fields.%s", tagName)
key := fmt.Sprintf(".extensions.sumologic.collector_fields.%q", tagName)
for _, confKey := range readOrder {
doc := string(conf.ConfD[confKey])
result, err := eval.Evaluate(key, doc, encoder, decoder)
Expand Down Expand Up @@ -76,7 +76,7 @@ func deleteTag(ctx *actionContext, conf ConfDir, docName string, writeDoc func([
return nil
}

const keyFmt = "del(.extensions.sumologic.collector_fields.%s)"
const keyFmt = "del(.extensions.sumologic.collector_fields.%q)"

for _, tagName := range ctx.Flags.DeleteTags {
expression := fmt.Sprintf(keyFmt, tagName)
Expand Down
10 changes: 10 additions & 0 deletions pkg/tools/otelcol-config/delete_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ func TestDeleteTagAction(t *testing.T) {
Flags: []string{"--delete-tag", "foo"},
ExpConfDWrite: []byte("extensions:\n sumologic:\n collector_fields:\n bar: baz\n"),
},
{
Name: "dot in tag name",
Conf: fstest.MapFS{
path.Join(ConfDotD, ConfDSettings): &fstest.MapFile{
Data: []byte("extensions:\n sumologic:\n collector_fields:\n foo.bar: baz\n"),
},
},
Flags: []string{"--delete-tag", "foo.bar"},
ExpConfDWrite: []byte("extensions:\n sumologic:\n collector_fields: {}\n"),
},
}

for _, test := range tests {
Expand Down
Loading
0