Skip to content

feat: add support for RDB current file size metric#1095

Open
akshaykumar-vijapur wants to merge 7 commits intooliver006:masterfrom
akshaykumar-vijapur:aks/addrdbsize
Open

feat: add support for RDB current file size metric#1095
akshaykumar-vijapur wants to merge 7 commits intooliver006:masterfrom
akshaykumar-vijapur:aks/addrdbsize

Conversation

@akshaykumar-vijapur
Copy link
Copy Markdown

Test result

# HELP redis_rdb_current_size_bytes Current RDB file size in bytes
# TYPE redis_rdb_current_size_bytes gauge
redis_rdb_current_size_bytes 188

All RDB-related Metrics

curl -s http://localhost:9122/metrics | grep -A 1 "redis_rdb"

Output:

# HELP redis_rdb_bgsave_in_progress rdb_bgsave_in_progress metric
# TYPE redis_rdb_bgsave_in_progress gauge
redis_rdb_bgsave_in_progress 0

# HELP redis_rdb_changes_since_last_save rdb_changes_since_last_save metric
# TYPE redis_rdb_changes_since_last_save gauge
redis_rdb_changes_since_last_save 0

# HELP redis_rdb_current_bgsave_duration_sec rdb_current_bgsave_duration_sec metric
# TYPE redis_rdb_current_bgsave_duration_sec gauge
redis_rdb_current_bgsave_duration_sec -1

# HELP redis_rdb_current_size_bytes Current RDB file size in bytes
# TYPE redis_rdb_current_size_bytes gauge
redis_rdb_current_size_bytes 188

# HELP redis_rdb_last_bgsave_duration_sec rdb_last_bgsave_duration_sec metric
# TYPE redis_rdb_last_bgsave_duration_sec gauge
redis_rdb_last_bgsave_duration_sec 0

# HELP redis_rdb_last_bgsave_status rdb_last_bgsave_status metric
# TYPE redis_rdb_last_bgsave_status gauge
redis_rdb_last_bgsave_status 1

# HELP redis_rdb_last_cow_size_bytes rdb_last_cow_size_bytes metric
# TYPE redis_rdb_last_cow_size_bytes gauge
redis_rdb_last_cow_size_bytes 385024

closes #1093

Copy link
Copy Markdown
Owner

@oliver006 oliver006 left a comment

Choose a reason for hiding this comment

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

This is great, thanks for opening this PR!

I'll give it a more thorough review later.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 75.47170% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.75%. Comparing base (d7bb38f) to head (5b57f63).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
exporter/rdb.go 75.55% 9 Missing and 2 partials ⚠️
main.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1095      +/-   ##
==========================================
- Coverage   81.88%   81.75%   -0.14%     
==========================================
  Files          20       21       +1     
  Lines        2700     2752      +52     
==========================================
+ Hits         2211     2250      +39     
- Misses        370      381      +11     
- Partials      119      121       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Owner

@oliver006 oliver006 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR - this feature is useful.
I left a bunch of comments that need addressing before we can move forward here.

// Made with Bob

It's ok to submit PRs with AI-generated code, I use AI myself all the time.

But I'd still expect a higher bar for code quality and expect you to review your own code before submitting the PR.
And/or use a better AI model.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 2, 2026

Coverage Report for CI Build 23999617636

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.09%) to 85.577%

Details

  • Coverage decreased (-0.09%) from the base build.
  • Patch coverage: 12 uncovered changes across 2 files (52 of 64 lines covered, 81.25%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
exporter/rdb.go 55 45 81.82%
main.go 2 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3321
Covered Lines: 2842
Line Coverage: 85.58%
Coverage Strength: 13887.6 hits per line

💛 - Coveralls

@akshaykumar-vijapur
Copy link
Copy Markdown
Author

@oliver006 Pls review and check.

@akshaykumar-vijapur
Copy link
Copy Markdown
Author

@oliver006 Pls check as we need this metrics in our env

akshaykumar-vijapur and others added 2 commits March 30, 2026 11:24
- Fix TestExtractRdbFileSizeMetricConfigDisabled to use e.Collect(ch) pattern
- Refactor extractRdbFileSizeMetric to accept config array instead of redis.Conn
  - Eliminates redundant CONFIG GET call by reusing already-extracted config
  - Parses config array to extract 'dir' and 'dbfilename' values
- Move rdb_current_size_bytes metric description between number_of_distinct_key_groups and script_result
- Update TestExtractRdbFileSizeMetric to use e.Collect(ch) pattern

Addresses review feedback from oliver006
@akshaykumar-vijapur
Copy link
Copy Markdown
Author

@oliver006 pls review

@akshaykumar-vijapur
Copy link
Copy Markdown
Author

@oliver006 pls review

@akshaykumar-vijapur
Copy link
Copy Markdown
Author

##  End-to-End Test (Inside Container)

### Setup:
```bash
# Start Redis container with exposed ports
docker run -d --name redis-e2e-final -p 6381:6379 -p 9125:9125 redis:latest

# Create test data and RDB file
docker exec redis-e2e-final redis-cli SET key1 "value1"
docker exec redis-e2e-final redis-cli SET key2 "value2"
docker exec redis-e2e-final redis-cli BGSAVE
sleep 2

Output:

OK
OK
Background saving started

Verify RDB File:

docker exec redis-e2e-final ls -lh /data/dump.rdb

Output:

-rw-------. 1 redis redis 119 Apr  5 10:30 /data/dump.rdb

RDB File Size: 119 bytes

Deploy Exporter Inside Container:

# Copy linux binary to container
docker cp ./redis_exporter_linux redis-e2e-final:/usr/local/bin/redis_exporter
docker exec redis-e2e-final chmod +x /usr/local/bin/redis_exporter

# Start exporter with RDB metric enabled
docker exec -d redis-e2e-final /usr/local/bin/redis_exporter \
  --redis.addr=redis://localhost:6379 \
  --include-rdb-file-size-metric \
  --web.listen-address=:9125 \
  --log-format=txt

sleep 5

Fetch Metrics:

curl -s http://localhost:9125/metrics | grep -B1 -A1 "rdb_current_size_bytes"

Output:

redis_rdb_current_bgsave_duration_sec -1
# HELP redis_rdb_current_size_bytes Current RDB file size in bytes
# TYPE redis_rdb_current_size_bytes gauge
redis_rdb_current_size_bytes 119
# HELP redis_rdb_last_bgsave_duration_sec rdb_last_bgsave_duration_sec metric

Verification:

docker exec redis-e2e-final stat -c %s /data/dump.rdb

Output:

Expected file size: 119
Metric value:       119 bytes

Result: Metric accurately reports RDB file size

}
}

if e.options.ConfigCommandName != "-" && e.options.InclRdbFileSizeMetric && len(config) > 0 {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

remove the extra len(config) > 0 check here - extractRdbFileSizeMetric() handles that

}

dbCount := 0
var config []interface{}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

instead of the extra variable, call extractRdbFileSizeMetric() right up here, after line 839

log "github.com/sirupsen/logrus"
)

func (e *Exporter) extractRdbFileSizeMetric(ch chan<- prometheus.Metric, config []interface{}) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I just simplified the config extraction anfd it's using a ma[string]string now which should make this code a lot simpler

#1109

for instance,m you don't need to iterate over the config map any longer but can simply look up filename and directory.

Please rebase and then use the config map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for RDB current file size metric (valkey_rdb_current_size_bytes)

4 participants