forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metricbeat: Canonicalize MBean names in Jolokia module (elastic#7321)
We were setting the `canonicalNaming` option to `false` in requests to Jolokia, assuming that it should leave MBean names in responses as they are. We need that for mappings to work. But in some scenarios, as when using wildcards, Jolokia is responding with canonicalized names, what breaks mappings. This change canonicalizes names from config only for mappings and the pre-built request. If we see that after setting `canonicalNaming` to `true` there is some scenario in which Jolokia replies with non-canonicalized names, then we'd have to canonicalize also MBeans for responses, or rethink how we do the mapping.
- Loading branch information
Showing
6 changed files
with
143 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package jmx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCanonicalMBeanName(t *testing.T) { | ||
cases := []struct { | ||
mbean string | ||
expected string | ||
ok bool | ||
}{ | ||
{ | ||
mbean: ``, | ||
ok: false, | ||
}, | ||
{ | ||
mbean: `type=Runtime`, | ||
ok: false, | ||
}, | ||
{ | ||
mbean: `java.lang`, | ||
ok: false, | ||
}, | ||
{ | ||
mbean: `java.lang:`, | ||
ok: false, | ||
}, | ||
{ | ||
mbean: `java.lang:type=Runtime,name`, | ||
ok: false, | ||
}, | ||
{ | ||
mbean: `java.lang:type=Runtime`, | ||
expected: `java.lang:type=Runtime`, | ||
ok: true, | ||
}, | ||
{ | ||
mbean: `java.lang:name=Foo,type=Runtime`, | ||
expected: `java.lang:name=Foo,type=Runtime`, | ||
ok: true, | ||
}, | ||
{ | ||
mbean: `java.lang:type=Runtime,name=Foo`, | ||
expected: `java.lang:name=Foo,type=Runtime`, | ||
ok: true, | ||
}, | ||
{ | ||
mbean: `java.lang:type=Runtime,name=Foo*`, | ||
expected: `java.lang:name=Foo*,type=Runtime`, | ||
ok: true, | ||
}, | ||
{ | ||
mbean: `java.lang:type=Runtime,name=*`, | ||
expected: `java.lang:name=*,type=Runtime`, | ||
ok: true, | ||
}, | ||
{ | ||
mbean: `java.lang:type=Runtime,name="foo,bar"`, | ||
expected: `java.lang:name="foo,bar",type=Runtime`, | ||
ok: true, | ||
}, | ||
{ | ||
mbean: `Catalina:type=RequestProcessor,worker="http-nio-8080",name=HttpRequest1`, | ||
expected: `Catalina:name=HttpRequest1,type=RequestProcessor,worker="http-nio-8080"`, | ||
ok: true, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
canonical, err := canonicalizeMBeanName(c.mbean) | ||
if c.ok { | ||
assert.NoError(t, err, "failed parsing for: "+c.mbean) | ||
assert.Equal(t, c.expected, canonical, "mbean: "+c.mbean) | ||
} else { | ||
assert.Error(t, err, "should have failed for: "+c.mbean) | ||
} | ||
} | ||
} |
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