improve(go.d/rabbitmq): add support for old RabbitMQ whoami tags format (#21049)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ilya Mashchenko committed
Sep 25, 2025 at 19:28 UTC
9a87df8144fbd54e3ab99bd9db14cf2f76d648a2
2 files changed
+31
-3
src/go/plugin/go.d/collector/rabbitmq/collect.go
+6
-1
@@ -62,7 +62,12 @@ func (c *Collector) getClusterMeta() (id string, name string, err error) {
62
return "", "", fmt.Errorf("unexpected response: whoami: user name n is empty")
63
}
64
65
- if !slices.Contains(user.Tags, "administrator") {
65
+ // In RabbitMQ < 3.8.3 the `tags` field may be returned as a single string
66
+ // (e.g. "administrator,management") instead of an array. We intentionally
67
+ // treat it as one tag and do not split on commas here.
68
+ if !slices.ContainsFunc(user.Tags, func(s string) bool {
69
+ return strings.Contains(s, "administrator")
70
+ }) {
71
c.Warningf("user %s lacks 'administrator' tag: cluster ID and name cannot be collected.", user.Name)
72
return "", "", nil
73
}
src/go/plugin/go.d/collector/rabbitmq/restapi.go
+25
-2
@@ -2,6 +2,11 @@
2
3
package rabbitmq
4
5
+import (
6
+ "encoding/json"
7
+ "fmt"
8
+)
9
+
10
const (
11
urlPathAPIWhoami = "/api/whoami"
12
urlPathAPIDefinitions = "/api/definitions"
@@ -12,8 +17,26 @@ const (
17
)
18
19
type apiWhoamiResp struct {
15
- Name string `json:"name"`
16
- Tags []string `json:"tags"`
20
+ Name string `json:"name"`
21
+ Tags apiWhoamiTags `json:"tags"`
22
+}
23
+
24
+type apiWhoamiTags []string
25
+
26
+func (a *apiWhoamiTags) UnmarshalJSON(data []byte) error {
27
+ var multi []string
28
+ if err := json.Unmarshal(data, &multi); err == nil {
29
+ *a = multi
30
+ return nil
31
+ }
32
+
33
+ var single string
34
+ if err := json.Unmarshal(data, &single); err == nil {
35
+ *a = []string{single}
36
+ return nil
37
+ }
38
+
39
+ return fmt.Errorf("unexpected tags format: %s", string(data))
40
}
41
42
type apiDefinitionsResp struct {