diff --git a/tembo-operator/Cargo.lock b/tembo-operator/Cargo.lock index 62f594fe8..bba4ac57b 100644 --- a/tembo-operator/Cargo.lock +++ b/tembo-operator/Cargo.lock @@ -494,7 +494,7 @@ dependencies = [ [[package]] name = "controller" -version = "0.29.0" +version = "0.29.1" dependencies = [ "actix-web", "anyhow", diff --git a/tembo-operator/Cargo.toml b/tembo-operator/Cargo.toml index 76482f754..9424866f1 100644 --- a/tembo-operator/Cargo.toml +++ b/tembo-operator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "controller" description = "Tembo Operator for Postgres" -version = "0.29.0" +version = "0.29.1" edition = "2021" default-run = "controller" license = "Apache-2.0" diff --git a/tembo-operator/src/app_service/ingress.rs b/tembo-operator/src/app_service/ingress.rs index a85441fc6..91a6fa569 100644 --- a/tembo-operator/src/app_service/ingress.rs +++ b/tembo-operator/src/app_service/ingress.rs @@ -262,7 +262,7 @@ pub fn generate_ingress_tcp_routes( let mut routes: Vec = Vec::new(); for route in routings.iter() { match route.ingress_path.clone() { - Some(path) => { + Some(_path) => { if !route.ingress_type.clone()?.eq(&IngressType::tcp) { // Do not create IngressRouteTCPRoutes for non-TCP ingress type debug!("Skipping IngressRouteTCPRoutes for non-TCP ingress type"); diff --git a/tembo-operator/src/defaults.rs b/tembo-operator/src/defaults.rs index e6565fc01..d45a998a1 100644 --- a/tembo-operator/src/defaults.rs +++ b/tembo-operator/src/defaults.rs @@ -65,6 +65,10 @@ pub fn default_postgres_exporter_image() -> String { "quay.io/prometheuscommunity/postgres-exporter:v0.12.0".to_owned() } +pub fn default_postgres_exporter_target_databases() -> Vec { + vec!["postgres".to_owned()] +} + pub fn default_extensions() -> Vec { vec![] } diff --git a/tembo-operator/src/lib.rs b/tembo-operator/src/lib.rs index 4b718a8bb..d4ac37aaf 100644 --- a/tembo-operator/src/lib.rs +++ b/tembo-operator/src/lib.rs @@ -47,6 +47,9 @@ pub enum Error { #[error("SerializationError: {0}")] SerializationError(#[source] serde_json::Error), + #[error("SerializationError: {0}")] + YamlSerializationError(#[source] serde_yaml::Error), + #[error("Kube Error: {0}")] KubeError(#[from] kube::Error), @@ -71,3 +74,9 @@ impl Error { format!("{self:?}").to_lowercase() } } + +impl From for Error { + fn from(err: serde_yaml::Error) -> Self { + Error::YamlSerializationError(err) + } +} diff --git a/tembo-operator/src/postgres_exporter.rs b/tembo-operator/src/postgres_exporter.rs index 97c4be649..c80f33cb6 100644 --- a/tembo-operator/src/postgres_exporter.rs +++ b/tembo-operator/src/postgres_exporter.rs @@ -108,6 +108,8 @@ pub struct Metrics { /// - total_messages: /// description: Total number of messages that have passed into the queue. /// usage: GAUGE +/// target_databases: +/// - "postgres" /// ``` #[derive(Clone, Debug, JsonSchema, PartialEq, Serialize, Deserialize)] pub struct QueryItem { @@ -131,6 +133,16 @@ pub struct QueryItem { /// description: the metric's description /// metrics_mapping: the optional column mapping when usage is set to MAPPEDMETRIC pub metrics: Vec, + + /// The default database can always be overridden for a given user-defined + /// metric, by specifying a list of one or more databases in the target_databases + /// option. + /// + /// See: [https://cloudnative-pg.io/documentation/1.20/monitoring/#example-of-a-user-defined-metric-running-on-multiple-databases](https://cloudnative-pg.io/documentation/1.20/monitoring/#example-of-a-user-defined-metric-running-on-multiple-databases) + /// + /// **Default:** `["postgres"]` + #[serde(default = "defaults::default_postgres_exporter_target_databases")] + pub target_databases: Vec, } #[derive(Clone, Debug, JsonSchema, PartialEq, Serialize, Deserialize)] @@ -185,7 +197,7 @@ pub async fn reconcile_metrics_configmap(cdb: &CoreDB, client: Client, ns: &str) // directly and not through the reconcile function. match cdb.spec.metrics.clone().and_then(|m| m.queries) { Some(queries) => { - let qdata = serde_yaml::to_string(&queries).unwrap(); + let qdata = serde_yaml::to_string(&queries)?; let d: BTreeMap = BTreeMap::from([(QUERIES.to_string(), qdata)]); apply_configmap( client.clone(), @@ -196,7 +208,7 @@ pub async fn reconcile_metrics_configmap(cdb: &CoreDB, client: Client, ns: &str) .await? } None => { - debug!("No queries specified in CoreDB spec"); + debug!("No queries specified in CoreDB spec {}", coredb_name); } } Ok(()) @@ -223,7 +235,8 @@ mod tests { "description": "Time at which postmaster started" } } - ] + ], + "target_databases": ["postgres"] }, "extensions": { "query": "select count(*) as num_ext from pg_available_extensions", @@ -235,7 +248,8 @@ mod tests { "description": "Num extensions" } } - ] + ], + "target_databases": ["postgres"] } } ); @@ -286,6 +300,8 @@ mod tests { - num_ext: usage: GAUGE description: Num extensions + target_databases: + - postgres pg_postmaster: query: SELECT pg_postmaster_start_time as start_time_seconds from pg_postmaster_start_time() master: true @@ -293,6 +309,8 @@ pg_postmaster: - start_time_seconds: usage: GAUGE description: Time at which postmaster started + target_databases: + - postgres "#; // formmatted correctly as yaml (for configmap) assert_eq!(yaml, data); diff --git a/tembo-operator/src/stacks/templates/message_queue.yaml b/tembo-operator/src/stacks/templates/message_queue.yaml index 468d18501..27671c2bf 100644 --- a/tembo-operator/src/stacks/templates/message_queue.yaml +++ b/tembo-operator/src/stacks/templates/message_queue.yaml @@ -95,6 +95,8 @@ postgres_metrics: - total_messages: usage: GAUGE description: Total number of messages that have passed into the queue. + target_databases: + - "postgres" postgres_config_engine: mq postgres_config: - name: shared_preload_libraries diff --git a/tembo-operator/yaml/sample-message-queue.yaml b/tembo-operator/yaml/sample-message-queue.yaml index 79e25ef3d..ac68dfd12 100644 --- a/tembo-operator/yaml/sample-message-queue.yaml +++ b/tembo-operator/yaml/sample-message-queue.yaml @@ -55,7 +55,7 @@ spec: image: quay.io/prometheuscommunity/postgres-exporter:v0.12.0 queries: pgmq: - query: select queue_name, queue_length, oldest_msg_age_sec, newest_msg_age_sec, total_messages from public.pgmq_metrics_all() + query: select queue_name, queue_length, oldest_msg_age_sec, newest_msg_age_sec, total_messages from pgmq.metrics_all() master: true metrics: - queue_name: @@ -73,6 +73,8 @@ spec: - total_messages: description: Total number of messages that have passed into the queue. usage: GAUGE + target_databases: + - "postgres" runtime_config: - name: shared_buffers value: "1024MB"