Skip to main content

Crate enya_client

Crate enya_client 

Source
Expand description

Metrics client abstraction supporting multiple backends.

This crate provides a unified interface for querying metrics from different backends (Prometheus, Enya, etc.) using PromQL as the query language.

§Architecture

The MetricsClient trait defines a promise-based async interface that all backends implement. Methods return Promise objects that can be polled each frame in immediate mode GUIs like egui. HTTP requests are handled by reqwest which works on both native (with tokio) and WASM (with browser fetch).

§Example

use enya_client::{MetricsClient, QueryRequest};
use enya_client::prometheus::PrometheusClient;

// Create a client for your backend
let client = PrometheusClient::new("http://localhost:9090");

// Fire off a query - returns a promise
let request = QueryRequest::new("cpu_usage", r#"sum(cpu_usage{env="prod"}) by (host)"#);
let promise = client.query(request, &ctx);

// In your update loop, poll for results
if let Some(result) = promise.ready() {
    match result {
        Ok(response) => { /* update visualization */ }
        Err(e) => { /* show error */ }
    }
}

Re-exports§

pub use demo::DemoMetricsClient;
pub use error::ClientError;
pub use promise::promise_channel;
pub use request::QueryRequest;
pub use types::MetricsBucket;
pub use types::MetricsGroup;
pub use types::QueryResponse;
pub use types::ResultType;
pub use types::Timestamp;
pub use prometheus::response::MetricLabels;
pub use logs::DemoLogsClient;
pub use logs::LogEntry;
pub use logs::LogLevel;
pub use logs::LogsClient;
pub use logs::LogsQuery;
pub use logs::LogsResponse;
pub use logs::LogsResult;
pub use logs::LokiClient;
pub use logs::QueryDirection;
pub use logs::StreamsResult;

Modules§

demo
Demo metrics client for offline/showcase mode.
error
Error types for the metrics client.
logs
Logs client abstraction supporting multiple backends.
otlp
OpenTelemetry Protocol (OTLP) support.
prometheus
Prometheus backend implementation.
promise
Promise-based async helpers for HTTP requests.
request
Query request types.
tracing
Tracing client abstraction for distributed trace backends.
types
Shared API types for metrics query responses.

Structs§

BackendInfo
Backend health/version information from a health check.
HealthCheckManager
Manages in-flight health check requests using promises.
LabelsManager
Manages in-flight label/metadata fetches using promises.
LogsQueryManager
Manages multiple in-flight log queries in parallel using promises.
MetricLabelsManager
Manages in-flight per-metric label fetches using promises.
Promise
A promise that waits for the reception of a single value, presumably from some async task.
QueryManager
Manages multiple in-flight queries in parallel using promises.

Constants§

DEFAULT_QUERY_TIMEOUT_SECS
Default query timeout in seconds. If a query doesn’t complete within this time, it will be cancelled with a timeout error.

Traits§

MetricsClient
Metrics client trait - promise-based async interface.

Functions§

normalize_url
Normalize a base URL: ensure it has an http:// scheme and strip trailing slashes.
now_unix_secs
Get the current Unix timestamp in seconds. Works on both native and WASM platforms.
url_encode
Simple URL encoding for query parameters.

Type Aliases§

HealthCheckResult
Result type for health check operations.
LabelsResult
Result type for label list operations.
MetricLabelsResult
Result type for metric series label operations.
QueryResult
Result type for query operations.