Repository navigation
feat(metrics): Export worker, background-work, and transaction-age gauges - #5401
colinbarry wants to merge 15 commits into
Conversation
memgraph_workers and memgraph_workers_busy report the size of the query worker pool and how many workers are running a query. A query blocked on a lock still holds its worker, so a busy pool with low throughput points to waiting rather than load.
memgraph_worker_queue_length reports the query tasks waiting for a free worker. A queue that stays above zero means the worker pool is the limit.
memgraph_snapshot_running_seconds and memgraph_gc_running_seconds report, per database, how long the running snapshot or GC run has taken so far, and 0 when none is running. The duration histograms record only when the work finishes, so a long snapshot was invisible while it ran.
memgraph_longest_transaction_seconds reports, per database, how long the oldest open transaction has been open, so a transaction that holds up others or blocks garbage collection is visible. process_start_time_seconds is the standard Prometheus start time, for uptime and restart detection.
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
|
A failing snapshot was invisible until a restart recovered from an old one. Each database now exports memgraph_last_snapshot_timestamp_seconds, the last time it was confirmed snapshot-current (a snapshot written, or nothing new to write), and memgraph_snapshot_failures_total by reason: no_space or write_error. A requested abort is not counted as a failure.
|
This PR has potential conflicts with the following other open pull requests which modify the same files:
|
…tart A scrape can see a snapshot or GC run as running before its start time is stored, and reported the steady clock's whole age as the run's duration. Report the run only once its start time is set.
The snapshot written on the switch from analytical to transactional mode bypassed the snapshot metrics, so its success did not update the last snapshot time and its failure was not counted. Both snapshot paths now share the same recording.
A dropped database's sessions keep running while they drain, and a new database can take its name meanwhile. Keying the longest transaction age by name gave the new database the dropped one's transaction ages. Key it by uuid, which the metrics entries already track.
|
Release note advisory Release note: The note contains multiple sentences; the release note must be a single short sentence ending with a period immediately followed by the PR link. Please condense into one sentence. |
The queue also holds parallel query subtasks, and a task can wait in one worker's queue while another worker is idle.
Bound the last snapshot timestamp from above, give the per-database transaction age test an age for another database incarnation, and drive the longest transaction gauge end to end with an open transaction.
… in SHOW METRICS INFO Every metric must be readable through Cypher. Add the snapshot failure counters, the worker pool gauges, and the process start time to SHOW METRICS INFO. The worker pool rows are read when the query runs, and are absent when there is no priority worker pool, as on the metrics endpoint. The deprecated JSON endpoint is unchanged.
…oint The JSON endpoint appends every global SHOW METRICS INFO row, so adding the process start time and worker pool gauges there exposed them on the deprecated endpoint too. Report them from their own function, which only SHOW METRICS INFO calls.
There was a problem hiding this comment.
Automated review by the Memgraph review service
Verdict: APPROVE WITH NITS
Findings: 0 blocker, 6 non-blocking, 0 nit (6 inline) · 1 pre-existing · 2 nits (collapsed)
Pre-existing, not introduced by this PR (1)
-
src/utils/priority_thread_pool.cpp:137-155[Non-blocking]
GetNumQueuedTaskshas a bounded undercount window; test races with the monitor interval(pop/repush),
166–170(GetNumQueuedTasks) ⚠ citation suspect: report citestests/unit/utils_priority_thread_pool.cpp:923— file is 589 lines; actual assertion is at line 287.
Nits (2)
-
tests/unit/prometheus_metrics.cpp:139-158[Nit] Test uses identical nil UUIDs for two separate databases, making the per-database isolation check vacuous
-
src/storage/v2/inmemory/storage.cpp:98-107[Nit] Missing coverage: no test for failure classification logic
tests/unit/prometheus_metrics.cpp+src/storage/v2/inmemory/storage.cpp:98–107
| &snapshot_progress_, | ||
| "storage_mode_change"); |
There was a problem hiding this comment.
[Non-blocking] memgraph_snapshot_running_seconds reads 0 during storage-mode-change snapshots
| // Populate GlobalMetricHandles — only session, memory, and HA metrics | ||
| prometheus::Labels const no_labels{}; | ||
|
|
There was a problem hiding this comment.
[Non-blocking] process_start_time_seconds is captured at lazy metrics-singleton construction, not at process start
singleton at 2707–2710
| void RecordSnapshotFailure(metrics::DatabaseMetricHandles const &handles, durability::SnapshotCreationError const error, | ||
| std::atomic_bool const &abort_requested) { | ||
| if (error == durability::SnapshotCreationError::kNoSpaceLeft) { | ||
| handles.snapshot_failures_no_space.Increment(); | ||
| } else if (!abort_requested.load(std::memory_order_acquire)) { | ||
| handles.snapshot_failures_write_error.Increment(); | ||
| } | ||
| } | ||
|
|
||
| constexpr auto ActionToStorageOperation(MetadataDelta::Action const action) -> durability::StorageMetadataOperation { |
There was a problem hiding this comment.
[Non-blocking] Snapshot-failure classification can lose a write_error count when shutdown races with a write failure
| @@ -4692,8 +4710,10 @@ std::expected<std::filesystem::path, InMemoryStorage::CreateSnapshotError> InMem | |||
| .storage_uuid_ = storage_uuid, | |||
There was a problem hiding this comment.
[Non-blocking] memgraph_snapshot_failures_total omits broken-storage snapshot refusals
Cited lines 4638-4642 are outside this PR's changes; this comment is on the nearest changed line.
| return results; | ||
| } | ||
|
|
||
| std::map<utils::UUID, double> InterpreterContext::LongestTransactionSeconds( |
There was a problem hiding this comment.
[Non-blocking] (performance hazard) Scrape-frequency longest-transaction walk contends with commits/aborts and holds a spinlock during db_acc_mutex_ acquisition
Cited lines 334-350.
| .db_embedding_memory_tracked = db.DbEmbeddingMemoryUsage(), | ||
| .db_query_memory_tracked = db.DbQueryMemoryUsage()}; | ||
| if (auto const *mem = dynamic_cast<storage::InMemoryStorage const *>(db.storage())) { | ||
| if (auto const progress = mem->TryGetSnapshotProgress(); progress && progress->start_steady_ms > 0) { | ||
| snapshot.snapshot_running_seconds = SecondsSince(progress->start_steady_ms); | ||
| } |
There was a problem hiding this comment.
[Non-blocking] (observability gap) Non-InMemoryStorage databases report constant 0 for snapshot/GC metrics
The pool's monitor can hold a task outside every queue while it moves it off a stuck worker, so a single read right after queuing could undercount.
|



Throughput drops with idle CPU were hard to diagnose from the metrics: nothing showed whether queries were queueing for a worker, whether a snapshot or garbage collection was running at that moment, whether one long transaction was holding others up, or whether snapshots had stopped succeeding.
This adds the following metrics. The snapshot ones are updated when a snapshot ends; the rest are read at scrape time, and cost the query path nothing beyond a brief per-session check during a scrape:
memgraph_workers--bolt-num-workers)memgraph_workers_busymemgraph_worker_queue_lengthmemgraph_snapshot_running_secondsdatabase,uuidmemgraph_gc_running_secondsdatabase,uuidmemgraph_longest_transaction_secondsdatabase,uuidmemgraph_last_snapshot_timestamp_secondsdatabase,uuidmemgraph_snapshot_failures_totaldatabase,uuid,reasonno_spaceorwrite_error. A requested abort is not a failureprocess_start_time_secondsThe worker gauges are absent when Memgraph runs without the priority worker pool. The longest-transaction gauge reads sessions the same way
SHOW TRANSACTIONSdoes.SHOW METRICS INFOaddsWorkers,WorkersBusy,WorkerQueueLength,ProcessStartTime,SnapshotFailuresNoSpace, andSnapshotFailuresWriteError. The running times and the longest transaction are already inSHOW TRANSACTIONS, and the last snapshot inSHOW SNAPSHOTS.