operations capa

operations-sla

SLA policy tracking and status calculation

SLA policy tracking and status calculation

Tieroperations
Roleunclassified (baselined)
Pathcrates/operations/sla
Edition2021
Targetsoperations_sla
Public items52 across 5 modules
Tests25

What it is for

# operations-sla

SLA (Service Level Agreement) tracking library crates for Rust applications.

Overview

This crate provides:

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

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`

ItemWhat it is
pub enum SlaErrorErrors that can occur during SLA operations.
SlaError :: fn policy_not_found(name : impl Into <String>) -> SelfCreate a policy not found error.
SlaError :: fn invalid_priority(priority : impl Into <String>) -> SelfCreate an invalid priority error.
pub type Result<T>: std::result::Result <T, SlaError>Result type for SLA operations.

`models`

ItemWhat it is
pub enum SlaBreachTypeSLA breach types.
SlaBreachType :: fn as_str(& self) -> & 'static strGet 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 SlaStatusSLA status for tracking.
SlaStatus :: fn as_str(& self) -> & 'static strGet string representation.
SlaStatus :: fn parse(s : & str) -> Option <Self>Parse from string.
SlaStatus :: fn is_problematic(& self) -> boolCheck if this status indicates a problem (at risk or breached).
SlaStatus :: fn is_terminal(& self) -> boolCheck if this is a terminal state (won't change).
SlaStatus :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
pub struct SlaPolicySLA policy configuration.
SlaPolicy :: fn default() -> Self
SlaPolicy :: fn new(name : impl Into <String>) -> SelfCreate a new policy with the given name.
SlaPolicy :: fn with_times(first_response_minutes : i64, resolution_minutes : i64) -> SelfCreate a policy with custom response/resolution times.
SlaPolicy :: fn with_name(mut self, name : impl Into <String>) -> SelfSet the policy name.
SlaPolicy :: fn with_at_risk_threshold(mut self, percent : u8) -> SelfSet the at-risk threshold percentage.
SlaPolicy :: fn with_pause_on_waiting(mut self, pause : bool) -> SelfSet whether to pause on waiting.
SlaPolicy :: fn first_response_duration(& self) -> DurationGet first response duration.
SlaPolicy :: fn resolution_duration(& self) -> DurationGet resolution duration.
SlaPolicy :: fn first_response_at_risk_duration(& self) -> DurationGet at-risk threshold duration for first response.
SlaPolicy :: fn resolution_at_risk_duration(& self) -> DurationGet at-risk threshold duration for resolution.
pub struct SlaBreachSLA breach record.
SlaBreach :: fn new(entity_id : Uuid, breach_type : SlaBreachType, breached_at : DateTime <Utc>, exceeded_by_minutes : i64,) -> SelfCreate a new breach record.
pub struct EntitySlaStatusSLA status calculation result for an entity.
EntitySlaStatus :: fn has_problems(& self) -> boolCheck if any SLA is problematic (at risk or breached).
EntitySlaStatus :: fn worst_status(& self) -> SlaStatusGet the worst status between first response and resolution.
pub struct SlaInputInput data for SLA calculation.
SlaInput :: fn new(entity_id : Uuid, created_at : DateTime <Utc>) -> SelfCreate new SLA input.
SlaInput :: fn with_first_response(mut self, at : DateTime <Utc>) -> SelfSet first response time.
SlaInput :: fn with_resolved(mut self, at : DateTime <Utc>) -> SelfSet resolved time.
SlaInput :: fn with_closed(mut self, at : DateTime <Utc>) -> SelfSet closed time.

`policy`

ItemWhat it is
pub trait SlaPolicySourceTrait for resolving SLA policies
pub struct DefaultSlaPolicySourceDefault SLA policy source using configuration
DefaultSlaPolicySource :: fn new() -> SelfCreate 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,) -> SelfCreate with custom SLA times for all priorities.
DefaultSlaPolicySource :: fn policy_for_priority(& self, priority : Option <& str>) -> SlaPolicyGet 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`

ItemWhat it is
pub const LOW: & strLow priority.
pub const NORMAL: & strNormal priority (default).
pub const HIGH: & strHigh priority.
pub const URGENT: & strUrgent priority.
pub const ALL: & & strAll valid priority levels.

`tracker`

ItemWhat it is
fn calculate_sla_status(input : & SlaInput, policy : & SlaPolicy, now : DateTime <Utc>,) -> EntitySlaStatusCalculate 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.

ExportDefined 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)
Locationcrates/operations/sla
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
chrono^0.4serdenoalways
serde^1.0derivenoalways
serde_json^1.0noalways
thiserror^2.0noalways
uuid^1.0v4, serdenoalways

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

KindNameSource
liboperations_sla`src/lib.rs`

Error model

Error typeNamed by
SlaErrorResult

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone 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.

1 workspace crate depends on this one: application-sla.

Verification

KindCount
Unit tests25
Integration tests0
Examples0
Doctests1

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
error201
models600
policy301
policy::priorities500
tracker401

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc4752
Public modules with a //! block45
pie showData
    title Public items with rustdoc
    "Documented" : 47
    "No rustdoc detected" : 5

Metrics

MetricValue
Rust source files5
Source lines1114
Code lines775
Public API items52
Public modules5
Tests25
Examples0
Cargo features0
Direct runtime dependencies5
Workspace reverse dependencies1
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.

Todas las operations · Manual