Skip to content

Commit aaa9fa6

Browse files
committed
Change from database to databases
1 parent 36462c0 commit aaa9fa6

File tree

7 files changed

+43
-31
lines changed

7 files changed

+43
-31
lines changed

config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,11 +2120,13 @@ spec:
21202120
type: string
21212121
x-kubernetes-validations:
21222122
- rule: duration("0") <= self && self <= duration("60m")
2123-
database:
2123+
databases:
21242124
description: |-
2125-
The database to target with added custom queries.
2125+
The databases to target with added custom queries.
21262126
Default behavior is to target `postgres`.
2127-
type: string
2127+
items:
2128+
type: string
2129+
type: array
21282130
name:
21292131
description: |-
21302132
The name of this batch of queries, which will be used in naming the OTel

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11965,11 +11965,13 @@ spec:
1196511965
type: string
1196611966
x-kubernetes-validations:
1196711967
- rule: duration("0") <= self && self <= duration("60m")
11968-
database:
11968+
databases:
1196911969
description: |-
11970-
The database to target with added custom queries.
11970+
The databases to target with added custom queries.
1197111971
Default behavior is to target `postgres`.
11972-
type: string
11972+
items:
11973+
type: string
11974+
type: array
1197311975
name:
1197411976
description: |-
1197511977
The name of this batch of queries, which will be used in naming the OTel

internal/collector/postgres_metrics.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,31 @@ func EnablePostgresMetrics(ctx context.Context, inCluster *v1beta1.PostgresClust
191191
for _, querySet := range inCluster.Spec.Instrumentation.Metrics.CustomQueries.Add {
192192
// Create a receiver for the query set
193193

194-
db := "postgres"
195-
if querySet.Database != "" {
196-
db = querySet.Database
194+
dbs := []string{"postgres"}
195+
if len(querySet.Databases) != 0 {
196+
dbs = querySet.Databases
197197
}
198-
receiverName := "sqlquery/" + querySet.Name
199-
config.Receivers[receiverName] = map[string]any{
200-
"driver": "postgres",
201-
"datasource": fmt.Sprintf(
202-
`host=localhost dbname=%s port=5432 user=%s password=${env:PGPASSWORD}`,
203-
db,
204-
MonitoringUser),
205-
"collection_interval": querySet.CollectionInterval,
206-
// Give Postgres time to finish setup.
207-
"initial_delay": "15s",
208-
"queries": "${file:/etc/otel-collector/" +
209-
querySet.Name + "/" + querySet.Queries.Key + "}",
198+
for _, db := range dbs {
199+
receiverName := fmt.Sprintf(
200+
"sqlquery/%s-%s", querySet.Name, db)
201+
config.Receivers[receiverName] = map[string]any{
202+
"driver": "postgres",
203+
"datasource": fmt.Sprintf(
204+
`host=localhost dbname=%s port=5432 user=%s password=${env:PGPASSWORD}`,
205+
db,
206+
MonitoringUser),
207+
"collection_interval": querySet.CollectionInterval,
208+
// Give Postgres time to finish setup.
209+
"initial_delay": "15s",
210+
"queries": "${file:/etc/otel-collector/" +
211+
querySet.Name + "/" + querySet.Queries.Key + "}",
212+
}
213+
214+
// Add the receiver to the pipeline
215+
pipeline := config.Pipelines[PostgresMetrics]
216+
pipeline.Receivers = append(pipeline.Receivers, receiverName)
217+
config.Pipelines[PostgresMetrics] = pipeline
210218
}
211-
212-
// Add the receiver to the pipeline
213-
pipeline := config.Pipelines[PostgresMetrics]
214-
pipeline.Receivers = append(pipeline.Receivers, receiverName)
215-
config.Pipelines[PostgresMetrics] = pipeline
216219
}
217220
}
218221
if inCluster.Spec.Instrumentation.Metrics.PerDBMetricTargets != nil {

pkg/apis/postgres-operator.crunchydata.com/v1beta1/instrumentation_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ type InstrumentationCustomQueries struct {
165165
// +optional
166166
CollectionInterval *Duration `json:"collectionInterval,omitempty"`
167167

168-
// The database to target with added custom queries.
168+
// The databases to target with added custom queries.
169169
// Default behavior is to target `postgres`.
170170
// ---
171171
// +optional
172-
Database string `json:"database,omitempty"`
172+
Databases []string `json:"databases,omitempty"`
173173
}
174174

175175
// ---

pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/kuttl/e2e/otel-logging-and-metrics/18-assert-custom-queries-per-db.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ commands:
2828
retry "custom metric not found for pikachu db"
2929
exit 1
3030
}
31-
{ ! contains "${scrape_metrics}" 'ccp_table_size_bytes_1{dbname="onix"'; } || {
31+
{ contains "${scrape_metrics}" 'ccp_table_size_bytes_1{dbname="onix"'; } || {
3232
retry "custom metric found for onix db"
3333
exit 1
3434
}

testing/kuttl/e2e/otel-logging-and-metrics/files/17--add-custom-queries-per-db.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ spec:
99
customQueries:
1010
add:
1111
- name: custom1
12-
database: pikachu
12+
databases: [pikachu, onix]
1313
queries:
1414
name: my-custom-queries2
1515
key: custom1.yaml
1616
- name: custom2
17-
database: onix
17+
databases: [onix]
1818
queries:
1919
name: my-custom-queries2
2020
key: custom2.yaml

0 commit comments

Comments
 (0)