Skip to content

Commit

Permalink
Consolidate stack metrics into metrics sidecar instead of postgres ex…
Browse files Browse the repository at this point in the history
…porter deployment (#425)
  • Loading branch information
nhudson authored Dec 16, 2023
1 parent 5fbe479 commit 5016af1
Show file tree
Hide file tree
Showing 18 changed files with 877 additions and 799 deletions.
2 changes: 1 addition & 1 deletion charts/tembo-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: tembo-operator
description: 'Helm chart to deploy the tembo-operator'
type: application
icon: https://cloud.tembo.io/images/TemboElephant.png
version: 0.2.2
version: 0.2.3
home: https://tembo.io
sources:
- https://github.com/tembo-io/tembo-stacks
Expand Down
14 changes: 4 additions & 10 deletions charts/tembo-operator/templates/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ spec:
nullable: true
properties:
enabled:
default: true
default: false
description: |-
To enable or disable the metric.
Expand Down Expand Up @@ -1675,18 +1675,12 @@ spec:
format: int32
type: integer
postgresExporterEnabled:
default: true
description: |-
Enable the use of the Postgres Exporter deployment for metrics collection
**Default**: true.
default: false
description: '**DEPRECATED** Enable the use of the Postgres Exporter deployment for metrics collection This is no longer used and will be removed in a future release.'
type: boolean
postgresExporterImage:
default: quay.io/prometheuscommunity/postgres-exporter:v0.12.0
description: |-
The postgres-exporter image you want to use for the postgres-exporter deployment.
**Default**: quay.io/prometheuscommunity/postgres-exporter:v0.12.0
description: '**DEPRECATED** The postgres-exporter image you want to use for the postgres-exporter deployment. This is no longer used and will be removed in a future release.'
type: string
replicas:
default: 1
Expand Down
48 changes: 37 additions & 11 deletions conductor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 21 additions & 17 deletions conductor/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mod test {
};

use kube::{
api::ListParams,
runtime::wait::{await_condition, conditions},
Api, Client, Config,
};
Expand Down Expand Up @@ -232,13 +231,6 @@ mod test {
let pod_name = format!("{}-1", &namespace);
pod_ready_and_running(pods.clone(), pod_name.clone()).await;

// Wait for postgres-exporter pod to be running
let lp = ListParams::default()
.labels(format!("app=postgres-exporter,coredb.io/name={}", namespace).as_str());
let exporter_pods = pods.list(&lp).await.expect("could not get pods");
let exporter_pod_name = exporter_pods.items[0].metadata.name.as_ref().unwrap();
pod_ready_and_running(pods.clone(), exporter_pod_name.clone()).await;

// ADD AN EXTENSION - ASSERT IT MAKES IT TO STATUS.EXTENSIONS
// conductor receives a CRUDevent from control plane
// take note of number of extensions at this point in time
Expand Down Expand Up @@ -297,9 +289,6 @@ mod test {
thread::sleep(time::Duration::from_secs(40));

pod_ready_and_running(pods.clone(), pod_name.clone()).await;
let exporter_pods = pods.list(&lp).await.expect("could not get pods");
let exporter_pod_name = exporter_pods.items[0].metadata.name.as_ref().unwrap();
pod_ready_and_running(pods.clone(), exporter_pod_name.clone()).await;

// Get the last time the pod was started
// using SELECT pg_postmaster_start_time();
Expand Down Expand Up @@ -348,9 +337,6 @@ mod test {
}

pod_ready_and_running(pods.clone(), pod_name).await;
let exporter_pods = pods.list(&lp).await.expect("could not get pods");
let exporter_pod_name = exporter_pods.items[0].metadata.name.as_ref().unwrap();
pod_ready_and_running(pods.clone(), exporter_pod_name.clone()).await;

// Get the last time the pod was started
// using SELECT pg_postmaster_start_time();
Expand Down Expand Up @@ -407,10 +393,28 @@ mod test {
use conductor::aws::cloudformation::AWSConfigState;
let aws_region = "us-east-1".to_owned();
let region = Region::new(aws_region);
let aws_config_state = AWSConfigState::new(region).await;
let aws_config_state = AWSConfigState::new(region.clone()).await;
let stack_name = format!("org-{}-inst-{}-cf", org_name, dbname);
let exists = aws_config_state.does_stack_exist(&stack_name).await;
assert!(!exists, "CF stack was not deleted");
// let dcf = aws_config_state
// .delete_cloudformation_stack(&stack_name)
// .await;
// assert!(dcf);
// let exists = aws_config_state.does_stack_exist(&stack_name).await;
// assert!(!exists, "CF stack was not deleted");
match aws_config_state
.delete_cloudformation_stack(&stack_name)
.await
{
Ok(_) => {
// If deletion was successful, check if the stack still exists
let stack_exists = aws_config_state.does_stack_exist(&stack_name).await;
assert!(!stack_exists, "CloudFormation stack was not deleted");
}
Err(e) => {
// If there was an error deleting the stack, fail the test
panic!("Failed to delete CloudFormation stack: {:?}", e);
}
}
}

async fn kube_client() -> kube::Client {
Expand Down
2 changes: 1 addition & 1 deletion tembo-operator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tembo-operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "controller"
description = "Tembo Operator for Postgres"
version = "0.27.1"
version = "0.28.0"
edition = "2021"
default-run = "controller"
license = "Apache-2.0"
Expand Down
10 changes: 4 additions & 6 deletions tembo-operator/src/apis/coredb_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ pub struct CoreDBSpec {
#[serde(default = "defaults::default_pkglibdir_storage")]
pub pkglibdirStorage: Quantity,

/// Enable the use of the Postgres Exporter deployment for metrics collection
///
/// **Default**: true.
/// **DEPRECATED** Enable the use of the Postgres Exporter deployment for metrics collection
/// This is no longer used and will be removed in a future release.
#[serde(default = "defaults::default_postgres_exporter_enabled")]
pub postgresExporterEnabled: bool,

Expand All @@ -379,9 +378,8 @@ pub struct CoreDBSpec {
#[serde(default = "defaults::default_image")]
pub image: String,

/// The postgres-exporter image you want to use for the postgres-exporter deployment.
///
/// **Default**: quay.io/prometheuscommunity/postgres-exporter:v0.12.0
/// **DEPRECATED** The postgres-exporter image you want to use for the postgres-exporter deployment.
/// This is no longer used and will be removed in a future release.
#[serde(default = "defaults::default_postgres_exporter_image")]
pub postgresExporterImage: String,

Expand Down
15 changes: 15 additions & 0 deletions tembo-operator/src/cloudnativepg/cnpg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::{
defaults::{default_image, default_llm_image},
errors::ValueError,
is_postgres_ready, patch_cdb_status_merge,
postgres_exporter::EXPORTER_CONFIGMAP_PREFIX,
psql::PsqlOutput,
trunk::extensions_that_require_load,
Context, RESTARTED_AT,
Expand Down Expand Up @@ -601,6 +602,20 @@ pub fn cnpg_cluster_from_cdb(
})
}

if cdb
.spec
.metrics
.as_ref()
.and_then(|m| m.queries.as_ref())
.is_some()
{
let configmap = format!("{}{}", EXPORTER_CONFIGMAP_PREFIX, cdb.name_any());
metrics.push(ClusterMonitoringCustomQueriesConfigMap {
key: "tembo-queries".to_string(),
name: configmap,
})
}

Cluster {
metadata: ObjectMeta {
name: Some(name.clone()),
Expand Down
3 changes: 3 additions & 0 deletions tembo-operator/src/configmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ pub async fn apply_configmap(
cm_name: &str,
data: BTreeMap<String, String>,
) -> Result<(), Error> {
let mut labels: BTreeMap<String, String> = BTreeMap::new();
labels.insert("cnpg.io/reload".to_owned(), "true".to_owned());
let cm_api: Api<ConfigMap> = Api::namespaced(client, namespace);
let cm = ConfigMap {
metadata: ObjectMeta {
name: Some(cm_name.to_string()),
labels: Some(labels),
..Default::default()
},
data: Some(data),
Expand Down
Loading

0 comments on commit 5016af1

Please sign in to comment.