From 15d4dece98bb20abc611629efcef8a5b37a7db25 Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Thu, 25 Sep 2025 15:05:59 +0300 Subject: [PATCH 1/3] improve(go.d/rabbitmq): add support for old RabbitMQ whoami tags format --- .../plugin/go.d/collector/rabbitmq/restapi.go | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/go/plugin/go.d/collector/rabbitmq/restapi.go b/src/go/plugin/go.d/collector/rabbitmq/restapi.go index 10dd40734a4eae..3cef37f138cbc4 100644 --- a/src/go/plugin/go.d/collector/rabbitmq/restapi.go +++ b/src/go/plugin/go.d/collector/rabbitmq/restapi.go @@ -2,6 +2,11 @@ package rabbitmq +import ( + "encoding/json" + "fmt" +) + const ( urlPathAPIWhoami = "/api/whoami" urlPathAPIDefinitions = "/api/definitions" @@ -12,8 +17,31 @@ const ( ) type apiWhoamiResp struct { - Name string `json:"name"` - Tags []string `json:"tags"` + Name string `json:"name"` + Tags apiWhoamiTags `json:"tags"` +} + +type apiWhoamiTags []string + +func (a *apiWhoamiTags) UnmarshalJSON(data []byte) error { + var multi []string + if err := json.Unmarshal(data, &multi); err == nil { + *a = multi + return nil + } + + var single string + if err := json.Unmarshal(data, &single); err == nil { + *a = []string{single} + return nil + } + + if string(data) == "null" { + *a = nil + return nil + } + + return fmt.Errorf("unexpected tags format: %s", string(data)) } type apiDefinitionsResp struct { From 3cdb34615d7777bd53caef59ee8868cd19e70bef Mon Sep 17 00:00:00 2001 From: Ilya Mashchenko Date: Thu, 25 Sep 2025 15:10:27 +0300 Subject: [PATCH 2/3] Update src/go/plugin/go.d/collector/rabbitmq/restapi.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/go/plugin/go.d/collector/rabbitmq/restapi.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/go/plugin/go.d/collector/rabbitmq/restapi.go b/src/go/plugin/go.d/collector/rabbitmq/restapi.go index 3cef37f138cbc4..b54419a1f116a7 100644 --- a/src/go/plugin/go.d/collector/rabbitmq/restapi.go +++ b/src/go/plugin/go.d/collector/rabbitmq/restapi.go @@ -36,11 +36,6 @@ func (a *apiWhoamiTags) UnmarshalJSON(data []byte) error { return nil } - if string(data) == "null" { - *a = nil - return nil - } - return fmt.Errorf("unexpected tags format: %s", string(data)) } From 01da12998739fcadda07452148764ad164677783 Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Thu, 25 Sep 2025 15:28:45 +0300 Subject: [PATCH 3/3] fix tags contains administrator check --- src/go/plugin/go.d/collector/rabbitmq/collect.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/go/plugin/go.d/collector/rabbitmq/collect.go b/src/go/plugin/go.d/collector/rabbitmq/collect.go index ac8d807f014d4d..8283d64a0cc924 100644 --- a/src/go/plugin/go.d/collector/rabbitmq/collect.go +++ b/src/go/plugin/go.d/collector/rabbitmq/collect.go @@ -62,7 +62,12 @@ func (c *Collector) getClusterMeta() (id string, name string, err error) { return "", "", fmt.Errorf("unexpected response: whoami: user name n is empty") } - if !slices.Contains(user.Tags, "administrator") { + // In RabbitMQ < 3.8.3 the `tags` field may be returned as a single string + // (e.g. "administrator,management") instead of an array. We intentionally + // treat it as one tag and do not split on commas here. + if !slices.ContainsFunc(user.Tags, func(s string) bool { + return strings.Contains(s, "administrator") + }) { c.Warningf("user %s lacks 'administrator' tag: cluster ID and name cannot be collected.", user.Name) return "", "", nil }