Skip to content

Commit ded39ce

Browse files
committed
feat: add replication info to /metrics endpoint
Exposes 4 new fields to the `/metrics` endpoint relating to replication info: - `master_link_status` - `master_last_io_seconds_ago` - `master_sync_in_progress` - `slave_repl_offset` This commit also adds integration testing to validate the new functionality. Fixes #6183 Signed-off-by: Eric <hayter.eric@gmail.com>
1 parent 5db9666 commit ded39ce

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/server/server_family.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,24 @@ void PrintPrometheusMetrics(uint64_t uptime, const Metrics& m, DflyCmd* dfly_cmd
21272127
&resp->body());
21282128
}
21292129

2130+
// Replication Info
2131+
if (m.replica_side_info) {
2132+
const ReplicaSummary& rsummary = m.replica_side_info->summary;
2133+
AppendMetricWithoutLabels("master_link_status", "1 if up 0 if down",
2134+
rsummary.master_link_established ? 1 : 0, MetricType::GAUGE,
2135+
&resp->body());
2136+
AppendMetricWithoutLabels("master_last_io_seconds_ago", "Last Master IO Seconds Ago",
2137+
rsummary.master_last_io_sec, MetricType::GAUGE, &resp->body());
2138+
AppendMetricWithoutLabels("master_sync_in_progress", "1 if true 0 if false",
2139+
rsummary.full_sync_in_progress ? 1 : 0, MetricType::GAUGE,
2140+
&resp->body());
2141+
// Print last known offset either during stable sync (online) or during disconnects when
2142+
// the full sync phase did not start yet.
2143+
if (rsummary.full_sync_done || (rsummary.passed_full_sync && !rsummary.master_link_established))
2144+
AppendMetricWithoutLabels("slave_repl_offset", "Slave Replication Offset",
2145+
rsummary.repl_offset_sum, MetricType::GAUGE, &resp->body());
2146+
}
2147+
21302148
// Stream access pattern metrics
21312149
if (m.shard_stats.stream_sequential_accesses || m.shard_stats.stream_random_accesses ||
21322150
m.shard_stats.stream_fetch_all_accesses) {

tests/dragonfly/replication_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,18 @@ async def test_replication_info(df_factory: DflyInstanceFactory, df_seeder_facto
11471147
await wait_available_async(c_replica)
11481148
await assert_lag_condition(master, c_master, lambda lag: lag == 0)
11491149

1150+
# Replica should expose replication metrics
1151+
replica_metrics = await replica.metrics()
1152+
assert replica_metrics["dragonfly_master_link_status"].samples[0].value == 1
1153+
assert replica_metrics["dragonfly_master_sync_in_progress"].samples[0].value == 0
1154+
assert replica_metrics["dragonfly_master_last_io_seconds_ago"].samples[0].value >= 0
1155+
assert "dragonfly_slave_repl_offset" in replica_metrics
1156+
1157+
# Master should not expose replica-side metrics
1158+
master_metrics = await master.metrics()
1159+
assert "dragonfly_master_link_status" not in master_metrics
1160+
assert "dragonfly_slave_repl_offset" not in master_metrics
1161+
11501162
await c_master.connection_pool.disconnect()
11511163
await c_replica.connection_pool.disconnect()
11521164

0 commit comments

Comments
 (0)