Repository navigation
feat(metrics): Export replica state, replication lag, and role gauges - #5024
colinbarry wants to merge 11 commits into
Conversation
Tracking
Standard development
CI Testing Labels
Kubernetes operator / Helm chartsDoes this change affect how Memgraph is deployed or configured on Kubernetes? It likely does if it adds, removes or renames a flag; changes run-time or startup settings; touches the license, AWS settings, coordinators, replication, TLS, monitoring or another enterprise feature.
Documentation checklist
|
1a204e5 to
1387087
Compare
|
This PR has potential conflicts with the following other open pull requests which modify the same files:
|
|
Dashboards had no way to see whether a replica is healthy or how far it lags, or which role an instance holds, without running Cypher queries. Data instances now export memgraph_replica_state and memgraph_replica_txns_behind for each replica and database, plus memgraph_replication_role, memgraph_main_writeable, and memgraph_registered_replicas. The values are read from the instance's own replication state at scrape time, so they work without HA and never block a scrape.
The killed replica stayed out of the cleanup fixture's reach, so its data directory survived and a rerun started it with the replica role already set, failing setup.
The replica gauges used a replica label, while the HA instance gauges and the replication throughput histograms use mg_instance for the same names. Use mg_instance, so dashboards can join replica and cluster views.
12eeca1 to
0a94622
Compare
An ASYNC replica catches up in periodic recovery rounds, so it is normally reported behind between rounds. Without the mode, dashboards could not tell that from a SYNC replica that has fallen behind. memgraph_replica_state and memgraph_replica_txns_behind now carry a mode label with the values SHOW REPLICAS uses.
The replica gauges' mode label had tests for sync and async replicas only. A STRICT_SYNC replica, registered alongside an ASYNC one as clusters allow, is now checked to report mode="strict_sync".
|
Release note advisory Release note: The content is informative and the PR link matches, but it contains multiple sentences and is longer than the required single short sentence; please condense into one sentence followed immediately by the PR link in the specified format. |
The scrape read each replica's state with a blocking spin lock, which a commit holds across its replication RPC, so a scrape could wait out an RPC timeout while holding the replication state read lock. The scrape now tries that lock and drops the whole snapshot when it is busy, leaving the gauges at their previous values. A new replica's gauges are also built before they enter the map, so a failed Add can't leave a null entry behind.
SHOW REPLICAS spelled out each replication mode name by hand, duplicating the names the metrics use. It now takes them from ReplicationModeName.
…TION ROLE memgraph_main_writeable had no Cypher view, and its name hid that it reflects only replication, not licence or storage limits. The gauge is now memgraph_accepts_writes, and SHOW REPLICATION ROLE gains a writeable column with the same value: false on a replica, and on a main whether it accepts writes. Tests that read SHOW REPLICATION ROLE rows now expect the second column.
|







Dashboards had no way to see whether a replica is healthy, how far it lags, or which role an instance holds, without running Cypher queries such as
SHOW REPLICAS.Data instances now export these gauges:
memgraph_replica_statemg_instance,database,mode,stateSHOW REPLICASnames:ready,replicating,recovery,invalid,divergedmemgraph_replica_transactions_behindmg_instance,database,modememgraph_replication_rolerolemainorreplica)memgraph_accepts_writesmemgraph_registered_replicasThe values are read from the instance's own replication state at scrape time, so they work without HA. A scrape never waits on a lock: if the replication state or a replica's state is busy, it keeps the previous values.
modeis the replica's replication mode (sync,async, orstrict_sync). An ASYNC replica catches up in periodic recovery rounds and normally showsinvalidbetween them, so dashboards need the mode to tell that apart from a SYNC replica falling behind. The lag calculation is now shared withSHOW REPLICATION LAG, and the state and mode names withSHOW REPLICAS.SHOW REPLICATION ROLEgains a second column,writeable, with the same value asmemgraph_accepts_writes: false on a replica, and on a main whether it accepts writes (always true outside HA).