feldera_types/query_params.rs
1//! Types for the query parameters of the pipeline endpoints.
2
3use serde::{Deserialize, Serialize};
4use utoipa::{IntoParams, ToSchema};
5
6use crate::runtime_status::RuntimeDesiredStatus;
7
8/// Circuit metrics output format.
9/// - `prometheus`: [format](https://github.com/prometheus/docs/blob/4b1b80f5f660a2f8dc25a54f52a65a502f31879a/docs/instrumenting/exposition_formats.md) expected by Prometheus
10/// - `json`: JSON format
11#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, ToSchema)]
12#[serde(rename_all = "snake_case")]
13pub enum MetricsFormat {
14 Prometheus,
15 Json,
16}
17
18/// Returns default metrics format.
19fn default_metrics_format() -> MetricsFormat {
20 MetricsFormat::Prometheus
21}
22
23/// Query parameters to retrieve pipeline circuit metrics.
24#[derive(Debug, Deserialize, IntoParams, ToSchema)]
25pub struct MetricsParameters {
26 #[serde(default = "default_metrics_format")]
27 pub format: MetricsFormat,
28}
29
30#[derive(Debug, Deserialize, IntoParams, ToSchema)]
31#[serde(default)]
32pub struct ActivateParams {
33 #[serde(with = "crate::runtime_status::snake_case_runtime_desired_status")]
34 pub initial: RuntimeDesiredStatus,
35}
36
37impl Default for ActivateParams {
38 fn default() -> Self {
39 Self {
40 initial: RuntimeDesiredStatus::Running,
41 }
42 }
43}
44
45#[derive(Debug, Deserialize, Serialize, IntoParams, ToSchema)]
46#[serde(default)]
47pub struct SamplyProfileParams {
48 /// In a multihost pipeline, the ordinal of the pipeline to sample.
49 pub ordinal: usize,
50 /// The number of seconds to sample for the profile, from 1 to 300.
51 pub duration_secs: u64,
52}
53
54impl SamplyProfileParams {
55 /// The longest profile a caller can request, in seconds.
56 pub const MAX_DURATION_SECS: u64 = 300;
57}
58
59/// Default query parameters for POST of a pipeline samply profile.
60impl Default for SamplyProfileParams {
61 fn default() -> Self {
62 Self {
63 ordinal: 0,
64 duration_secs: 30,
65 }
66 }
67}
68
69/// Query parameters to retrieve samply profile.
70#[derive(Debug, Default, Deserialize, Serialize, IntoParams, ToSchema)]
71#[into_params(parameter_in = Query)]
72#[serde(default)]
73pub struct SamplyProfileGetParams {
74 /// In a multihost pipeline, the ordinal of the pipeline to sample.
75 pub ordinal: usize,
76 /// If true, returns 204 redirect with Retry-After header if profile collection is in progress.
77 /// If false or not provided, returns the last collected profile.
78 pub latest: bool,
79}
80
81/// Query parameters to the `/commit_transaction` endpoint.
82#[derive(Debug, Default, Deserialize, Serialize, IntoParams, ToSchema)]
83#[into_params(parameter_in = Query)]
84#[serde(default)]
85pub struct CommitTransactionParams {
86 /// The ID of the transaction to commit, which `/start_transaction`
87 /// returned:
88 ///
89 /// - If this is the transaction that the API started and that is still
90 /// open, the request commits it.
91 /// - If this is the last transaction that `/commit_transaction`
92 /// committed, the request succeeds and does nothing, so it is safe to
93 /// retry.
94 /// - Otherwise, the request fails with 409 Conflict, for example if no
95 /// transaction with this ID has started yet.
96 ///
97 /// Without this parameter, the request commits the transaction that the
98 /// API started.
99 #[param(value_type = Option<i64>)]
100 #[schema(value_type = Option<i64>)]
101 pub transaction_id: Option<crate::transaction::TransactionId>,
102
103 /// The `incarnation_uuid` that `/start_transaction` returned. If the
104 /// pipeline restarted since then, the request fails with 400 Bad Request
105 /// and error code `IncarnationUuidMismatch`, because transaction IDs start
106 /// again after a restart.
107 pub incarnation_uuid: Option<uuid::Uuid>,
108}
109
110/// Query parameters to the `/approve` endpoint.
111#[derive(Debug, Deserialize, IntoParams, ToSchema)]
112pub struct ApproveParameters {
113 /// Bootstrap the pipeline with output connectors disabled.
114 #[serde(default)]
115 pub silent_bootstrap: bool,
116 /// Bootstrap new and modified views concurrently, keeping the pre-existing
117 /// views live while the new ones backfill. Mutually exclusive with
118 /// `silent_bootstrap`.
119 #[serde(default)]
120 pub concurrent_bootstrap: bool,
121}
122
123/// Query parameters to the `/stats` endpoint.
124#[derive(Debug, Default, Deserialize, Serialize, IntoParams, ToSchema)]
125#[into_params(parameter_in = Query)]
126pub struct StatsParams {
127 /// When `true`, the response includes the most recent error messages of
128 /// each connector. An error message can contain values from the record
129 /// that caused it. The default is `false`, which keeps the response small
130 /// for callers that poll `/stats`.
131 #[serde(default)]
132 pub include_connector_errors: bool,
133}