feat(obs): add bounded metrics dimensions (#5645)

* feat(obs): add drive topology detail metrics

Expose additive drive info, topology, state, and per-drive API metrics while preserving the existing drive metric label sets.

Backlog: rustfs/backlog#1655

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(obs): preserve suspect drive runtime state

Keep suspect as a bounded drive runtime state and avoid all-zero runtime_state samples for that storage health state.

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(obs): skip unknown drive inode samples

Avoid exporting zero inode gauges for missing or stale drive snapshots and ignore zero-count API latency buckets.

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): add scanner source work detail metrics

Expose additive scanner source and cycle work metrics with bounded server/source/state labels while leaving the existing aggregate scanner metrics unchanged.

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): add ilm action detail metrics

Expose additive ILM action/state task metrics with a server label while preserving the existing aggregate ILM series.

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): add delivery target server metrics

Expose additive audit and notification delivery target metrics with server labels and extend removed-target tombstones for the server-aware series.

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): add replication target flow metrics

Expose additive bucket replication target sent and failed-flow metrics while preserving existing bucket aggregates and target backlog series.

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): add request server metrics

Expose additive API request metrics with server labels while preserving the existing request and traffic metric label sets.

Co-Authored-By: heihutu <heihutu@gmail.com>

* style(obs): apply rustfmt to metrics changes

Apply rustfmt output to the metrics dimension changes without altering behavior.

Co-Authored-By: heihutu <heihutu@gmail.com>

* style(obs): reuse audit target label constant

Use the exported audit target_id label constant for legacy audit target metrics.

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): populate drive disk metrics

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): add scanner bucket drive result metrics

Co-Authored-By: heihutu <heihutu@gmail.com>

* feat(obs): add replication proxy server metrics

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(obs): address metric liveness review

Use checked division for drive API latency aggregation and keep recovered drive, scanner current-cycle, replication flow, audit target, and notification target series from retaining stale values.

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(obs): address metric dimension review

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(obs): address additional metric review

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(obs): count drive calls at start

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(obs): address metrics dimension review

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(metrics): address dimension review gaps

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(metrics): address scanner review follow-ups

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(metrics): address runtime review follow-ups

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(metrics): reduce disk metric contention

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(metrics): address runtime review follow-ups

Co-Authored-By: heihutu <heihutu@gmail.com>

* fix(metrics): retire stale dimension series

Co-Authored-By: heihutu <heihutu@gmail.com>

---------

Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
houseme
2026-08-03 09:03:34 +08:00
committed by GitHub
parent 988cd8adbb
commit 035ce5d784
36 changed files with 6282 additions and 666 deletions
+88 -2
View File
@@ -14,7 +14,8 @@
use std::{collections::HashMap, time::SystemTime};
use serde::{Deserialize, Serialize};
use serde::ser::SerializeStruct;
use serde::{Deserialize, Serialize, Serializer};
use time::OffsetDateTime;
use crate::metrics::TimedAction;
@@ -61,17 +62,41 @@ impl ItemState {
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq)]
pub struct DiskMetrics {
#[serde(rename = "lastMinute", alias = "last_minute")]
pub last_minute: HashMap<String, TimedAction>,
#[serde(rename = "apiCalls", alias = "api_calls")]
pub api_calls: HashMap<String, u64>,
#[serde(rename = "totalWaiting", alias = "total_waiting")]
pub total_waiting: u32,
#[serde(rename = "totalErrsAvailability", alias = "total_errors_availability")]
pub total_errors_availability: u64,
#[serde(rename = "totalErrsTimeout", alias = "total_errors_timeout")]
pub total_errors_timeout: u64,
#[serde(rename = "totalWrites", alias = "total_writes")]
pub total_writes: u64,
#[serde(rename = "totalDeletes", alias = "total_deletes")]
pub total_deletes: u64,
}
impl Serialize for DiskMetrics {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("DiskMetrics", 7)?;
state.serialize_field("last_minute", &self.last_minute)?;
state.serialize_field("api_calls", &self.api_calls)?;
state.serialize_field("total_waiting", &self.total_waiting)?;
state.serialize_field("total_errors_availability", &self.total_errors_availability)?;
state.serialize_field("total_errors_timeout", &self.total_errors_timeout)?;
state.serialize_field("total_writes", &self.total_writes)?;
state.serialize_field("total_deletes", &self.total_deletes)?;
state.end()
}
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct Disk {
pub endpoint: String,
@@ -432,6 +457,17 @@ mod tests {
disk_index: i32,
}
#[derive(Deserialize)]
struct LegacyDiskMetricsCompat {
last_minute: HashMap<String, TimedAction>,
api_calls: HashMap<String, u64>,
total_waiting: u32,
total_errors_availability: u64,
total_errors_timeout: u64,
total_writes: u64,
total_deletes: u64,
}
#[test]
fn test_item_state_to_string() {
assert_eq!(ItemState::Offline.to_string(), ITEM_OFFLINE);
@@ -495,6 +531,56 @@ mod tests {
assert_eq!(metrics.total_deletes, 50);
}
#[test]
fn test_disk_metrics_json_preserves_internode_legacy_fields() {
let metrics = DiskMetrics {
total_waiting: 5,
total_errors_availability: 2,
total_errors_timeout: 1,
total_writes: 1000,
total_deletes: 50,
..Default::default()
};
let json = serde_json::to_value(metrics).expect("disk metrics should serialize");
assert!(json.get("last_minute").is_some());
assert!(json.get("api_calls").is_some());
assert_eq!(json["total_waiting"], serde_json::json!(5));
assert_eq!(json["total_errors_availability"], serde_json::json!(2));
assert_eq!(json["total_errors_timeout"], serde_json::json!(1));
assert_eq!(json["total_writes"], serde_json::json!(1000));
assert_eq!(json["total_deletes"], serde_json::json!(50));
assert!(json.get("lastMinute").is_none());
assert!(json.get("totalErrsTimeout").is_none());
}
#[test]
fn test_disk_metrics_msgpack_uses_internode_legacy_fields() {
let metrics = DiskMetrics {
total_waiting: 5,
total_errors_availability: 2,
total_errors_timeout: 1,
total_writes: 1000,
total_deletes: 50,
..Default::default()
};
let mut encoded = Vec::new();
metrics
.serialize(&mut Serializer::new(&mut encoded).with_struct_map())
.expect("disk metrics should encode as named msgpack");
let decoded: LegacyDiskMetricsCompat = rmp_serde::from_slice(&encoded).expect("legacy disk metrics should decode");
assert!(decoded.last_minute.is_empty());
assert!(decoded.api_calls.is_empty());
assert_eq!(decoded.total_waiting, 5);
assert_eq!(decoded.total_errors_availability, 2);
assert_eq!(decoded.total_errors_timeout, 1);
assert_eq!(decoded.total_writes, 1000);
assert_eq!(decoded.total_deletes, 50);
}
#[test]
fn test_disk_default() {
let disk = Disk::default();