• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oliver006 / redis_exporter / 17172001870

23 Aug 2025 05:58AM UTC coverage: 84.921% (-0.9%) from 85.87%
17172001870

Pull #1028

github

web-flow
Merge 891f7f01e into 7632b7b20
Pull Request #1028: sirupsen/log --> log/slog

121 of 249 new or added lines in 18 files covered. (48.59%)

6 existing lines in 1 file now uncovered.

2568 of 3024 relevant lines covered (84.92%)

13254.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.29
/exporter/nodes.go
1
package exporter
2

3
import (
4
        "log/slog"
5
        "regexp"
6
        "strings"
7

8
        "github.com/gomodule/redigo/redis"
9
)
10

11
var reNodeAddress = regexp.MustCompile(`^(?P<ip>.+):(?P<port>\d+)@(?P<cport>\d+)(?:,(?P<hostname>.+))?`)
12

13
func (e *Exporter) getClusterNodes(c redis.Conn) ([]string, error) {
4✔
14
        output, err := redis.String(doRedisCmd(c, "CLUSTER", "NODES"))
4✔
15
        if err != nil {
4✔
NEW
16
                slog.Error("Error getting cluster nodes", "error", err)
×
17
                return nil, err
×
18
        }
×
19

20
        lines := strings.Split(output, "\n")
4✔
21
        nodes := []string{}
4✔
22

4✔
23
        for _, line := range lines {
32✔
24
                if node, ok := parseClusterNodeString(line); ok {
52✔
25
                        nodes = append(nodes, node)
24✔
26
                }
24✔
27
        }
28

29
        return nodes, nil
4✔
30
}
31

32
/*
33
<id> <ip:port@cport[,hostname]> <flags> <master> <ping-sent> <pong-recv> <config-epoch> <link-state> <slot> <slot> ... <slot>
34
eaf69c70d876558a948ba62af0884a37d42c9627 127.0.0.1:7002@17002 master - 0 1742836359057 3 connected 10923-16383
35
*/
36
func parseClusterNodeString(node string) (string, bool) {
38✔
37
        slog.Debug("parseClusterNodeString node", "node", node)
38✔
38

38✔
39
        fields := strings.Fields(node)
38✔
40
        if len(fields) < 2 {
44✔
41
                slog.Debug("Invalid field count for node", "node", node)
6✔
42
                return "", false
6✔
43
        }
6✔
44

45
        address := reNodeAddress.FindStringSubmatch(fields[1])
32✔
46
        if len(address) < 3 {
33✔
47
                slog.Debug("Invalid format for node address", "address", fields[1])
1✔
48
                return "", false
1✔
49
        }
1✔
50

51
        return address[1] + ":" + address[2], true
31✔
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc