Skip to content

Commit

Permalink
[Metricbeat] In jolokia jmx mbean canonization the keys should be sor…
Browse files Browse the repository at this point in the history
…ted first (#25631) (#25733)

(cherry picked from commit 182a4eb)

Co-authored-by: Hacko-nPacko <[email protected]>
  • Loading branch information
mergify[bot] and Hacko-nPacko authored May 17, 2021
1 parent 71251ef commit b9be52a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Metricbeat*

- Sort correctly the keys when accessing JMX through the Jolokia module {pull}25631[25631]
- Add dedot for tags in ec2 metricset and cloudwatch metricset. {issue}15843[15843] {pull}15844[15844]
- Use RFC3339 format for timestamps collected using the SQL module. {pull}15847[15847]
- Avoid parsing errors returned from prometheus endpoints. {pull}15712[15712]
- Change lookup_fields from metricset.host to service.address {pull}15883[15883]
- Add dedot for cloudwatch metric name. {issue}15916[15916] {pull}15917[15917]
- Fixed issue `logstash-xpack` module suddenly ceasing to monitor Logstash. {issue}15974[15974] {pull}16044[16044]
- Fix checking tagsFilter using length in cloudwatch metricset. {pull}14525[14525]
- Fixed bug with `elasticsearch/cluster_stats` metricset not recording license expiration date correctly. {issue}14541[14541] {pull}14591[14591]
- Log bulk failures from bulk API requests to monitoring cluster. {issue}14303[14303] {pull}14356[14356]
Expand Down
17 changes: 9 additions & 8 deletions metricbeat/module/jolokia/jmx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package jmx

import (
"encoding/json"

"fmt"
"regexp"
"sort"
Expand Down Expand Up @@ -140,21 +139,23 @@ var mbeanGetEscapeReplacer = strings.NewReplacer("\"", "!\"", ".", "!.", "!", "!
//
// Set "escape" parameter to true if you want to use the canonicalized name for a Jolokia HTTP GET request, false otherwise.
func (m *MBeanName) Canonicalize(escape bool) string {
var keySlice []string

var propertySlice []string
for key := range m.Properties {
keySlice = append(keySlice, key)
}

for key, value := range m.Properties {
sort.Strings(keySlice)

var propertySlice = make([]string, len(keySlice))
for i, key := range keySlice {
value := m.Properties[key]
tmpVal := value
if escape {
tmpVal = mbeanGetEscapeReplacer.Replace(value)
}

propertySlice = append(propertySlice, key+"="+tmpVal)
propertySlice[i] = key + "=" + tmpVal
}

sort.Strings(propertySlice)

return m.Domain + ":" + strings.Join(propertySlice, ",")
}

Expand Down
13 changes: 13 additions & 0 deletions metricbeat/module/jolokia/jmx/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ func TestCanonicalizeMbeanName(t *testing.T) {
escape: true,
expected: `Catalina:name=HttpRequest1,type=RequestProcessor,worker=!"http-nio-8080!"`,
},
{
mbean: &MBeanName{
Domain: `solr`,
Properties: map[string]string{
"dom1": "jvm",
"name": "used",
"name0": "memory",
"name1": "total",
},
},
escape: true,
expected: `solr:dom1=jvm,name=used,name0=memory,name1=total`,
},
}

for _, c := range cases {
Expand Down

0 comments on commit b9be52a

Please sign in to comment.