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
  • Listing admin audit events
  • 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::ResolvedServerConfig;
pub use config::RetryConfig;
pub use config::resolve_server_config;
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.
AuditEvent
An append-only audit event for tracking mutations and admin actions.
BaselineRecord
The primary storage model for baselines.
BaselineSummary
Summary of a baseline record (without full receipt).
DecisionRecord
A stored performance decision receipt for the server-side decision ledger.
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.
ListAuditEventsQuery
Query parameters for listing audit events.
ListAuditEventsResponse
Response for audit event list operation.
ListBaselinesQuery
Request for baseline list operation.
ListBaselinesResponse
Response for baseline list operation.
ListDecisionsQuery
Query parameters for listing decision records.
ListDecisionsResponse
Response for decision 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.
PruneDecisionsRequest
Request for pruning old performance decision records.
PruneDecisionsResponse
Response for a decision prune operation.
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.
UploadDecisionRequest
Request for uploading a performance decision.
VerdictRecord
A record of a benchmark execution verdict.

Enums§

AuditAction
The action that was performed in an audit event.
AuditResourceType
The type of resource affected by an audit event.
BaselineSource
Source of baseline creation.