Skip to main content

Crate perfgate_client

Crate perfgate_client 

Source
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§

AffectedProject
A project affected by a fleet-wide dependency regression.
BaselineRecord
The primary storage model for baselines.
BaselineSummary
Summary of a baseline record (without full receipt).
DeleteBaselineResponse
Response for baseline deletion.
DependencyChange
A single dependency version change observed alongside a benchmark run.
DependencyEvent
A recorded dependency change event with its performance impact.
DependencyImpactQuery
Query parameters for dependency impact lookup.
DependencyImpactResponse
Response for dependency impact lookup.
FleetAlert
A fleet-wide alert: multiple projects regressed after the same dependency update.
HealthResponse
Response for health check.
ListBaselinesQuery
Request for baseline list operation.
ListBaselinesResponse
Response for baseline list operation.
ListFleetAlertsQuery
Query parameters for listing fleet alerts.
ListFleetAlertsResponse
Response for listing fleet alerts.
ListVerdictsQuery
Request for verdict list operation.
ListVerdictsResponse
Response for verdict list operation.
PaginationInfo
Pagination information for lists.
PromoteBaselineRequest
Request for baseline promotion.
PromoteBaselineResponse
Response for baseline promotion.
RecordDependencyEventRequest
Request to record a dependency change event.
RecordDependencyEventResponse
Response after recording dependency events.
StorageHealth
Health status of a storage backend.
SubmitVerdictRequest
Request for submitting a verdict.
UploadBaselineRequest
Request for baseline upload.
UploadBaselineResponse
Response for successful baseline upload.
VerdictRecord
A record of a benchmark execution verdict.

Enums§

BaselineSource
Source of baseline creation.