Skip to content

Commit 2a0c044

Browse files
authored
[receiver/redisreceiver] Add support for Redis sentinel information (#42401)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add support for exposing Redis sentinel and mode metrics. Redis Sentinel metrics with Redis mode: ```sh # HELP redis_mode Redis server mode # TYPE redis_mode gauge redis_mode{mode="sentinel",otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 1 # HELP redis_sentinel_masters Number of masters monitored by Sentinel. # TYPE redis_sentinel_masters gauge redis_sentinel_masters{otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 1 # HELP redis_sentinel_running_scripts Number of running Sentinel scripts. # TYPE redis_sentinel_running_scripts gauge redis_sentinel_running_scripts{otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 0 # HELP redis_sentinel_scripts_queue_length Length of Sentinel scripts queue. # TYPE redis_sentinel_scripts_queue_length gauge redis_sentinel_scripts_queue_length{otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 0 # HELP redis_sentinel_simulate_failure_flags Simulated failure flags bitmask. # TYPE redis_sentinel_simulate_failure_flags gauge redis_sentinel_simulate_failure_flags{otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 0 # HELP redis_sentinel_tilt Whether Sentinel is in TILT mode (1 = tilt, 0 = normal). # TYPE redis_sentinel_tilt gauge redis_sentinel_tilt{otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 0 # HELP redis_sentinel_tilt_since_seconds Duration in seconds of current TILT, or -1 if not in TILT mode. # TYPE redis_sentinel_tilt_since_seconds gauge redis_sentinel_tilt_since_seconds{otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} -1 # HELP redis_sentinel_tilt_total Total TILT occurrences since start. # TYPE redis_sentinel_tilt_total counter redis_sentinel_tilt_total{otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 0 ``` Redis mode (standalone): ```sh # HELP redis_mode Redis server mode # TYPE redis_mode gauge redis_mode{mode="standalone",otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 1 ``` Redis mode (cluster): ```sh # HELP redis_mode Redis server mode # TYPE redis_mode gauge redis_mode{mode="cluster",otel_scope_name="github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver",otel_scope_schema_url="",otel_scope_version="0.134.0-dev"} 1 ``` <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #42365 <!--Describe what testing was performed and which tests were added.--> #### Testing I tested this against all the possible modes (sentinel, standalone, and cluster). The sentinel metrics are only evaluated and exposed when `redis_mode:sentinel`. I also added integration tests `TestIntegrationV8Sentinel` for the `sentinel` mode. <!--Describe the documentation added.--> #### Documentation Updated the documentation using `mdatagen` <!--Please delete paragraphs that you did not use before submitting.--> --------- Signed-off-by: Paulo Dias <[email protected]>
1 parent 9a21c47 commit 2a0c044

File tree

12 files changed

+1194
-6
lines changed

12 files changed

+1194
-6
lines changed

.chloggen/feat_42365.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: "enhancement"
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: "receiver/redis"
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Add support for redis.mode and redis.sentinel.* metrics"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [42365]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/redisreceiver/documentation.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,20 @@ Initial amount of memory consumed by Redis at startup in bytes
455455
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
456456
| By | Sum | Int | Cumulative | false | Development |
457457
458+
### redis.mode
459+
460+
Redis server mode
461+
462+
| Unit | Metric Type | Value Type | Stability |
463+
| ---- | ----------- | ---------- | --------- |
464+
| {mode} | Gauge | Int | Development |
465+
466+
#### Attributes
467+
468+
| Name | Description | Values | Requirement Level |
469+
| ---- | ----------- | ------ | -------- |
470+
| mode | Redis server mode | Str: ``cluster``, ``sentinel``, ``standalone`` | Recommended |
471+
458472
### redis.replication.replica_offset
459473
460474
Offset for redis replica
@@ -477,6 +491,54 @@ Redis node's role
477491
| ---- | ----------- | ------ | -------- |
478492
| role | Redis node's role | Str: ``replica``, ``primary`` | Recommended |
479493
494+
### redis.sentinel.masters
495+
496+
Number of masters monitored by Sentinel.
497+
498+
| Unit | Metric Type | Value Type | Stability |
499+
| ---- | ----------- | ---------- | --------- |
500+
| {master} | Gauge | Int | Development |
501+
502+
### redis.sentinel.running_scripts
503+
504+
Number of running Sentinel scripts.
505+
506+
| Unit | Metric Type | Value Type | Stability |
507+
| ---- | ----------- | ---------- | --------- |
508+
| {script} | Gauge | Int | Development |
509+
510+
### redis.sentinel.scripts_queue_length
511+
512+
Length of Sentinel scripts queue.
513+
514+
| Unit | Metric Type | Value Type | Stability |
515+
| ---- | ----------- | ---------- | --------- |
516+
| {script} | Gauge | Int | Development |
517+
518+
### redis.sentinel.simulate_failure_flags
519+
520+
Simulated failure flags bitmask.
521+
522+
| Unit | Metric Type | Value Type | Stability |
523+
| ---- | ----------- | ---------- | --------- |
524+
| {flag} | Gauge | Int | Development |
525+
526+
### redis.sentinel.tilt_since_seconds
527+
528+
Duration in seconds of current TILT, or -1 if not in TILT mode.
529+
530+
| Unit | Metric Type | Value Type | Stability |
531+
| ---- | ----------- | ---------- | --------- |
532+
| s | Gauge | Int | Development |
533+
534+
### redis.sentinel.total_tilt
535+
536+
Total TILT occurrences since start.
537+
538+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
539+
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
540+
| {event} | Sum | Int | Cumulative | true | Development |
541+
480542
### redis.tracking_total_keys
481543
482544
Number of keys being tracked by the server

receiver/redisreceiver/integration_test.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import (
1919
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
2020
)
2121

22-
const redisPort = "6379"
22+
const (
23+
redisPort = "6379"
24+
sentinelPort = "26379"
25+
)
2326

2427
func TestIntegrationV6(t *testing.T) {
2528
scraperinttest.NewIntegrationTest(
@@ -38,6 +41,8 @@ func TestIntegrationV6(t *testing.T) {
3841
scraperinttest.WithCompareOptions(
3942
pmetrictest.IgnoreMetricValues(),
4043
pmetrictest.IgnoreMetricDataPointsOrder(),
44+
pmetrictest.IgnoreMetricsOrder(),
45+
pmetrictest.IgnoreResourceMetricsOrder(),
4146
pmetrictest.IgnoreStartTimestamp(),
4247
pmetrictest.IgnoreTimestamp(),
4348
pmetrictest.ChangeResourceAttributeValue("server.address", func(_ string) string {
@@ -83,6 +88,8 @@ func TestIntegrationV7Cluster(t *testing.T) {
8388
scraperinttest.WithCompareOptions(
8489
pmetrictest.IgnoreMetricValues(),
8590
pmetrictest.IgnoreMetricDataPointsOrder(),
91+
pmetrictest.IgnoreMetricsOrder(),
92+
pmetrictest.IgnoreResourceMetricsOrder(),
8693
pmetrictest.IgnoreStartTimestamp(),
8794
pmetrictest.IgnoreTimestamp(),
8895
),
@@ -91,3 +98,48 @@ func TestIntegrationV7Cluster(t *testing.T) {
9198
scraperinttest.WithCompareTimeout(time.Minute),
9299
).Run(t)
93100
}
101+
102+
func TestIntegrationV8Sentinel(t *testing.T) {
103+
scraperinttest.NewIntegrationTest(
104+
NewFactory(),
105+
scraperinttest.WithContainerRequest(
106+
testcontainers.ContainerRequest{
107+
Image: "redis:8.2.1",
108+
ExposedPorts: []string{sentinelPort},
109+
Cmd: []string{
110+
"redis-sentinel",
111+
"/etc/redis/sentinel.conf",
112+
},
113+
Files: []testcontainers.ContainerFile{
114+
{
115+
HostFilePath: filepath.Join("testdata", "integration", "redis-sentinel.conf"),
116+
ContainerFilePath: "/etc/redis/sentinel.conf",
117+
FileMode: 0o644,
118+
},
119+
},
120+
WaitingFor: wait.ForListeningPort(sentinelPort),
121+
}),
122+
scraperinttest.WithCustomConfig(
123+
func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
124+
rCfg := cfg.(*Config)
125+
rCfg.Endpoint = fmt.Sprintf("%s:%s", ci.Host(t), ci.MappedPort(t, sentinelPort))
126+
rCfg.MetricsBuilderConfig.Metrics.RedisMode.Enabled = true
127+
rCfg.MetricsBuilderConfig.Metrics.RedisSentinelMasters.Enabled = true
128+
rCfg.MetricsBuilderConfig.Metrics.RedisSentinelRunningScripts.Enabled = true
129+
rCfg.MetricsBuilderConfig.Metrics.RedisSentinelScriptsQueueLength.Enabled = true
130+
rCfg.MetricsBuilderConfig.Metrics.RedisSentinelSimulateFailureFlags.Enabled = true
131+
rCfg.MetricsBuilderConfig.Metrics.RedisSentinelTiltSinceSeconds.Enabled = true
132+
rCfg.MetricsBuilderConfig.Metrics.RedisSentinelTotalTilt.Enabled = true
133+
}),
134+
scraperinttest.WithCompareOptions(
135+
pmetrictest.IgnoreMetricValues(),
136+
pmetrictest.IgnoreMetricDataPointsOrder(),
137+
pmetrictest.IgnoreMetricsOrder(),
138+
pmetrictest.IgnoreResourceMetricsOrder(),
139+
pmetrictest.IgnoreStartTimestamp(),
140+
pmetrictest.IgnoreTimestamp(),
141+
),
142+
scraperinttest.WithExpectedFile(filepath.Join("testdata", "integration", "expected-sentinel.yaml")),
143+
scraperinttest.WithCreateContainerTimeout(time.Minute),
144+
).Run(t)
145+
}

receiver/redisreceiver/internal/metadata/generated_config.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/redisreceiver/internal/metadata/generated_config_test.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)