Skip to content

Commit e917e0a

Browse files
authored
[OTel] Fix CLI example to use proper syntax (#10259)
This uses the expected `::` syntax instead of `.` for the `--set` argument.
1 parent 117ba4f commit e917e0a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

internal/pkg/agent/cmd/otel_flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func setupOtelFlags(flags *pflag.FlagSet) {
2727
" single location can be set per flag entry e.g. `--config=file:/path/to/first --config=file:path/to/second`.")
2828

2929
flags.StringArray(otelSetFlagName, []string{}, "Set arbitrary component config property. The component has to be defined in the config file and the flag"+
30-
" has a higher precedence. Array config properties are overridden and maps are joined. Example --set=processors.batch.timeout=2s")
30+
" has a higher precedence. Array config properties are overridden and maps are joined. Example --set \"processors::batch::timeout=2s\"")
3131

3232
flags.Bool(manager.OtelSetSupervisedFlagName, false, "Set that this collector is supervised.")
3333
// the only error we can get here is that the flag does not exist

internal/pkg/agent/cmd/validate_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ func TestValidateCommand(t *testing.T) {
2323
[]string{filepath.Join("testdata", "otel", "otel.yml")},
2424
false,
2525
},
26+
{
27+
"otel config with set",
28+
[]string{filepath.Join("testdata", "otel", "otel.yml"), "yaml:processors::resource::attributes: [{ key: service.name, action: insert, value: elastic-otel-test1 }]"},
29+
false,
30+
},
31+
{
32+
"otel config with set missing action field",
33+
[]string{filepath.Join("testdata", "otel", "otel.yml"), "yaml:processors::resource::attributes: [{ key: service.name, value: elastic-otel-test2 }]"},
34+
true,
35+
},
36+
{
37+
"otel config with set missing key field",
38+
[]string{filepath.Join("testdata", "otel", "otel.yml"), "yaml:processors::resource::attributes: [{ action: insert, value: elastic-otel-test3 }]"},
39+
true,
40+
},
41+
{
42+
"otel config with set missing key and action fields",
43+
[]string{filepath.Join("testdata", "otel", "otel.yml"), "yaml:processors::resource::attributes: [{ value: elastic-otel-test4 }]"},
44+
true,
45+
},
2646
{
2747
"agent config",
2848
[]string{filepath.Join("testdata", "otel", "elastic-agent.yml")},
@@ -33,7 +53,12 @@ func TestValidateCommand(t *testing.T) {
3353
for _, tc := range tt {
3454
t.Run(tc.Name, func(t *testing.T) {
3555
err := validateOtelConfig(context.Background(), tc.ConfigPaths)
36-
require.Equal(t, tc.ExpectingErr, err != nil)
56+
57+
if tc.ExpectingErr {
58+
require.Error(t, err)
59+
} else {
60+
require.NoError(t, err)
61+
}
3762
})
3863
}
3964
}

0 commit comments

Comments
 (0)