From 3f369c8c29e1ba81dca02400e12ee947e723b7bd Mon Sep 17 00:00:00 2001 From: sdairs Date: Tue, 17 Nov 2026 15:20:01 +0000 Subject: [PATCH] fix(api): add Postgres standby count and graduate Postgres operations from Beta - New `PgStandbyCount` integer enum (0, 1, 2, Unknown(i64)) for the `pgStandbyCount` schema. - `standby_count` on PostgresService, PostgresServiceListItem, PostgresServicePostRequest and PostgresServicePatchRequest (optional) and on the orphan BasePostgresService (required, as the spec resolves it). - Regenerate BETA_OPERATIONS: 19 Postgres operations are no longer Beta. - CLI: `cloud postgres create/update` send no standbyCount (pinned by the existing builder tests); live test literals gain the new field. Refs #1466 Co-Authored-By: Claude Opus 5.5 --- crates/clickhouse-cloud-api/CHANGELOG.md | 16 +++ crates/clickhouse-cloud-api/src/meta.rs | 22 +--- crates/clickhouse-cloud-api/src/models.rs | 6 +- .../src/models/postgres.rs | 67 ++++++++++++ .../tests/client/postgres.rs | 102 ++++++++++++++++++ .../tests/integration_postgres_test.rs | 26 +++++ .../tests/model_facade_test.rs | 4 + .../tests/models/postgres.rs | 76 +++++++++++++ .../src/cloud/postgres/lifecycle.rs | 6 ++ .../tests/live_clickpipe_postgres_cdc_test.rs | 1 + 10 files changed, 303 insertions(+), 23 deletions(-) diff --git a/crates/clickhouse-cloud-api/CHANGELOG.md b/crates/clickhouse-cloud-api/CHANGELOG.md index fa249dc6..f2f42ab3 100644 --- a/crates/clickhouse-cloud-api/CHANGELOG.md +++ b/crates/clickhouse-cloud-api/CHANGELOG.md @@ -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. diff --git a/crates/clickhouse-cloud-api/src/meta.rs b/crates/clickhouse-cloud-api/src/meta.rs index 00aa21f4..6e50dc0e 100644 --- a/crates/clickhouse-cloud-api/src/meta.rs +++ b/crates/clickhouse-cloud-api/src/meta.rs @@ -113,24 +113,7 @@ 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", @@ -138,8 +121,6 @@ pub const BETA_OPERATIONS: &[&str] = &[ "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", @@ -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")); diff --git a/crates/clickhouse-cloud-api/src/models.rs b/crates/clickhouse-cloud-api/src/models.rs index 10ab30c8..289707f6 100644 --- a/crates/clickhouse-cloud-api/src/models.rs +++ b/crates/clickhouse-cloud-api/src/models.rs @@ -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, diff --git a/crates/clickhouse-cloud-api/src/models/postgres.rs b/crates/clickhouse-cloud-api/src/models/postgres.rs index 2096f4f7..4b5f93f6 100644 --- a/crates/clickhouse-cloud-api/src/models/postgres.rs +++ b/crates/clickhouse-cloud-api/src/models/postgres.rs @@ -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 for PgStandbyCount { + fn from(value: i64) -> Self { + match value { + 0 => Self::Zero, + 1 => Self::One, + 2 => Self::Two, + value => Self::Unknown(value), + } + } +} + +impl From 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 { @@ -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, } @@ -1242,6 +1293,10 @@ pub struct PostgresService { pub region: Option, #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, + /// 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, #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, #[serde(rename = "storageSize", skip_serializing_if = "Option::is_none")] @@ -1340,6 +1395,10 @@ pub struct PostgresServiceListItem { pub region: Option, #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, + /// 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, #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -1370,6 +1429,10 @@ pub struct PostgresServicePatchRequest { pub name: Option, #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, + /// 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, #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option, } @@ -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, #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option, } diff --git a/crates/clickhouse-cloud-api/tests/client/postgres.rs b/crates/clickhouse-cloud-api/tests/client/postgres.rs index f39f02d7..6e31ea70 100644 --- a/crates/clickhouse-cloud-api/tests/client/postgres.rs +++ b/crates/clickhouse-cloud-api/tests/client/postgres.rs @@ -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()), @@ -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; diff --git a/crates/clickhouse-cloud-api/tests/integration_postgres_test.rs b/crates/clickhouse-cloud-api/tests/integration_postgres_test.rs index 875aa890..7a9e5021 100644 --- a/crates/clickhouse-cloud-api/tests/integration_postgres_test.rs +++ b/crates/clickhouse-cloud-api/tests/integration_postgres_test.rs @@ -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, @@ -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"); diff --git a/crates/clickhouse-cloud-api/tests/model_facade_test.rs b/crates/clickhouse-cloud-api/tests/model_facade_test.rs index aa0f9f76..8852579e 100644 --- a/crates/clickhouse-cloud-api/tests/model_facade_test.rs +++ b/crates/clickhouse-cloud-api/tests/model_facade_test.rs @@ -118,6 +118,10 @@ fn extracted_models_keep_root_and_models_paths() { PhantomData::, PhantomData::, ); + assert_same_type( + PhantomData::, + PhantomData::, + ); assert_same_type( PhantomData::, PhantomData::, diff --git a/crates/clickhouse-cloud-api/tests/models/postgres.rs b/crates/clickhouse-cloud-api/tests/models/postgres.rs index dd5f9701..4ba60a84 100644 --- a/crates/clickhouse-cloud-api/tests/models/postgres.rs +++ b/crates/clickhouse-cloud-api/tests/models/postgres.rs @@ -266,6 +266,7 @@ fn serialize_postgres_service_post_request() { provider: PgProvider::Aws, region: "us-east-1".to_string(), size: PgSize::C6gd_large, + standby_count: None, ha_type: None, ip_access_list: None, pg_bouncer_config: None, @@ -870,6 +871,7 @@ fn postgres_service_post_request_distinguishes_omitted_and_empty_access_list() { provider: PgProvider::Aws, region: "us-east-1".to_string(), size: PgSize::C6gd_large, + standby_count: None, ha_type: None, ip_access_list: None, pg_bouncer_config: None, @@ -1060,3 +1062,77 @@ fn pg_config_serializes_only_the_new_gucs_that_are_set() { }) ); } + +#[test] +fn pg_standby_count_serializes_as_an_integer_and_keeps_unknown_values() { + for (wire, value) in [ + (0, PgStandbyCount::Zero), + (1, PgStandbyCount::One), + (2, PgStandbyCount::Two), + (7, PgStandbyCount::Unknown(7)), + ] { + assert_eq!( + serde_json::to_value(value).unwrap(), + serde_json::json!(wire) + ); + assert_eq!( + serde_json::from_value::(serde_json::json!(wire)).unwrap(), + value + ); + assert_eq!(value.to_string(), wire.to_string()); + } + assert!(serde_json::from_value::(serde_json::json!("1")).is_err()); +} + +#[test] +fn postgres_standby_count_tolerates_missing_and_null_in_responses() { + for wire in [ + serde_json::json!({}), + serde_json::json!({"standbyCount": null}), + ] { + let pg: PostgresService = serde_json::from_value(wire.clone()).unwrap(); + assert_eq!(pg.standby_count, None); + assert_eq!(serde_json::to_value(pg).unwrap(), serde_json::json!({})); + + let item: PostgresServiceListItem = serde_json::from_value(wire).unwrap(); + assert_eq!(item.standby_count, None); + assert_eq!(serde_json::to_value(item).unwrap(), serde_json::json!({})); + } +} + +#[test] +fn postgres_requests_send_standby_count_only_when_set() { + assert_eq!( + serde_json::to_value(PostgresServicePatchRequest::default()).unwrap(), + serde_json::json!({}) + ); + assert_eq!( + serde_json::to_value(PostgresServicePatchRequest { + standby_count: Some(PgStandbyCount::Zero), + ..Default::default() + }) + .unwrap(), + serde_json::json!({"standbyCount": 0}) + ); + let mut create = PostgresServicePostRequest { + name: "pg".to_string(), + provider: PgProvider::Aws, + region: "us-east-1".to_string(), + size: PgSize::C6gd_large, + standby_count: None, + pg_bouncer_config: None, + ha_type: None, + ip_access_list: None, + pg_config: None, + postgres_version: None, + tags: None, + }; + assert!( + serde_json::to_value(&create) + .unwrap() + .get("standbyCount") + .is_none() + ); + create.standby_count = Some(PgStandbyCount::Two); + assert_eq!(serde_json::to_value(&create).unwrap()["standbyCount"], 2); +} diff --git a/crates/clickhousectl/src/cloud/postgres/lifecycle.rs b/crates/clickhousectl/src/cloud/postgres/lifecycle.rs index e89a627d..cf164091 100644 --- a/crates/clickhousectl/src/cloud/postgres/lifecycle.rs +++ b/crates/clickhousectl/src/cloud/postgres/lifecycle.rs @@ -635,6 +635,8 @@ fn build_postgres_create_request( pg_config, pg_bouncer_config, ip_access_list: postgres_create_ip_access_list(opts.ip_allow, opts.block_public_access), + // Not exposed by `cloud postgres create` yet: never sent. + standby_count: None, }) } @@ -695,6 +697,8 @@ pub(super) fn build_postgres_update_request( ha_type, tags, ip_access_list, + // Not exposed by `cloud postgres update` yet: never sent. + standby_count: None, } } @@ -1074,6 +1078,7 @@ pub(super) mod tests { assert!(req.deletion_protection.is_none()); assert!(req.tags.is_none()); assert!(req.ip_access_list.is_none()); + assert!(req.standby_count.is_none()); assert_eq!(serde_json::to_value(req).unwrap(), serde_json::json!({})); } @@ -1247,6 +1252,7 @@ pub(super) mod tests { assert!(req.pg_config.is_none()); assert!(req.pg_bouncer_config.is_none()); assert!(req.ip_access_list.is_none()); + assert!(req.standby_count.is_none()); assert!( serde_json::to_value(&req) .unwrap() diff --git a/crates/clickhousectl/tests/live_clickpipe_postgres_cdc_test.rs b/crates/clickhousectl/tests/live_clickpipe_postgres_cdc_test.rs index 1bea6591..7707e123 100644 --- a/crates/clickhousectl/tests/live_clickpipe_postgres_cdc_test.rs +++ b/crates/clickhousectl/tests/live_clickpipe_postgres_cdc_test.rs @@ -133,6 +133,7 @@ async fn cloud_clickpipe_postgres_cli_cdc() -> TestResult<()> { provider: PgProvider::Unknown(ctx.provider.clone()), region: ctx.region.clone(), size: PgSize::R8gd_medium, + standby_count: None, tags: Some(ctx.clickpipe_run_tags()), ha_type: None, ip_access_list: None,