pub struct MetricsQuery { /* private fields */ }Expand description
Builder for constructing queries against a metrics repository.
MetricsQuery provides a fluent API for filtering metrics by various criteria
including time ranges, tags, and analyzer types. Queries are constructed
incrementally and executed asynchronously.
§Example
use term_guard::repository::MetricsQuery;
let results = repository.load().await
.after(start_timestamp)
.before(end_timestamp)
.with_tag("environment", "production")
.for_analyzers(vec!["completeness", "size"])
.execute()
.await?;
for (key, context) in results {
println!("Metrics at {}: {:?}", key.timestamp, context.all_metrics());
}Implementations§
Source§impl MetricsQuery
impl MetricsQuery
Sourcepub fn new(repository: Arc<dyn MetricsRepository>) -> Self
pub fn new(repository: Arc<dyn MetricsRepository>) -> Self
Creates a new query for the given repository.
§Arguments
repository- The repository to query against
Sourcepub fn for_analyzers<I, S>(self, analyzers: I) -> Self
pub fn for_analyzers<I, S>(self, analyzers: I) -> Self
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates query parameters for correctness.
§Returns
Returns an error if the query parameters are invalid.
Sourcepub async fn execute(self) -> Result<Vec<(ResultKey, AnalyzerContext)>>
pub async fn execute(self) -> Result<Vec<(ResultKey, AnalyzerContext)>>
Executes the query and returns the results.
§Returns
A vector of (ResultKey, AnalyzerContext) pairs matching the query criteria, sorted by timestamp according to the specified sort order.
§Errors
Returns an error if the query execution fails (e.g., I/O error, invalid query).
§Example
let results = repository.load().await
.after(start_time)
.with_tag("environment", "production")
.execute()
.await?;
for (key, context) in results {
println!("Timestamp: {}", key.timestamp);
println!("Metrics: {:?}", context.all_metrics());
}Sourcepub async fn count(self) -> Result<usize>
pub async fn count(self) -> Result<usize>
Returns a count of metrics matching the query criteria without loading them.
This is more efficient than executing the query and counting results when only the count is needed.
§Errors
Returns an error if the count operation fails.
Sourcepub fn get_before(&self) -> Option<i64>
pub fn get_before(&self) -> Option<i64>
Accessor methods for DataFusion integration
pub fn get_after(&self) -> Option<i64>
pub fn get_analyzers(&self) -> &Option<Vec<String>>
pub fn get_limit(&self) -> Option<usize>
pub fn get_offset(&self) -> Option<usize>
pub fn get_sort_order(&self) -> SortOrder
pub fn is_ascending(&self) -> bool
Auto Trait Implementations§
impl Freeze for MetricsQuery
impl !RefUnwindSafe for MetricsQuery
impl Send for MetricsQuery
impl Sync for MetricsQuery
impl Unpin for MetricsQuery
impl !UnwindSafe for MetricsQuery
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more