feldera-types 0.383.0

Public API types for Feldera
Documentation
//! Types for the query parameters of the pipeline endpoints.

use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToSchema};

use crate::runtime_status::RuntimeDesiredStatus;

/// Circuit metrics output format.
/// - `prometheus`: [format](https://github.com/prometheus/docs/blob/4b1b80f5f660a2f8dc25a54f52a65a502f31879a/docs/instrumenting/exposition_formats.md) expected by Prometheus
/// - `json`: JSON format
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum MetricsFormat {
    Prometheus,
    Json,
}

/// Returns default metrics format.
fn default_metrics_format() -> MetricsFormat {
    MetricsFormat::Prometheus
}

/// Query parameters to retrieve pipeline circuit metrics.
#[derive(Debug, Deserialize, IntoParams, ToSchema)]
pub struct MetricsParameters {
    #[serde(default = "default_metrics_format")]
    pub format: MetricsFormat,
}

#[derive(Debug, Deserialize, IntoParams, ToSchema)]
#[serde(default)]
pub struct ActivateParams {
    #[serde(with = "crate::runtime_status::snake_case_runtime_desired_status")]
    pub initial: RuntimeDesiredStatus,
}

impl Default for ActivateParams {
    fn default() -> Self {
        Self {
            initial: RuntimeDesiredStatus::Running,
        }
    }
}

#[derive(Debug, Deserialize, Serialize, IntoParams, ToSchema)]
#[serde(default)]
pub struct SamplyProfileParams {
    /// In a multihost pipeline, the ordinal of the pipeline to sample.
    pub ordinal: usize,
    /// The number of seconds to sample for the profile, from 1 to 300.
    pub duration_secs: u64,
}

impl SamplyProfileParams {
    /// The longest profile a caller can request, in seconds.
    pub const MAX_DURATION_SECS: u64 = 300;
}

/// Default query parameters for POST of a pipeline samply profile.
impl Default for SamplyProfileParams {
    fn default() -> Self {
        Self {
            ordinal: 0,
            duration_secs: 30,
        }
    }
}

/// Query parameters to retrieve samply profile.
#[derive(Debug, Default, Deserialize, Serialize, IntoParams, ToSchema)]
#[into_params(parameter_in = Query)]
#[serde(default)]
pub struct SamplyProfileGetParams {
    /// In a multihost pipeline, the ordinal of the pipeline to sample.
    pub ordinal: usize,
    /// If true, returns 204 redirect with Retry-After header if profile collection is in progress.
    /// If false or not provided, returns the last collected profile.
    pub latest: bool,
}

/// Query parameters to the `/commit_transaction` endpoint.
#[derive(Debug, Default, Deserialize, Serialize, IntoParams, ToSchema)]
#[into_params(parameter_in = Query)]
#[serde(default)]
pub struct CommitTransactionParams {
    /// The ID of the transaction to commit, which `/start_transaction`
    /// returned:
    ///
    /// - If this is the transaction that the API started and that is still
    ///   open, the request commits it.
    /// - If this is the last transaction that `/commit_transaction`
    ///   committed, the request succeeds and does nothing, so it is safe to
    ///   retry.
    /// - Otherwise, the request fails with 409 Conflict, for example if no
    ///   transaction with this ID has started yet.
    ///
    /// Without this parameter, the request commits the transaction that the
    /// API started.
    #[param(value_type = Option<i64>)]
    #[schema(value_type = Option<i64>)]
    pub transaction_id: Option<crate::transaction::TransactionId>,

    /// The `incarnation_uuid` that `/start_transaction` returned.  If the
    /// pipeline restarted since then, the request fails with 400 Bad Request
    /// and error code `IncarnationUuidMismatch`, because transaction IDs start
    /// again after a restart.
    pub incarnation_uuid: Option<uuid::Uuid>,
}

/// Query parameters to the `/approve` endpoint.
#[derive(Debug, Deserialize, IntoParams, ToSchema)]
pub struct ApproveParameters {
    /// Bootstrap the pipeline with output connectors disabled.
    #[serde(default)]
    pub silent_bootstrap: bool,
    /// Bootstrap new and modified views concurrently, keeping the pre-existing
    /// views live while the new ones backfill. Mutually exclusive with
    /// `silent_bootstrap`.
    #[serde(default)]
    pub concurrent_bootstrap: bool,
}

/// Query parameters to the `/stats` endpoint.
#[derive(Debug, Default, Deserialize, Serialize, IntoParams, ToSchema)]
#[into_params(parameter_in = Query)]
pub struct StatsParams {
    /// When `true`, the response includes the most recent error messages of
    /// each connector. An error message can contain values from the record
    /// that caused it. The default is `false`, which keeps the response small
    /// for callers that poll `/stats`.
    #[serde(default)]
    pub include_connector_errors: bool,
}