mon: Never decrease op counters on OSD restart or master change #190
@@ -758,7 +758,7 @@ class Mon
|
||||
{
|
||||
const txn = [];
|
||||
const { object_counts, object_bytes, backfillfull_pools, backfillfull_osds } = sum_object_counts(this.state, this.config);
|
||||
let stats = sum_op_stats(this.state.osd, this.prev_stats);
|
||||
let stats = sum_op_stats(this.state.osd, this.prev_stats, this.state.stats);
|
||||
let { inode_stats, seen_pools } = sum_inode_stats(this.state, this.prev_stats);
|
||||
stats.object_counts = object_counts;
|
||||
stats.object_bytes = object_bytes;
|
||||
|
||||
105
mon/stats.js
105
mon/stats.js
@@ -61,12 +61,50 @@ function derive_osd_stats(st, prev, prev_diff)
|
||||
return diff;
|
||||
}
|
||||
|
||||
// sum_op_stats(this.state.osd, this.prev_stats)
|
||||
function sum_op_stats(all_osd, prev_stats)
|
||||
const counter_keys = { op_stats: [ 'count', 'usec', 'bytes' ], subop_stats: [ 'count', 'usec' ], recovery_stats: [ 'count', 'bytes' ] };
|
||||
|
||||
// Add the growth of an OSD counter since <prev> to <total>
|
||||
function add_growth(total, cur, prev, keys)
|
||||
{
|
||||
for (const k of keys)
|
||||
{
|
||||
const c = BigInt(cur[k]||0), p = BigInt(prev && prev[k]||0);
|
||||
// A counter that went down means that the OSD restarted
|
||||
total[k] = (total[k]||0n) + (c >= p ? c-p : c);
|
||||
}
|
||||
}
|
||||
|
||||
// sum_op_stats(this.state.osd, this.prev_stats, this.state.stats)
|
||||
function sum_op_stats(all_osd, prev_stats, saved_stats)
|
||||
{
|
||||
// Total counters are exported as Prometheus counters, so they must never go down.
|
||||
// OSD counters reset on restart, down OSDs and OSDs not yet seen by a new master
|
||||
// are missing, so sum the growth of OSD counters starting from the saved totals
|
||||
if (!prev_stats.totals)
|
||||
{
|
||||
prev_stats.totals = {};
|
||||
for (const type in counter_keys)
|
||||
{
|
||||
prev_stats.totals[type] = {};
|
||||
for (const op in (saved_stats||{})[type]||{})
|
||||
{
|
||||
prev_stats.totals[type][op] = {};
|
||||
add_growth(prev_stats.totals[type][op], saved_stats[type][op], null, counter_keys[type]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const osd in all_osd.stats)
|
||||
{
|
||||
const cur = { ...all_osd.stats[osd], inode_stats: all_osd.inodestats[osd]||{} };
|
||||
const prev = prev_stats.osd_stats[osd];
|
||||
for (const type in counter_keys)
|
||||
{
|
||||
for (const op in prev && cur[type] || {})
|
||||
{
|
||||
prev_stats.totals[type][op] = prev_stats.totals[type][op] || {};
|
||||
add_growth(prev_stats.totals[type][op], cur[type][op], prev[type] && prev[type][op], counter_keys[type]);
|
||||
}
|
||||
}
|
||||
prev_stats.osd_diff[osd] = derive_osd_stats(
|
||||
cur, prev_stats.osd_stats[osd], prev_stats.osd_diff[osd]
|
||||
);
|
||||
@@ -107,6 +145,13 @@ function sum_op_stats(all_osd, prev_stats)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const type in prev_stats.totals)
|
||||
{
|
||||
for (const op in prev_stats.totals[type])
|
||||
{
|
||||
sum_diff[type][op] = { ...sum_diff[type][op], ...prev_stats.totals[type][op] };
|
||||
}
|
||||
}
|
||||
return sum_diff;
|
||||
}
|
||||
|
||||
@@ -246,28 +291,57 @@ function sum_inode_stats(state, prev_stats)
|
||||
const used = state.pool.stats[pool_id].used_raw_tb;
|
||||
state.pool.stats[pool_id].used_raw_tb = Number(used)/1024/1024/1024/1024;
|
||||
}
|
||||
for (const osd_num in state.osd.state)
|
||||
// Per-inode counters must never go down too, see sum_op_stats()
|
||||
if (!prev_stats.inode_totals)
|
||||
{
|
||||
const ist = state.osd.inodestats[osd_num];
|
||||
if (!ist || !state.osd.state[osd_num])
|
||||
prev_stats.inode_totals = {};
|
||||
prev_stats.osd_inodestats = {};
|
||||
for (const pool_id in state.inode.stats)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (const pool_id in ist)
|
||||
{
|
||||
inode_stats[pool_id] = inode_stats[pool_id] || {};
|
||||
for (const inode_num in ist[pool_id])
|
||||
prev_stats.inode_totals[pool_id] = {};
|
||||
for (const inode_num in state.inode.stats[pool_id])
|
||||
{
|
||||
inode_stats[pool_id][inode_num] = inode_stats[pool_id][inode_num] || inode_stub();
|
||||
const t = prev_stats.inode_totals[pool_id][inode_num] = {};
|
||||
for (const op of [ 'read', 'write', 'delete' ])
|
||||
{
|
||||
inode_stats[pool_id][inode_num][op].count += BigInt(ist[pool_id][inode_num][op].count||0);
|
||||
inode_stats[pool_id][inode_num][op].usec += BigInt(ist[pool_id][inode_num][op].usec||0);
|
||||
inode_stats[pool_id][inode_num][op].bytes += BigInt(ist[pool_id][inode_num][op].bytes||0);
|
||||
t[op] = {};
|
||||
add_growth(t[op], state.inode.stats[pool_id][inode_num][op]||{}, null, counter_keys.op_stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const osd_num in state.osd.inodestats)
|
||||
{
|
||||
const ist = state.osd.inodestats[osd_num]||{};
|
||||
const prev = prev_stats.osd_inodestats[osd_num];
|
||||
prev_stats.osd_inodestats[osd_num] = ist;
|
||||
for (const pool_id in prev && ist || {})
|
||||
{
|
||||
prev_stats.inode_totals[pool_id] = prev_stats.inode_totals[pool_id] || {};
|
||||
for (const inode_num in ist[pool_id])
|
||||
{
|
||||
const t = prev_stats.inode_totals[pool_id][inode_num] =
|
||||
prev_stats.inode_totals[pool_id][inode_num] || { read: {}, write: {}, delete: {} };
|
||||
const pr = prev[pool_id] && prev[pool_id][inode_num];
|
||||
for (const op of [ 'read', 'write', 'delete' ])
|
||||
{
|
||||
add_growth(t[op], ist[pool_id][inode_num][op]||{}, pr && pr[op], counter_keys.op_stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const pool_id in prev_stats.inode_totals)
|
||||
{
|
||||
inode_stats[pool_id] = inode_stats[pool_id] || {};
|
||||
for (const inode_num in prev_stats.inode_totals[pool_id])
|
||||
{
|
||||
inode_stats[pool_id][inode_num] = inode_stats[pool_id][inode_num] || inode_stub();
|
||||
for (const op of [ 'read', 'write', 'delete' ])
|
||||
{
|
||||
Object.assign(inode_stats[pool_id][inode_num][op], prev_stats.inode_totals[pool_id][inode_num][op]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const osd in state.osd.state)
|
||||
{
|
||||
const osd_diff = prev_stats.osd_diff[osd];
|
||||
@@ -312,6 +386,7 @@ function sum_inode_stats(state, prev_stats)
|
||||
{
|
||||
// Deleted inode (no data, no I/O, no config)
|
||||
delete inode_stats[pool_id][inode_num];
|
||||
delete (prev_stats.inode_totals[pool_id]||{})[inode_num];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
54
mon/test-stats.js
Normal file
54
mon/test-stats.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) Vitaliy Filippov, 2019+
|
||||
// License: VNPL-1.1 (see README.md for details)
|
||||
|
||||
// Total and per-inode op counters must never go down: on OSD down, OSD restart and monitor master change
|
||||
// Run: node test-stats.js
|
||||
|
||||
const assert = require('assert');
|
||||
const { sum_op_stats, sum_inode_stats, serialize_bigints } = require('./stats.js');
|
||||
|
||||
const state = {
|
||||
config: { pools: { 1: {} }, inode: { 1: { 5: {} } } },
|
||||
osd: { state: { 1: { state: 'up' }, 2: { state: 'up' } }, stats: {}, inodestats: {}, space: {} },
|
||||
pool: { stats: {} },
|
||||
inode: { stats: {} },
|
||||
stats: {},
|
||||
};
|
||||
let prev_stats = { osd_stats: {}, osd_diff: {} };
|
||||
|
||||
let last = [ 0n, 0n, 0n, 0n, 0n, 0n ];
|
||||
|
||||
function step(time, counts, growth)
|
||||
{
|
||||
for (const osd in counts)
|
||||
{
|
||||
const c = { count: counts[osd], usec: counts[osd]*10, bytes: counts[osd]*4096 };
|
||||
state.osd.stats[osd] = { time, op_stats: { primary_write: c } };
|
||||
state.osd.inodestats[osd] = { 1: { 5: { read: c, write: c, delete: c } } };
|
||||
}
|
||||
// Round-trip through JSON like /stats and /inode/stats in etcd
|
||||
const json = (o) => JSON.parse(JSON.stringify(serialize_bigints(o)));
|
||||
state.stats = json(sum_op_stats(state.osd, prev_stats, state.stats));
|
||||
state.inode.stats = json(sum_inode_stats(state, prev_stats).inode_stats);
|
||||
const st = state.stats.op_stats.primary_write || {};
|
||||
const ist = state.inode.stats[1] && state.inode.stats[1][5] && state.inode.stats[1][5].write || {};
|
||||
const cur = [ st.count, st.usec, st.bytes, ist.count, ist.usec, ist.bytes ].map(v => BigInt(v||0));
|
||||
if (growth !== null)
|
||||
{
|
||||
const g = [ growth, growth*10, growth*4096 ].map(BigInt);
|
||||
assert.deepStrictEqual(cur.map((c, i) => c-last[i]), [ ...g, ...g ]);
|
||||
}
|
||||
last = cur;
|
||||
}
|
||||
|
||||
step(1, { 1: 1000, 2: 2000 }, null); // OSDs are seen for the first time
|
||||
step(2, { 1: 1100, 2: 2100 }, null);
|
||||
delete state.osd.state[2]; // OSD 2 is down, its last stats stay in etcd
|
||||
step(3, { 1: 1200 }, 100);
|
||||
state.osd.state[2] = { state: 'up' }; // OSD 2 restarted, its counters start from zero
|
||||
step(4, { 1: 1300, 2: 50 }, 150);
|
||||
prev_stats = { osd_stats: {}, osd_diff: {} }; // Another monitor becomes the master
|
||||
step(4, {}, 0);
|
||||
step(5, { 1: 1400, 2: 150 }, 200);
|
||||
|
||||
console.log('OK');
|
||||
Reference in New Issue
Block a user