Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/clickhouse-cloud-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ the request body is unchanged, and `ClickPipeSettings` remains as a type alias
of `ClickPipeSettingsPutRequest`: existing code compiles unchanged. Responses
still use `ClickPipeSettingsResponse`.

`PostgresService`, `PostgresServiceListItem`, `PostgresServicePostRequest` and
`PostgresServicePatchRequest` gain optional `standby_count` (`standbyCount`),
typed by the new `PgStandbyCount` integer enum (`Zero`, `One`, `Two`, and an
`Unknown(i64)` catch-all; it serializes as a JSON number). The values accepted
depend on `ha_type`: `none` takes 0, `async` takes 1, and `sync` takes 1 or 2;
when it is omitted, the default for the HA type applies (0, 1 and 2
respectively), including when `ha_type` changes on update. The orphan
`BasePostgresService` gains a required `standby_count: PgStandbyCount`.
Struct-literal callers need `standby_count: None` (or a value for
`BasePostgresService`), or `..Default::default()` for the PATCH body.

The Postgres service, configuration, metrics, Prometheus, logs, backups,
certificates, read-replica, restore, password, state and slow-query
operations are no longer Beta: 19 entries leave `meta::BETA_OPERATIONS`, so
`meta::is_beta_operation` returns `false` for them.

## 0.5.1

No changes to this crate; released in lockstep with `clickhousectl` 0.5.1.
Expand Down
22 changes: 2 additions & 20 deletions crates/clickhouse-cloud-api/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,14 @@ pub const BETA_OPERATIONS: &[&str] = &[
"organization_public_previews_get_list",
"organization_quota_get",
"organization_quotas_get_list",
"postgres_instance_config_get",
"postgres_instance_config_patch",
"postgres_instance_config_post",
"postgres_instance_create_read_replica",
"postgres_instance_metrics_get",
"postgres_instance_prometheus_get",
"postgres_instance_restore",
"postgres_logs_get_list",
"postgres_org_prometheus_get",
"postgres_service_backup_get_list",
"postgres_service_certs_get",
"postgres_service_create",
"postgres_service_delete",
"postgres_service_get",
"postgres_service_get_list",
"postgres_service_patch",
"postgres_service_patch_state",
"postgres_service_set_password",
"replica_aware_routing_get",
"replica_aware_routing_update",
"service_clickhouse_setting_delete",
"service_clickhouse_setting_get",
"service_clickhouse_settings_list_get",
"service_clickhouse_settings_schema_get",
"service_clickhouse_settings_update",
"slow_query_pattern_get",
"slow_query_patterns_get_list",
"snapshot_configuration_get",
"snapshot_configuration_update",
"snapshot_get",
Expand Down Expand Up @@ -275,7 +256,8 @@ mod tests {
fn is_beta_operation_matches_constant() {
assert!(is_beta_operation("replica_aware_routing_get"));
assert!(!is_beta_operation("scaling_schedule_get"));
assert!(is_beta_operation("postgres_service_get_list"));
assert!(is_beta_operation("click_stack_list_alerts"));
assert!(!is_beta_operation("postgres_service_get_list"));
assert!(!is_beta_operation("services_list"));
assert!(!is_beta_operation("organization_prometheus_discovery_get"));
assert!(!is_beta_operation("not_a_real_op"));
Expand Down
6 changes: 3 additions & 3 deletions crates/clickhouse-cloud-api/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ pub use postgres::{
PgConfigEnableParallelHash, PgConfigIoMethod, PgConfigLogLockWaits, PgConfigResponse,
PgConfigSslMinProtocolVersion, PgConfigWalCompression, PgCreatedAtProperty,
PgDeletionProtectionProperty, PgHaType, PgIdProperty, PgIsPrimaryProperty, PgNameProperty,
PgPassword, PgPitrRestoreTargetProperty, PgProvider, PgRegion, PgSize, PgStateProperty,
PgStorageSize, PgTags, PgTagsResponse, PgVersion, PostgresBackup, PostgresInstanceConfig,
PostgresInstanceConfigResponse, PostgresInstanceUpdateConfigResponse,
PgPassword, PgPitrRestoreTargetProperty, PgProvider, PgRegion, PgSize, PgStandbyCount,
PgStateProperty, PgStorageSize, PgTags, PgTagsResponse, PgVersion, PostgresBackup,
PostgresInstanceConfig, PostgresInstanceConfigResponse, PostgresInstanceUpdateConfigResponse,
PostgresIpAccessListEntry, PostgresIpAccessListEntryResponse, PostgresIpAccessListPatch,
PostgresIpAccessListRuleReference, PostgresLogEntry, PostgresLogsGetListSeverity,
PostgresLogsGetListSortorder, PostgresMetric, PostgresMetricDataPoint, PostgresMetricSeries,
Expand Down
67 changes: 67 additions & 0 deletions crates/clickhouse-cloud-api/src/models/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,53 @@ impl PgHaType {
pub const VALUES: &'static [&'static str] = &["none", "async", "sync"];
}

/// `pgStandbyCount` enum from the ClickHouse Cloud API: the number of hot
/// standby instances.
///
/// Accepted values and defaults depend on `haType`: `none` takes 0 (default),
/// `async` takes 1 (default), and `sync` takes 1 or 2 (default). When `haType`
/// is updated without a standby count, the default for the new `haType`
/// applies.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(from = "i64", into = "i64")]
#[repr(i64)]
pub enum PgStandbyCount {
Zero = 0,
One = 1,
Two = 2,
/// Catch-all for unknown or newly-added values.
#[serde(untagged)]
Unknown(i64),
}

impl From<i64> for PgStandbyCount {
fn from(value: i64) -> Self {
match value {
0 => Self::Zero,
1 => Self::One,
2 => Self::Two,
value => Self::Unknown(value),
}
}
}

impl From<PgStandbyCount> for i64 {
fn from(value: PgStandbyCount) -> Self {
match value {
PgStandbyCount::Zero => 0,
PgStandbyCount::One => 1,
PgStandbyCount::Two => 2,
PgStandbyCount::Unknown(value) => value,
}
}
}

impl std::fmt::Display for PgStandbyCount {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", i64::from(*self))
}
}

/// `pgProvider` enum from the ClickHouse Cloud API.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub enum PgProvider {
Expand Down Expand Up @@ -1194,6 +1241,10 @@ pub struct BasePostgresService {
pub provider: PgProvider,
pub region: PgRegion,
pub size: PgSize,
/// Number of hot standby instances; see [`PgStandbyCount`] for the values
/// each `haType` accepts.
#[serde(rename = "standbyCount")]
pub standby_count: PgStandbyCount,
pub tags: PgTags,
}

Expand Down Expand Up @@ -1242,6 +1293,10 @@ pub struct PostgresService {
pub region: Option<PgRegion>,
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<PgSize>,
/// Number of hot standby instances; see [`PgStandbyCount`] for the values
/// each `haType` accepts.
#[serde(rename = "standbyCount", skip_serializing_if = "Option::is_none")]
pub standby_count: Option<PgStandbyCount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<PgStateProperty>,
#[serde(rename = "storageSize", skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1340,6 +1395,10 @@ pub struct PostgresServiceListItem {
pub region: Option<PgRegion>,
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<PgSize>,
/// Number of hot standby instances; see [`PgStandbyCount`] for the values
/// each `haType` accepts.
#[serde(rename = "standbyCount", skip_serializing_if = "Option::is_none")]
pub standby_count: Option<PgStandbyCount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub state: Option<PgStateProperty>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1370,6 +1429,10 @@ pub struct PostgresServicePatchRequest {
pub name: Option<PgNameProperty>,
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<PgSize>,
/// Number of hot standby instances; see [`PgStandbyCount`] for the values
/// each `haType` accepts.
#[serde(rename = "standbyCount", skip_serializing_if = "Option::is_none")]
pub standby_count: Option<PgStandbyCount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<PgTags>,
}
Expand All @@ -1395,6 +1458,10 @@ pub struct PostgresServicePostRequest {
pub provider: PgProvider,
pub region: PgRegion,
pub size: PgSize,
/// Number of hot standby instances; see [`PgStandbyCount`] for the values
/// each `haType` accepts.
#[serde(rename = "standbyCount", skip_serializing_if = "Option::is_none")]
pub standby_count: Option<PgStandbyCount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<PgTags>,
}
Expand Down
102 changes: 102 additions & 0 deletions crates/clickhouse-cloud-api/tests/client/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async fn create_postgres_service() {
provider: PgProvider::Aws,
region: "us-east-1".to_string(),
size: PgSize::C6gd_large,
standby_count: None,
pg_bouncer_config: Some(PgBouncerConfig::from([
("default_pool_size".into(), "16".into()),
("future_parameter".into(), "on".into()),
Expand All @@ -133,6 +134,107 @@ async fn create_postgres_service() {
assert_eq!(pg.password.as_deref(), Some("generated-pw"));
}

#[tokio::test]
async fn create_postgres_service_sends_standby_count() {
let (s, c) = setup().await;

Mock::given(method("POST"))
.and(path("/v1/organizations/org-1/postgres"))
.and(body_partial_json(
serde_json::json!({"haType": "sync", "standbyCount": 1}),
))
.respond_with(ok_json(serde_json::json!({
"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"haType": "sync",
"standbyCount": 1
})))
.expect(1)
.mount(&s)
.await;

let body = PostgresServicePostRequest {
name: "pg-ha".to_string(),
provider: PgProvider::Aws,
region: "us-east-1".to_string(),
size: PgSize::C6gd_large,
standby_count: Some(PgStandbyCount::One),
pg_bouncer_config: None,
ha_type: Some(PgHaType::Sync),
ip_access_list: None,
pg_config: None,
postgres_version: None,
tags: None,
};
let pg = c
.postgres_service_create("org-1", &body)
.await
.unwrap()
.result
.unwrap();
assert_eq!(pg.standby_count, Some(PgStandbyCount::One));
}

#[tokio::test]
async fn postgres_list_and_get_read_standby_count() {
let (s, c) = setup().await;

Mock::given(method("GET"))
.and(path("/v1/organizations/org-1/postgres"))
.respond_with(ok_json(serde_json::json!([
{"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "standbyCount": 2}
])))
.expect(1)
.mount(&s)
.await;
Mock::given(method("GET"))
.and(path("/v1/organizations/org-1/postgres/pg-1"))
.respond_with(ok_json(serde_json::json!({
"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"standbyCount": 0
})))
.expect(1)
.mount(&s)
.await;

let list = c.postgres_service_get_list("org-1").await.unwrap();
assert_eq!(
list.result.unwrap()[0].standby_count,
Some(PgStandbyCount::Two)
);
let pg = c.postgres_service_get("org-1", "pg-1").await.unwrap();
assert_eq!(pg.result.unwrap().standby_count, Some(PgStandbyCount::Zero));
}

#[tokio::test]
async fn update_postgres_service_sends_standby_count() {
let (s, c) = setup().await;

Mock::given(method("PATCH"))
.and(path("/v1/organizations/org-1/postgres/pg-1"))
.and(wiremock::matchers::body_json(
serde_json::json!({"standbyCount": 2}),
))
.respond_with(ok_json(serde_json::json!({
"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"standbyCount": 2
})))
.expect(1)
.mount(&s)
.await;

let body = PostgresServicePatchRequest {
standby_count: Some(PgStandbyCount::Two),
..Default::default()
};
let pg = c
.postgres_service_patch("org-1", "pg-1", &body)
.await
.unwrap()
.result
.unwrap();
assert_eq!(pg.standby_count, Some(PgStandbyCount::Two));
}

#[tokio::test]
async fn list_postgres_services() {
let (s, c) = setup().await;
Expand Down
26 changes: 26 additions & 0 deletions crates/clickhouse-cloud-api/tests/integration_postgres_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async fn cloud_postgres_crud_lifecycle() -> TestResult<()> {
provider: PgProvider::Unknown(ctx.provider.clone()),
region: ctx.region.clone(),
size: size.clone(),
standby_count: None,
tags: Some(ctx.postgres_run_tags()),
ha_type: None,
ip_access_list: None,
Expand Down Expand Up @@ -194,6 +195,31 @@ async fn cloud_postgres_crud_lifecycle() -> TestResult<()> {
"created postgres service was not visible in list"
);

// A service created without haType or standbyCount gets haType "none",
// whose only (and default) standby count is 0.
failures
.run(
&ctx,
StepKind::NonBlocking,
"postgres get reports the default standby count",
|| {
let ha_type = ready.ha_type.clone();
let standby_count = ready.standby_count;
async move {
if ha_type == Some(PgHaType::None)
&& standby_count != Some(PgStandbyCount::Zero)
{
return Err(format!(
"expected standbyCount 0 for haType none, got {standby_count:?}"
)
.into());
}
Ok(())
}
},
)
.await?;

// ── Certificates ────────────────────────────────────────────

log_phase("Certificates");
Expand Down
4 changes: 4 additions & 0 deletions crates/clickhouse-cloud-api/tests/model_facade_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ fn extracted_models_keep_root_and_models_paths() {
PhantomData::<api::ClickPipeSettings>,
PhantomData::<api::models::ClickPipeSettingsPutRequest>,
);
assert_same_type(
PhantomData::<api::PgStandbyCount>,
PhantomData::<api::models::PgStandbyCount>,
);
assert_same_type(
PhantomData::<api::PostgresBackup>,
PhantomData::<api::models::PostgresBackup>,
Expand Down
Loading
Loading