SLA policy tracking and status calculation
| Tier | operations |
| Role | unclassified (baselined) |
| Path | crates/operations/sla |
| Edition | 2021 |
| Targets | operations_sla |
| Public items | 52 across 5 modules |
| Tests | 25 |
What it is for
# operations-sla
SLA (Service Level Agreement) tracking library crates for Rust applications.
Overview
This crate provides:
- SLA policy definitions with configurable response/resolution times
- Status tracking (on track, at risk, breached, met)
- Breach detection and reporting
- Pluggable policy sources for multi-tenant systems
Example
use operations_sla::{
SlaPolicy, SlaInput, SlaStatus, DefaultSlaPolicySource, SlaPolicySource,
calculate_sla_status,
};
use chrono::{Utc, Duration};
use uuid::Uuid;
// Define an SLA policy
let policy = SlaPolicy::with_times(60, 480); // 1 hour response, 8 hour resolution
// Create input data
let now = Utc::now();
let input = SlaInput::new(Uuid::new_v4(), now - Duration::minutes(30));
// Calculate SLA status
let status = calculate_sla_status(&input, &policy, now);
assert_eq!(status.first_response_status, SlaStatus::OnTrack);
// Use the default policy source for priority-based policies
let source = DefaultSlaPolicySource::new();
let urgent_policy = source.get_policy(Uuid::new_v4(), None, Some("urgent"), None).unwrap();
assert_eq!(urgent_policy.first_response_minutes, 15);
Capabilities
Result
SLA error types.
| Item |
|---|
pub type Result<T>: std::result::Result <T, SlaError> |
SlaError
SLA error types.
| Item |
|---|
pub enum SlaError |
SlaError :: fn policy_not_found(name : impl Into <String>) -> Self |
SlaError :: fn invalid_priority(priority : impl Into <String>) -> Self |
EntitySlaStatus
SLA data models.
| Item |
|---|
pub struct EntitySlaStatus |
EntitySlaStatus :: fn has_problems(& self) -> bool |
EntitySlaStatus :: fn worst_status(& self) -> SlaStatus |
SlaBreach
SLA data models.
| Item |
|---|
pub struct SlaBreach |
SlaBreach :: fn new(entity_id : Uuid, breach_type : SlaBreachType, breached_at : DateTime <Utc>, exceeded_by_minutes : i64,) -> Self |
SlaBreachType
SLA data models.
| Item |
|---|
pub enum SlaBreachType |
SlaBreachType :: fn as_str(& self) -> & 'static str |
SlaBreachType :: fn parse(s : & str) -> Option <Self> |
SlaBreachType :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
SlaInput
SLA data models.
| Item |
|---|
pub struct SlaInput |
SlaInput :: fn new(entity_id : Uuid, created_at : DateTime <Utc>) -> Self |
SlaInput :: fn with_first_response(mut self, at : DateTime <Utc>) -> Self |
SlaInput :: fn with_resolved(mut self, at : DateTime <Utc>) -> Self |
SlaInput :: fn with_closed(mut self, at : DateTime <Utc>) -> Self |
SlaPolicy
SLA data models.
| Item |
|---|
pub struct SlaPolicy |
SlaPolicy :: fn default() -> Self |
SlaPolicy :: fn new(name : impl Into <String>) -> Self |
SlaPolicy :: fn with_times(first_response_minutes : i64, resolution_minutes : i64) -> Self |
SlaPolicy :: fn with_name(mut self, name : impl Into <String>) -> Self |
SlaPolicy :: fn with_at_risk_threshold(mut self, percent : u8) -> Self |
SlaPolicy :: fn with_pause_on_waiting(mut self, pause : bool) -> Self |
SlaPolicy :: fn first_response_duration(& self) -> Duration |
SlaPolicy :: fn resolution_duration(& self) -> Duration |
SlaPolicy :: fn first_response_at_risk_duration(& self) -> Duration |
SlaPolicy :: fn resolution_at_risk_duration(& self) -> Duration |
SlaStatus
SLA data models.
| Item |
|---|
pub enum SlaStatus |
SlaStatus :: fn as_str(& self) -> & 'static str |
SlaStatus :: fn parse(s : & str) -> Option <Self> |
SlaStatus :: fn is_problematic(& self) -> bool |
SlaStatus :: fn is_terminal(& self) -> bool |
SlaStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
policy (other)
SLA policy management and resolution.
| Item |
|---|
fn validate_priority(priority : & str) -> Result <()> |
DefaultSlaPolicySource
SLA policy management and resolution.
| Item |
|---|
pub struct DefaultSlaPolicySource |
DefaultSlaPolicySource :: fn new() -> Self |
DefaultSlaPolicySource :: fn with_custom_times(low_response : i64, low_resolution : i64, normal_response : i64, normal_resolution : i64, high_response : i64, high_resolution : i64, urgent_response : i64, urgent_resolution : i64,) -> Self |
DefaultSlaPolicySource :: fn policy_for_priority(& self, priority : Option <& str>) -> SlaPolicy |
DefaultSlaPolicySource :: fn default() -> Self |
DefaultSlaPolicySource :: fn get_policy(& self, _tenant_id : Uuid, _client_id : Option <Uuid>, priority : Option <& str>, _category : Option <& str>,) -> Result <SlaPolicy> |
SlaPolicySource
SLA policy management and resolution.
| Item |
|---|
pub trait SlaPolicySource |
policy::priorities (other)
_No module-level documentation is present in the source._
| Item |
|---|
pub const LOW: & str |
pub const NORMAL: & str |
pub const HIGH: & str |
pub const URGENT: & str |
pub const ALL: & & str |
tracker (other)
SLA status calculation.
| Item |
|---|
fn calculate_sla_status(input : & SlaInput, policy : & SlaPolicy, now : DateTime <Utc>,) -> EntitySlaStatus |
fn check_breaches(input : & SlaInput, policy : & SlaPolicy, now : DateTime <Utc>) -> Vec <SlaBreach> |
fn filter_at_risk(statuses : & EntitySlaStatus) -> Vec <& EntitySlaStatus> |
fn sort_by_urgency(statuses : & mut EntitySlaStatus) |
How to use it
From this crate's own rustdoc:
use operations_sla::{
SlaPolicy, SlaInput, SlaStatus, DefaultSlaPolicySource, SlaPolicySource,
calculate_sla_status,
};
use chrono::{Utc, Duration};
use uuid::Uuid;
// Define an SLA policy
let policy = SlaPolicy::with_times(60, 480); // 1 hour response, 8 hour resolution
// Create input data
let now = Utc::now();
let input = SlaInput::new(Uuid::new_v4(), now - Duration::minutes(30));
// Calculate SLA status
let status = calculate_sla_status(&input, &policy, now);
assert_eq!(status.first_response_status, SlaStatus::OnTrack);
// Use the default policy source for priority-based policies
let source = DefaultSlaPolicySource::new();
let urgent_policy = source.get_policy(Uuid::new_v4(), None, Some("urgent"), None).unwrap();
assert_eq!(urgent_policy.first_response_minutes, 15);
Module structure
operations_sla
errormodelspolicypolicy::prioritiestracker
flowchart TD n_operations_sla["operations_sla"] n_operations_sla --> n_error["error"] n_operations_sla --> n_models["models"] n_operations_sla --> n_policy["policy"] n_policy --> n_policy__priorities["priorities"] n_operations_sla --> n_tracker["tracker"]
Public surface
`error`
| Item | What it is |
|---|---|
pub enum SlaError | Errors that can occur during SLA operations. |
SlaError :: fn policy_not_found(name : impl Into <String>) -> Self | Create a policy not found error. |
SlaError :: fn invalid_priority(priority : impl Into <String>) -> Self | Create an invalid priority error. |
pub type Result<T>: std::result::Result <T, SlaError> | Result type for SLA operations. |
`models`
| Item | What it is |
|---|---|
pub enum SlaBreachType | SLA breach types. |
SlaBreachType :: fn as_str(& self) -> & 'static str | Get string representation. |
SlaBreachType :: fn parse(s : & str) -> Option <Self> | Parse from string. |
SlaBreachType :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub enum SlaStatus | SLA status for tracking. |
SlaStatus :: fn as_str(& self) -> & 'static str | Get string representation. |
SlaStatus :: fn parse(s : & str) -> Option <Self> | Parse from string. |
SlaStatus :: fn is_problematic(& self) -> bool | Check if this status indicates a problem (at risk or breached). |
SlaStatus :: fn is_terminal(& self) -> bool | Check if this is a terminal state (won't change). |
SlaStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub struct SlaPolicy | SLA policy configuration. |
SlaPolicy :: fn default() -> Self | — |
SlaPolicy :: fn new(name : impl Into <String>) -> Self | Create a new policy with the given name. |
SlaPolicy :: fn with_times(first_response_minutes : i64, resolution_minutes : i64) -> Self | Create a policy with custom response/resolution times. |
SlaPolicy :: fn with_name(mut self, name : impl Into <String>) -> Self | Set the policy name. |
SlaPolicy :: fn with_at_risk_threshold(mut self, percent : u8) -> Self | Set the at-risk threshold percentage. |
SlaPolicy :: fn with_pause_on_waiting(mut self, pause : bool) -> Self | Set whether to pause on waiting. |
SlaPolicy :: fn first_response_duration(& self) -> Duration | Get first response duration. |
SlaPolicy :: fn resolution_duration(& self) -> Duration | Get resolution duration. |
SlaPolicy :: fn first_response_at_risk_duration(& self) -> Duration | Get at-risk threshold duration for first response. |
SlaPolicy :: fn resolution_at_risk_duration(& self) -> Duration | Get at-risk threshold duration for resolution. |
pub struct SlaBreach | SLA breach record. |
SlaBreach :: fn new(entity_id : Uuid, breach_type : SlaBreachType, breached_at : DateTime <Utc>, exceeded_by_minutes : i64,) -> Self | Create a new breach record. |
pub struct EntitySlaStatus | SLA status calculation result for an entity. |
EntitySlaStatus :: fn has_problems(& self) -> bool | Check if any SLA is problematic (at risk or breached). |
EntitySlaStatus :: fn worst_status(& self) -> SlaStatus | Get the worst status between first response and resolution. |
pub struct SlaInput | Input data for SLA calculation. |
SlaInput :: fn new(entity_id : Uuid, created_at : DateTime <Utc>) -> Self | Create new SLA input. |
SlaInput :: fn with_first_response(mut self, at : DateTime <Utc>) -> Self | Set first response time. |
SlaInput :: fn with_resolved(mut self, at : DateTime <Utc>) -> Self | Set resolved time. |
SlaInput :: fn with_closed(mut self, at : DateTime <Utc>) -> Self | Set closed time. |
`policy`
| Item | What it is |
|---|---|
pub trait SlaPolicySource | Trait for resolving SLA policies |
pub struct DefaultSlaPolicySource | Default SLA policy source using configuration |
DefaultSlaPolicySource :: fn new() -> Self | Create a new default policy source with standard SLA times. |
DefaultSlaPolicySource :: fn with_custom_times(low_response : i64, low_resolution : i64, normal_response : i64, normal_resolution : i64, high_response : i64, high_resolution : i64, urgent_response : i64, urgent_resolution : i64,) -> Self | Create with custom SLA times for all priorities. |
DefaultSlaPolicySource :: fn policy_for_priority(& self, priority : Option <& str>) -> SlaPolicy | Get policy for a specific priority string. |
DefaultSlaPolicySource :: fn default() -> Self | — |
DefaultSlaPolicySource :: fn get_policy(& self, _tenant_id : Uuid, _client_id : Option <Uuid>, priority : Option <& str>, _category : Option <& str>,) -> Result <SlaPolicy> | — |
fn validate_priority(priority : & str) -> Result <()> | Validate a priority string. |
`policy::priorities`
| Item | What it is |
|---|---|
pub const LOW: & str | Low priority. |
pub const NORMAL: & str | Normal priority (default). |
pub const HIGH: & str | High priority. |
pub const URGENT: & str | Urgent priority. |
pub const ALL: & & str | All valid priority levels. |
`tracker`
| Item | What it is |
|---|---|
fn calculate_sla_status(input : & SlaInput, policy : & SlaPolicy, now : DateTime <Utc>,) -> EntitySlaStatus | Calculate SLA status for an entity |
fn check_breaches(input : & SlaInput, policy : & SlaPolicy, now : DateTime <Utc>) -> Vec <SlaBreach> | Check for SLA breaches in a single input |
fn filter_at_risk(statuses : & EntitySlaStatus) -> Vec <& EntitySlaStatus> | Filter entities that are at risk or breached. |
fn sort_by_urgency(statuses : & mut EntitySlaStatus) | Sort statuses by urgency (most urgent first) |
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
{EntitySlaStatus,SlaBreach,SlaBreachType,SlaInput,SlaPolicy,SlaStatus} | models::{EntitySlaStatus,SlaBreach,SlaBreachType,SlaInput,SlaPolicy,SlaStatus} |
{Result,SlaError} | error::{Result,SlaError} |
{calculate_sla_status,check_breaches,filter_at_risk,sort_by_urgency} | tracker::{calculate_sla_status,check_breaches,filter_at_risk,sort_by_urgency} |
{priorities,validate_priority,DefaultSlaPolicySource,SlaPolicySource} | policy::{priorities,validate_priority,DefaultSlaPolicySource,SlaPolicySource} |
Boundary
Depends on no other workspace tier.
Shares tier operations with 40 other crates: operations-approval-workflow, operations-assessments, operations-block-imaging, operations-boot-media, operations-browser-agent-worker, operations-camera-discovery, operations-camera-liveview, operations-camera-registry, … (40 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | operations |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/operations/sla |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
serde | ^1.0 | derive | no | always |
serde_json | ^1.0 | — | no | always |
thiserror | ^2.0 | — | no | always |
uuid | ^1.0 | v4, serde | no | always |
Development. None.
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_sla["application-sla"] -->|uses| SELF SELF["operations-sla"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | operations_sla | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
SlaError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: application-sla.
Verification
| Kind | Count |
|---|---|
| Unit tests | 25 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 1 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
error | 2 | 0 | 1 |
models | 6 | 0 | 0 |
policy | 3 | 0 | 1 |
policy::priorities | 5 | 0 | 0 |
tracker | 4 | 0 | 1 |
What the tests establish, by name:
test_sla_breach_type_display—src/models.rstest_sla_breach_type_parse—src/models.rstest_sla_policy_default—src/models.rstest_sla_policy_durations—src/models.rstest_sla_policy_with_times—src/models.rstest_sla_status_display—src/models.rstest_sla_status_is_problematic—src/models.rstest_sla_status_parse—src/models.rstest_default_policy_for_unknown_priority—src/policy.rstest_default_policy_selection—src/policy.rstest_validate_priority—src/policy.rstest_check_breaches_both—src/tracker.rstest_check_breaches_first_response—src/tracker.rstest_check_breaches_none—src/tracker.rstest_first_response_closed_after_deadline_is_breached—src/tracker.rstest_first_response_closed_before_deadline_is_met—src/tracker.rstest_first_response_resolved_after_deadline_is_breached—src/tracker.rstest_first_response_resolved_before_deadline_is_met—src/tracker.rstest_first_response_unresolved_still_uses_deadline—src/tracker.rstest_sla_status_at_risk—src/tracker.rstest_sla_status_breached—src/tracker.rstest_sla_status_met—src/tracker.rstest_sla_status_met_but_breached—src/tracker.rstest_sla_status_on_track—src/tracker.rstest_sort_by_urgency—src/tracker.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 47 | 52 |
Public modules with a //! block | 4 | 5 |
pie showData
title Public items with rustdoc
"Documented" : 47
"No rustdoc detected" : 5
Metrics
| Metric | Value |
|---|---|
| Rust source files | 5 |
| Source lines | 1114 |
| Code lines | 775 |
| Public API items | 52 |
| Public modules | 5 |
| Tests | 25 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 5 |
| Workspace reverse dependencies | 1 |
pie showData
title Public API by kind
"constant" : 5
"enum" : 3
"function" : 5
"method" : 32
"struct" : 5
"trait" : 1
"type alias" : 1
pie showData
title Rust source composition
"Code" : 775
"Blank or comment" : 339
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.