Expand description
Client library for the perfgate baseline service.
This crate provides a client for interacting with the perfgate baseline service API, including:
- Uploading and downloading baselines
- Listing baselines with filtering
- Promoting and deleting baselines
- Health checking
- Automatic fallback to local storage when the server is unavailable
Part of the perfgate workspace.
§Quick Start
use perfgate_client::{BaselineClient, ClientConfig, ListBaselinesQuery};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client
let config = ClientConfig::new("https://perfgate.example.com/api/v1")
.with_api_key("your-api-key");
let client = BaselineClient::new(config)?;
// Check server health
let health = client.health_check().await?;
println!("Server status: {}", health.status);
// List baselines
let query = ListBaselinesQuery::new().with_limit(10);
let response = client.list_baselines("my-project", &query).await?;
for baseline in &response.baselines {
println!("{}: {}", baseline.benchmark, baseline.version);
}
Ok(())
}§Fallback Storage
When the server is unavailable, the client can fall back to local file storage:
use perfgate_client::{BaselineClient, ClientConfig, FallbackClient, FallbackStorage};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::new("https://perfgate.example.com/api/v1")
.with_api_key("your-api-key")
.with_fallback(FallbackStorage::local("./baselines"));
let client = BaselineClient::new(config)?;
let fallback_client = FallbackClient::new(
client,
Some(FallbackStorage::local("./baselines")),
);
// This will fall back to local storage if the server is unavailable
let baseline = fallback_client
.get_latest_baseline("my-project", "my-bench")
.await?;
Ok(())
}§Error Handling
The client provides detailed error types for different failure scenarios:
use perfgate_client::{BaselineClient, ClientConfig, ClientError};
#[tokio::main]
async fn main() {
let config = ClientConfig::new("https://perfgate.example.com/api/v1");
let client = BaselineClient::new(config).unwrap();
match client.get_latest_baseline("my-project", "my-bench").await {
Ok(baseline) => println!("Got baseline: {}", baseline.id),
Err(ClientError::NotFoundError(msg)) => {
eprintln!("Baseline not found: {}", msg);
}
Err(ClientError::AuthError(msg)) => {
eprintln!("Authentication failed: {}", msg);
}
Err(ClientError::ConnectionError(msg)) => {
eprintln!("Server unavailable: {}", msg);
}
Err(e) => eprintln!("Error: {}", e),
}
}Re-exports§
pub use client::BaselineClient;pub use config::AuthMethod;pub use config::ClientConfig;pub use config::FallbackStorage;pub use config::RetryConfig;pub use error::ClientError;pub use fallback::FallbackClient;
Modules§
- client
- Client for the perfgate baseline service.
- config
- Client configuration types.
- error
- Error types for the perfgate client.
- fallback
- Fallback storage implementation.
- types
- Request and response types for the baseline service API.
Structs§
- Affected
Project - A project affected by a fleet-wide dependency regression.
- Baseline
Record - The primary storage model for baselines.
- Baseline
Summary - Summary of a baseline record (without full receipt).
- Delete
Baseline Response - Response for baseline deletion.
- Dependency
Change - A single dependency version change observed alongside a benchmark run.
- Dependency
Event - A recorded dependency change event with its performance impact.
- Dependency
Impact Query - Query parameters for dependency impact lookup.
- Dependency
Impact Response - Response for dependency impact lookup.
- Fleet
Alert - A fleet-wide alert: multiple projects regressed after the same dependency update.
- Health
Response - Response for health check.
- List
Baselines Query - Request for baseline list operation.
- List
Baselines Response - Response for baseline list operation.
- List
Fleet Alerts Query - Query parameters for listing fleet alerts.
- List
Fleet Alerts Response - Response for listing fleet alerts.
- List
Verdicts Query - Request for verdict list operation.
- List
Verdicts Response - Response for verdict list operation.
- Pagination
Info - Pagination information for lists.
- Promote
Baseline Request - Request for baseline promotion.
- Promote
Baseline Response - Response for baseline promotion.
- Record
Dependency Event Request - Request to record a dependency change event.
- Record
Dependency Event Response - Response after recording dependency events.
- Storage
Health - Health status of a storage backend.
- Submit
Verdict Request - Request for submitting a verdict.
- Upload
Baseline Request - Request for baseline upload.
- Upload
Baseline Response - Response for successful baseline upload.
- Verdict
Record - A record of a benchmark execution verdict.
Enums§
- Baseline
Source - Source of baseline creation.