Skip to content

Commit 65ecb6e

Browse files
authored
DB o11y(fix): configure Alloy to connect DB with db-o11y user (#331)
1 parent 0f0da43 commit 65ecb6e

File tree

7 files changed

+22
-9
lines changed

7 files changed

+22
-9
lines changed

alloy/cloud.alloy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ otelcol.exporter.otlphttp "otlpEndpoint" {
269269

270270
// DB o11y
271271
prometheus.exporter.postgres "postgres_quickpizza" {
272-
data_source_names = [coalesce(env("QUICKPIZZA_DB"), "postgresql://localhost:5432/notexist")]
272+
data_source_names = [coalesce(env("DB_O11Y_CONNECTION"), "postgresql://localhost:5432/notexist")]
273273
enabled_collectors = ["stat_statements"]
274274

275275
autodiscovery {
@@ -278,7 +278,7 @@ prometheus.exporter.postgres "postgres_quickpizza" {
278278
}
279279

280280
database_observability.postgres "postgres_quickpizza" {
281-
data_source_name = coalesce(env("QUICKPIZZA_DB"), "postgresql://localhost:5432/notexist")
281+
data_source_name = coalesce(env("DB_O11Y_CONNECTION"), "postgresql://localhost:5432/notexist")
282282
forward_to = [loki.relabel.database_observability_postgres_quickpizza.receiver]
283283
targets = prometheus.exporter.postgres.postgres_quickpizza.targets
284284
enable_collectors = ["query_details", "query_samples", "schema_details", "explain_plans"]

compose.grafana-cloud.microservices.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ services:
3434
GRAFANA_CLOUD_TOKEN: "${GRAFANA_CLOUD_TOKEN}"
3535
GRAFANA_CLOUD_STACK: "${GRAFANA_CLOUD_STACK}"
3636
DEPLOYMENT_ENVIRONMENT: ${DEPLOYMENT_ENVIRONMENT:-development}
37-
# QUICKPIZZA_DB unset set to postgres. If empty, set to sqlite.
38-
QUICKPIZZA_DB: "${QUICKPIZZA_DB-postgres://postgres:postgres@quickpizza-db:5432/quickpizza_db?sslmode=disable}"
37+
DB_O11Y_CONNECTION: "postgres://db-o11y:db-o11y-password@quickpizza-db:5432/quickpizza_db?sslmode=disable"
3938
SERVICE_NAMESPACE: "${SERVICE_NAMESPACE:-quickpizza}"
4039
DB_SERVICE_NAME: "quickpizza-db"
4140
depends_on:

compose.grafana-cloud.monolithic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
GRAFANA_CLOUD_TOKEN: "${GRAFANA_CLOUD_TOKEN}"
2323
GRAFANA_CLOUD_STACK: "${GRAFANA_CLOUD_STACK}"
2424
DEPLOYMENT_ENVIRONMENT: ${DEPLOYMENT_ENVIRONMENT:-development}
25-
QUICKPIZZA_DB: "${QUICKPIZZA_DB-postgres://postgres:postgres@quickpizza-db:5432/quickpizza_db?sslmode=disable}"
25+
DB_O11Y_CONNECTION: "postgres://db-o11y:db-o11y-password@quickpizza-db:5432/quickpizza_db?sslmode=disable"
2626
SERVICE_NAMESPACE: "${SERVICE_NAMESPACE:-quickpizza}"
2727
DB_SERVICE_NAME: "quickpizza-db"
2828
depends_on:

terraform/alloy.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ resource "kubernetes_deployment" "alloy" {
9999
}
100100
}
101101
env {
102-
name = "QUICKPIZZA_DB"
102+
name = "DB_O11Y_CONNECTION"
103103
value_from {
104104
secret_key_ref {
105105
name = kubernetes_secret.quickpizza_postgres_credentials.metadata[0].name
106-
key = "CONNECTION_STRING"
106+
key = "DB_O11Y_CONNECTION_STRING"
107107
}
108108
}
109109
}

terraform/alloy/config.alloy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ otelcol.exporter.otlphttp "otlpEndpoint" {
345345

346346
// DB o11y
347347
prometheus.exporter.postgres "postgres_quickpizza" {
348-
data_source_names = [env("QUICKPIZZA_DB")]
348+
data_source_names = [env("DB_O11Y_CONNECTION")]
349349
enabled_collectors = ["stat_statements"]
350350

351351
autodiscovery {
@@ -354,7 +354,7 @@ prometheus.exporter.postgres "postgres_quickpizza" {
354354
}
355355

356356
database_observability.postgres "postgres_quickpizza" {
357-
data_source_name = env("QUICKPIZZA_DB")
357+
data_source_name = env("DB_O11Y_CONNECTION")
358358
forward_to = [loki.relabel.database_observability_postgres_quickpizza.receiver]
359359
targets = prometheus.exporter.postgres.postgres_quickpizza.targets
360360
enable_collectors = ["query_details", "query_samples", "schema_details", "explain_plans"]

terraform/database.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ resource "kubernetes_secret" "quickpizza_postgres_credentials" {
2525
data = {
2626
DATABASE_PASSWORD = var.quickpizza_db_password
2727
CONNECTION_STRING = format("postgres://%s:%s@%s/%s?sslmode=disable", var.quickpizza_db_user, var.quickpizza_db_password, kubernetes_service.postgres.metadata[0].name, var.quickpizza_db_name)
28+
# see scripts/init-db-observability.sh for usage
29+
DB_O11Y_CONNECTION_STRING = format("postgres://%s:%s@%s/%s?sslmode=disable", var.db_o11y_user, var.db_o11y_password, kubernetes_service.postgres.metadata[0].name, var.quickpizza_db_name)
2830
}
2931
}
3032

terraform/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,16 @@ variable "quickpizza_db_user" {
126126
variable "quickpizza_db_password" {
127127
default = "quickpizza"
128128
type = string
129+
}
130+
131+
variable "db_o11y_user" {
132+
default = "db-o11y"
133+
type = string
134+
sensitive = true
135+
}
136+
137+
variable "db_o11y_password" {
138+
default = "db-o11y-password"
139+
type = string
140+
sensitive = true
129141
}

0 commit comments

Comments
 (0)