Skip to content

feat: add postgres exporter #16244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: add postgres exporter
  • Loading branch information
f0ssel committed Jan 23, 2025
commit d6663e7bbbb83f3b938a394f54f57835a796c3fd
53 changes: 53 additions & 0 deletions scaletest/terraform/action/prometheus.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ locals {
prometheus_release_name = "prometheus"
prometheus_remote_write_send_interval = "15s"
prometheus_remote_write_metrics_regex = ".*"
prometheus_postgres_exporter_helm_repo = "https://prometheus-community.github.io/helm-charts"
prometheus_postgres_exporter_helm_chart = "prometheus-postgres-exporter"
prometheus_postgres_exporter_release_name = "prometheus-postgres-exporter"
}

resource "helm_release" "prometheus_chart_primary" {
Expand Down Expand Up @@ -43,6 +46,56 @@ YAML
depends_on = [helm_release.prometheus_chart_primary]
}

resource "kubernetes_secret" "prometheus_postgres_password" {
provider = kubernetes.primary

type = "kubernetes.io/basic-auth"
metadata {
name = "prometheus-postgres"
namespace = kubernetes_namespace.coder_primary.metadata.0.name
}
data = {
username = "${var.name}-prometheus"
password = random_password.prometheus_postgres_password.result
}
lifecycle {
ignore_changes = [timeouts, wait_for_service_account_token]
}
}

resource "helm_release" "prometheus_postgres_exporter" {
provider = helm.primary

repository = local.prometheus_postgres_exporter_helm_repo
chart = local.prometheus_postgres_exporter_helm_chart
name = local.prometheus_postgres_exporter_release_name
namespace = kubernetes_namespace.coder_primary.metadata.0.name
values = [<<EOF
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "cloud.google.com/gke-nodepool"
operator: "In"
values: ["${google_container_node_pool.node_pool["primary_misc"].name}"]
config:
datasource:
host: "${google_sql_database_instance.db.private_ip_address}"
user: "${var.name}-prometheus"
database: "${var.name}-coder"
passwordSecret:
name: "${kubernetes_secret.prometheus_postgres_password.metadata.0.name}"
key: password
autoDiscoverDatabases: true
serviceMonitor:
enabled: true
EOF
]

depends_on = [ helm_release.prometheus_chart_primary ]
}

resource "helm_release" "prometheus_chart_europe" {
provider = helm.europe

Expand Down
1 change: 1 addition & 0 deletions scaletest/terraform/action/prometheus_helm_values.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ prometheus:
externalLabels:
cluster: "${cluster}"
podMonitorSelectorNilUsesHelmValues: false
serviceMonitorSelectorNilUsesHelmValues: false
remoteWrite:
- url: "${prometheus_remote_write_url}"
tlsConfig:
Expand Down
Loading