endpoints comments
test-org/prometheus-exporter/pipeline/pr-rc This commit looks good Details

feature/1126
prplV 2025-03-07 10:53:20 +03:00
parent 1bf6595bbc
commit 83516e5fbc
1 changed files with 27 additions and 0 deletions

View File

@ -10,6 +10,17 @@ use crate::AppState;
use tracing::{ error, info, warn };
use crate::metrics::{MetricsProcesser, MetricsValueType};
/// An `Update` endpoint
///
/// Used to registrate new metrics and to update already
/// existing in local metrics `Registry`
///
/// # Usage
///
/// ``` bash
/// curl -X POST -d '"id" : ...' 'http::/localhost:9100/update'
/// ```
///
pub async fn update_metrics(
State(state): State<Arc<AppState>>,
Json(request) : Json<PrometheusMetrics<'_>>
@ -59,6 +70,17 @@ pub async fn update_metrics(
(http::StatusCode::ACCEPTED, "Ok")
}
/// An `Metrics` endpoint
///
/// Needed in sharing current local metrics `Registry` state
/// and all stored metrics
///
/// # Usage
///
/// ``` bash
/// curl -X GET 'http::/localhost:9100/metrics'
/// ```
///
pub async fn metrics_handler(State(state): State<Arc<AppState>>) -> String {
let registry = state.registry.lock();
@ -76,6 +98,11 @@ pub async fn metrics_handler(State(state): State<Arc<AppState>>) -> String {
}
}
/// A function-registrator
///
/// Registrates or updates metrics state in local
/// `Registry`
///
pub fn update_or_insert_metric<'a>(
metric: Gauge,
registry: MutexGuard<'a, Registry>,