From 48bfa64dcc19ff98436414578105080eebf1c45b Mon Sep 17 00:00:00 2001 From: Hacko-nPacko Date: Mon, 17 May 2021 11:58:51 +0300 Subject: [PATCH] [Metricbeat] In jolokia jmx mbean canonization the keys should be sorted first (#25631) (cherry picked from commit 182a4eb37220ca6b5799f36a2a55128217d47650) --- CHANGELOG.next.asciidoc | 7 +++++++ metricbeat/module/jolokia/jmx/config.go | 17 +++++++++-------- metricbeat/module/jolokia/jmx/config_test.go | 13 +++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 9433e7dd279c..f729cb3edcc6 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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] diff --git a/metricbeat/module/jolokia/jmx/config.go b/metricbeat/module/jolokia/jmx/config.go index 3e3d623662e7..7f9006f61f9f 100644 --- a/metricbeat/module/jolokia/jmx/config.go +++ b/metricbeat/module/jolokia/jmx/config.go @@ -19,7 +19,6 @@ package jmx import ( "encoding/json" - "fmt" "regexp" "sort" @@ -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, ",") } diff --git a/metricbeat/module/jolokia/jmx/config_test.go b/metricbeat/module/jolokia/jmx/config_test.go index e873ccec8662..4a2cfa62c52d 100644 --- a/metricbeat/module/jolokia/jmx/config_test.go +++ b/metricbeat/module/jolokia/jmx/config_test.go @@ -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 {