mon: Never decrease op counters on OSD restart or master change #190

Open
koolkhel wants to merge 2 commits from koolkhel/vitastor:mon-monotonic-stats into master
Contributor

Description

vitastor_stat_* and vitastor_image_stat_* are exported as Prometheus counters, but the monitor computed them as sums of absolute OSD counters, so they went down:

  • when an OSD is down (it is left out of the sum) or restarts (its counters start from zero);
  • after a monitor master change: the new master publishes no total op stats on its first update and then a partial sum until every OSD has reported twice.

rate()/increase() take every such drop for a counter reset and count the whole accumulated value as growth. A graph then shows a false spike for about the length of the rate window: thousands of ops per second on an idle cluster after one OSD restart, or several times the real load after a master change.

The monitor now sums the growth of OSD counters instead (the whole current value when a counter went down, i.e. the OSD restarted), starting from the totals saved in /stats and /inode/stats, so a new master continues the series. Rates (iops/bps/lat) are not changed.

  1. Total op counters (/stats, vitastor_stat_*).
  2. Per-inode counters (/inode/stats, vitastor_image_stat_*). A separate commit, so it can be taken or left on its own.

Trade-off: operations done between the old master's last update and the new master's first look at each OSD are not counted, so a graph shows a slightly low point around a master change instead of a spike.

Found: commit 1 was seen in a run on a test cluster: rate() of the total op counter spiked after every monitor master change and after an OSD restart (on an idle cluster, one OSD restart took the total primary_write count from 488061 down to 303334). Commit 2 was found by reading the code only: the per-inode counters are summed the same way; the new unit test shows them going down when an OSD goes down, but it was not seen on a cluster.

Tested: node mon/test-stats.js (new): OSD down, OSD restart, master change. On master it fails at the OSD down step (the total and the per-inode counters drop by that OSD's value); with only commit 1, the per-inode check fails at the same step; with both commits it passes. eslint is clean.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description `vitastor_stat_*` and `vitastor_image_stat_*` are exported as Prometheus counters, but the monitor computed them as sums of absolute OSD counters, so they went down: - when an OSD is down (it is left out of the sum) or restarts (its counters start from zero); - after a monitor master change: the new master publishes no total op stats on its first update and then a partial sum until every OSD has reported twice. `rate()`/`increase()` take every such drop for a counter reset and count the whole accumulated value as growth. A graph then shows a false spike for about the length of the rate window: thousands of ops per second on an idle cluster after one OSD restart, or several times the real load after a master change. The monitor now sums the growth of OSD counters instead (the whole current value when a counter went down, i.e. the OSD restarted), starting from the totals saved in `/stats` and `/inode/stats`, so a new master continues the series. Rates (`iops`/`bps`/`lat`) are not changed. 1. Total op counters (`/stats`, `vitastor_stat_*`). 2. Per-inode counters (`/inode/stats`, `vitastor_image_stat_*`). A separate commit, so it can be taken or left on its own. Trade-off: operations done between the old master's last update and the new master's first look at each OSD are not counted, so a graph shows a slightly low point around a master change instead of a spike. Found: commit 1 was seen in a run on a test cluster: `rate()` of the total op counter spiked after every monitor master change and after an OSD restart (on an idle cluster, one OSD restart took the total primary_write count from 488061 down to 303334). Commit 2 was found by reading the code only: the per-inode counters are summed the same way; the new unit test shows them going down when an OSD goes down, but it was not seen on a cluster. Tested: `node mon/test-stats.js` (new): OSD down, OSD restart, master change. On master it fails at the OSD down step (the total and the per-inode counters drop by that OSD's value); with only commit 1, the per-inode check fails at the same step; with both commits it passes. eslint is clean. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 2 commits 2026-11-25 20:24:09 +03:00
vitastor_stat_count/usec/bytes are exported as Prometheus counters, but
they were a sum of absolute OSD counters. The sum went down when an OSD
was down or restarted (its counters start from zero), and a new monitor
master published an empty and then a partial sum until every OSD had
reported twice. rate() takes every such drop for a counter reset and
shows a spike of the whole accumulated value.

Sum the growth of OSD counters instead, starting from the totals saved
in /stats, so that a new master continues them. Operations done between
the old master's last update and the new master's first look at an OSD
are not counted.
vitastor_image_stat_count/usec/bytes were a sum of absolute OSD inode
counters over up OSDs, so they went down when an OSD was down or
restarted, and rate() showed a false spike on image and pool graphs.

Sum the growth of OSD inode counters instead, like the total op
counters, starting from /inode/stats saved by the previous master.
Forget the totals of an inode together with its stats when it is
deleted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u mon-monotonic-stats:koolkhel-mon-monotonic-stats
git checkout koolkhel-mon-monotonic-stats
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#190
No description provided.