Add Metrics API: declare/list params and metrics, query bucket values (ticket 004)
Exposes param/metric declarations and derived bucket data over HTTP: POST /api/params and POST /api/metrics validate and declare against the engine, persisting into the active profile (if any) so declarations survive a restart; GET /api/metrics lists declarations; GET /api/metrics/:name queries bucket values with label, time-range, sequence, and limit filters. Adds a new EngineQuery::BucketValues variant that layers this filtering on top of ticket 003's bucket_values helper. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XFUNZwCvz3kcod3352ZR2o
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
f0348589f5
commit
49e8590cf3
+36
@@ -1,6 +1,8 @@
|
||||
use crate::data_value::{MetricPrimitiveKind, RegexToMetricPrimitiveMatcher};
|
||||
use crate::metric_primitive::MetricPrimitive;
|
||||
use crate::settings::CssEntry;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct LogEntryDto {
|
||||
@@ -54,6 +56,40 @@ pub struct TimelineParams {
|
||||
pub bucket_ms: Option<i64>,
|
||||
}
|
||||
|
||||
/// One entry from a metric's derived bucket timeseries: the label combination
|
||||
/// that bucket represents, plus one `(sequence, timestamp, value)` occurrence
|
||||
/// within it.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct BucketValueDto {
|
||||
pub labels: BTreeMap<String, MetricPrimitive>,
|
||||
pub sequence: u64,
|
||||
pub timestamp_ms: i64,
|
||||
pub value: MetricPrimitive,
|
||||
}
|
||||
|
||||
/// Query params for `GET /api/metrics/:name`. `labels` is a single
|
||||
/// comma-separated `key=value` list (e.g. `?labels=path=/a,duration=5`)
|
||||
/// rather than repeated `label.foo=bar` params, since axum's `Query`
|
||||
/// extractor needs a fixed/known set of field names — an arbitrary label set
|
||||
/// doesn't fit that without a custom deserializer. Every listed label must
|
||||
/// match (compared against each label value's `Display` form, see
|
||||
/// `MetricPrimitive`); unlisted labels on a bucket are ignored.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct BucketValuesParams {
|
||||
pub labels: Option<String>,
|
||||
pub since_sequence: Option<u64>,
|
||||
pub start_ms: Option<i64>,
|
||||
pub end_ms: Option<i64>,
|
||||
pub limit: Option<usize>,
|
||||
}
|
||||
|
||||
/// JSON error body returned by API handlers on a 4xx/5xx response, e.g.
|
||||
/// `{ "error": "invalid regex: ..." }`.
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ErrorDto {
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
/// Request body for `POST /api/settings/css`: raw CSS content to import and
|
||||
/// store alongside the settings file.
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user