perfgate_client/lib.rs
1//! Client library for the perfgate baseline service.
2//!
3//! This crate provides a client for interacting with the perfgate baseline
4//! service API, including:
5//!
6//! - Uploading and downloading baselines
7//! - Listing baselines with filtering
8//! - Promoting and deleting baselines
9//! - Listing admin audit events
10//! - Health checking
11//! - Automatic fallback to local storage when the server is unavailable
12//!
13//! Part of the [perfgate](https://github.com/EffortlessMetrics/perfgate) workspace.
14//!
15//! ## Quick Start
16//!
17//! ```rust,no_run
18//! use perfgate_client::{BaselineClient, ClientConfig, ListBaselinesQuery};
19//!
20//! #[tokio::main]
21//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
22//! // Create a client
23//! let config = ClientConfig::new("https://perfgate.example.com/api/v1")
24//! .with_api_key("your-api-key");
25//!
26//! let client = BaselineClient::new(config)?;
27//!
28//! // Check server health
29//! let health = client.health_check().await?;
30//! println!("Server status: {}", health.status);
31//!
32//! // List baselines
33//! let query = ListBaselinesQuery::new().with_limit(10);
34//! let response = client.list_baselines("my-project", &query).await?;
35//!
36//! for baseline in &response.baselines {
37//! println!("{}: {}", baseline.benchmark, baseline.version);
38//! }
39//!
40//! Ok(())
41//! }
42//! ```
43//!
44//! ## Fallback Storage
45//!
46//! When the server is unavailable, the client can fall back to local file storage:
47//!
48//! ```rust,no_run
49//! use perfgate_client::{BaselineClient, ClientConfig, FallbackClient, FallbackStorage};
50//!
51//! #[tokio::main]
52//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
53//! let config = ClientConfig::new("https://perfgate.example.com/api/v1")
54//! .with_api_key("your-api-key")
55//! .with_fallback(FallbackStorage::local("./baselines"));
56//!
57//! let client = BaselineClient::new(config)?;
58//! let fallback_client = FallbackClient::new(
59//! client,
60//! Some(FallbackStorage::local("./baselines")),
61//! );
62//!
63//! // This will fall back to local storage if the server is unavailable
64//! let baseline = fallback_client
65//! .get_latest_baseline("my-project", "my-bench")
66//! .await?;
67//!
68//! Ok(())
69//! }
70//! ```
71//!
72//! ## Error Handling
73//!
74//! The client provides detailed error types for different failure scenarios:
75//!
76//! ```rust,no_run
77//! use perfgate_client::{BaselineClient, ClientConfig, ClientError};
78//!
79//! #[tokio::main]
80//! async fn main() {
81//! let config = ClientConfig::new("https://perfgate.example.com/api/v1");
82//! let client = BaselineClient::new(config).unwrap();
83//!
84//! match client.get_latest_baseline("my-project", "my-bench").await {
85//! Ok(baseline) => println!("Got baseline: {}", baseline.id),
86//! Err(ClientError::NotFoundError(msg)) => {
87//! eprintln!("Baseline not found: {}", msg);
88//! }
89//! Err(ClientError::AuthError(msg)) => {
90//! eprintln!("Authentication failed: {}", msg);
91//! }
92//! Err(ClientError::ConnectionError(msg)) => {
93//! eprintln!("Server unavailable: {}", msg);
94//! }
95//! Err(e) => eprintln!("Error: {}", e),
96//! }
97//! }
98//! ```
99
100pub mod client;
101pub mod config;
102pub mod error;
103pub mod fallback;
104pub mod types;
105
106// Re-export main types at the crate root for convenience
107pub use client::BaselineClient;
108pub use config::{
109 AuthMethod, ClientConfig, FallbackStorage, ResolvedServerConfig, RetryConfig,
110 resolve_server_config,
111};
112pub use error::ClientError;
113pub use fallback::FallbackClient;
114pub use types::{
115 AffectedProject, AuditAction, AuditEvent, AuditResourceType, BaselineRecord, BaselineSource,
116 BaselineSummary, DecisionRecord, DeleteBaselineResponse, DependencyChange, DependencyEvent,
117 DependencyImpactQuery, DependencyImpactResponse, FleetAlert, HealthResponse,
118 ListAuditEventsQuery, ListAuditEventsResponse, ListBaselinesQuery, ListBaselinesResponse,
119 ListDecisionsQuery, ListDecisionsResponse, ListFleetAlertsQuery, ListFleetAlertsResponse,
120 ListVerdictsQuery, ListVerdictsResponse, PaginationInfo, PromoteBaselineRequest,
121 PromoteBaselineResponse, PruneDecisionsRequest, PruneDecisionsResponse,
122 RecordDependencyEventRequest, RecordDependencyEventResponse, StorageHealth,
123 SubmitVerdictRequest, UploadBaselineRequest, UploadBaselineResponse, UploadDecisionRequest,
124 VerdictRecord,
125};
126
127#[cfg(test)]
128mod tests {
129 use super::*;
130
131 #[test]
132 fn test_reexports() {
133 // Ensure all re-exports are accessible
134 let _config = ClientConfig::new("https://example.com");
135 let _query = ListBaselinesQuery::new();
136 }
137}