Skip to content

Commit 58ca6ba

Browse files
codebotenrogercoll
andauthored
[receiver/jmx] fix config parsing issue (open-telemetry#41952)
The scraper should support passing in a jmx_configs parameter instead of a target_system. This was not working previously, and is fixed with the change in this PR --------- Signed-off-by: alex boten <[email protected]> Co-authored-by: Roger Coll <[email protected]>
1 parent ee3a346 commit 58ca6ba

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: jmxreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "support `jmx_configs` for jmx scraper usecase"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [41952]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/jmxreceiver/config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,11 @@ func (c *Config) Validate() error {
295295
missingFields = append(missingFields, "`endpoint`")
296296
}
297297
if c.TargetSystem == "" {
298-
// jmx-scraper can specify jmx_configs instead
299-
if c.validateJar(jmxScraperVersions, c.JARPath) == nil && c.JmxConfigs == "" {
300-
missingFields = append(missingFields, "`target_system`", "`jmx_configs`")
298+
// jmx-scraper can use jmx_configs instead
299+
if c.validateJar(jmxScraperVersions, c.JARPath) == nil {
300+
if c.JmxConfigs == "" {
301+
missingFields = append(missingFields, "`target_system`", "`jmx_configs`")
302+
}
301303
} else {
302304
missingFields = append(missingFields, "`target_system`")
303305
}
@@ -337,9 +339,11 @@ func (c *Config) Validate() error {
337339
}
338340
}
339341

340-
for _, system := range strings.Split(c.TargetSystem, ",") {
341-
if _, ok := validTargetSystems[strings.ToLower(system)]; !ok {
342-
return fmt.Errorf("`target_system` list may only be a subset of %s", listKeys(validTargetSystems))
342+
if c.TargetSystem != "" {
343+
for _, system := range strings.Split(c.TargetSystem, ",") {
344+
if _, ok := validTargetSystems[strings.ToLower(system)]; !ok {
345+
return fmt.Errorf("`target_system` list may only be a subset of %s", listKeys(validTargetSystems))
346+
}
343347
}
344348
}
345349

receiver/jmxreceiver/config_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ func TestLoadConfig(t *testing.T) {
7272
},
7373
},
7474
},
75+
{
76+
id: component.NewIDWithName(metadata.Type, "validscraperjmxconfigs"),
77+
expected: &Config{
78+
JARPath: "testdata/fake_jmx_scraper.jar",
79+
Endpoint: "myendpoint:55555",
80+
CollectionInterval: 10 * time.Second,
81+
JmxConfigs: "testdata/rules.yaml",
82+
OTLPExporterConfig: otlpExporterConfig{
83+
Endpoint: "0.0.0.0:0",
84+
TimeoutSettings: exporterhelper.TimeoutConfig{
85+
Timeout: 5 * time.Second,
86+
},
87+
},
88+
},
89+
},
7590
{
7691
id: component.NewIDWithName(metadata.Type, "missingendpoint"),
7792
expectedErr: "missing required field(s): `endpoint`",

receiver/jmxreceiver/testdata/config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ jmx/all:
2424
one: two
2525
additional_jars:
2626
- testdata/fake_additional.jar
27+
jmx/validscraperjmxconfigs:
28+
jar_path: testdata/fake_jmx_scraper.jar
29+
endpoint: myendpoint:55555
30+
otlp:
31+
endpoint: 0.0.0.0:0
32+
timeout: 5s
33+
jmx_configs: testdata/rules.yaml
2734
jmx/missingendpoint:
2835
jar_path: testdata/fake_jmx.jar
2936
target_system: jvm

0 commit comments

Comments
 (0)