Skip to main content

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