Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/aloksingh_redis-receiver-cluster-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: redisreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Support CLUSTER INFO metric extraction from redis instance"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [38117]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
7 changes: 7 additions & 0 deletions receiver/redisreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
type client interface {
// retrieves a string of key/value pairs of redis metadata
retrieveInfo() (string, error)
// retrieves a string of key/value pairs of cluster metadata
retrieveClusterInfo() (string, error)
// line delimiter
// redis lines are delimited by \r\n, files (for testing) by \n
delimiter() string
Expand Down Expand Up @@ -44,6 +46,11 @@ func (c *redisClient) retrieveInfo() (string, error) {
return c.client.Info(context.Background(), "all").Result()
}

// Retrieve Redis CLUSTER INFO
func (c *redisClient) retrieveClusterInfo() (string, error) {
return c.client.ClusterInfo(context.Background()).Result()
}

// close client to release connection pool.
func (c *redisClient) close() error {
return c.client.Close()
Expand Down
4 changes: 4 additions & 0 deletions receiver/redisreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (fakeClient) retrieveInfo() (string, error) {
return readFile("info")
}

func (fakeClient) retrieveClusterInfo() (string, error) {
return readFile("clusterInfo")
}

func (fakeClient) close() error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions receiver/redisreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ type Config struct {
TLS configtls.ClientConfig `mapstructure:"tls,omitempty"`

MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`

ClusterInfoEnabled bool `mapstructure:"cluster_info_enabled"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be calculated by checking if any of the clusterInfo metrics are enabled.

Otherwise a user could enable the metrics, but disable this flag, and end up not getting the metrics they expect.

}

// configInfo holds configuration information to be used as resource/metrics attributes.
type configInfo struct {
Address string
Port string
Address string
Port string
ClusterInfoEnabled bool
}

func newConfigInfo(cfg *Config) (configInfo, error) {
address, port, err := net.SplitHostPort(cfg.Endpoint)
if err != nil {
return configInfo{}, fmt.Errorf("invalid endpoint %q: %w", cfg.Endpoint, err)
}
return configInfo{Address: address, Port: port}, nil
return configInfo{Address: address, Port: port, ClusterInfoEnabled: cfg.ClusterInfoEnabled}, nil
}
8 changes: 8 additions & 0 deletions receiver/redisreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ metrics:
enabled: true
```

### redis.cluster.slots_assigned

Number of slots which are associated to some node

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {slots} | Gauge | Int |

### redis.cmd.calls

Total number of calls for a command
Expand Down
1 change: 1 addition & 0 deletions receiver/redisreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestIntegrationV6(t *testing.T) {
testcontainers.ContainerRequest{
Image: "redis:6.0.3",
ExposedPorts: []string{redisPort},
Cmd: []string{"redis-server", "--cluster-enabled", "yes"},
WaitingFor: wait.ForListeningPort(redisPort),
}),
scraperinttest.WithCustomConfig(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions receiver/redisreceiver/internal/metadata/generated_metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ all_set:
enabled: true
redis.clients.max_output_buffer:
enabled: true
redis.cluster.slots_assigned:
enabled: true
redis.cmd.calls:
enabled: true
redis.cmd.latency:
Expand Down Expand Up @@ -88,6 +90,8 @@ none_set:
enabled: false
redis.clients.max_output_buffer:
enabled: false
redis.cluster.slots_assigned:
enabled: false
redis.cmd.calls:
enabled: false
redis.cmd.latency:
Expand Down
10 changes: 10 additions & 0 deletions receiver/redisreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ metrics:
gauge:
value_type: int
attributes: [db]

# below are all disabled by default
redis.replication.replica_offset:
enabled: false
Expand All @@ -352,6 +353,15 @@ metrics:
gauge:
value_type: int

redis.cluster.slots_assigned:
enabled: false
description: "Number of slots which are associated to some node"
unit: "{slots}"
gauge:
value_type: int
monotonic: false
aggregation_temporality: cumulative

tests:
config:
endpoint: localhost:6379
10 changes: 10 additions & 0 deletions receiver/redisreceiver/redis_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func (rs *redisScraper) Scrape(context.Context) (pmetric.Metrics, error) {
return pmetric.Metrics{}, err
}

if rs.configInfo.ClusterInfoEnabled {
clusterInf, errClsInf := rs.redisSvc.clusterInfo()
if errClsInf != nil {
return pmetric.Metrics{}, errClsInf
}
for k, v := range clusterInf {
inf[k] = v
}
}

now := pcommon.NewTimestampFromTime(time.Now())
currentUptime, err := inf.getUptimeInSeconds()
if err != nil {
Expand Down
32 changes: 24 additions & 8 deletions receiver/redisreceiver/redis_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ func newRedisSvc(client client) *redisSvc {
}
}

// Calls the Redis INFO command on the client and returns an `info` map.
func (p *redisSvc) info() (info, error) {
str, err := p.client.retrieveInfo()
if err != nil {
return nil, err
}
lines := strings.Split(str, p.delimiter)
func (p *redisSvc) retrievePairsFromString(str string) info {
attrs := make(map[string]string)

lines := strings.Split(str, p.delimiter)
for _, line := range lines {
if len(line) == 0 || strings.HasPrefix(line, "#") {
continue
Expand All @@ -39,5 +35,25 @@ func (p *redisSvc) info() (info, error) {
attrs[pair[0]] = pair[1]
}
}
return attrs, nil

return attrs
}

// Calls the Redis INFO command on the client and returns an `info` map.
func (p *redisSvc) info() (info, error) {
strInfo, err := p.client.retrieveInfo()
if err != nil {
return nil, err
}

return p.retrievePairsFromString(strInfo), nil
}

func (p *redisSvc) clusterInfo() (info, error) {
strClusterInfo, err := p.client.retrieveClusterInfo()
if err != nil {
return nil, err
}

return p.retrievePairsFromString(strClusterInfo), nil
}
1 change: 1 addition & 0 deletions receiver/redisreceiver/testdata/clusterInfo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cluster_slots_assigned:12
Loading