Skip to content

Commit b0451f1

Browse files
committed
OTel: Allow users to add metrics exporters.
1 parent 8f4e976 commit b0451f1

File tree

8 files changed

+54
-4
lines changed

8 files changed

+54
-4
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,13 @@ spec:
23012301
type: string
23022302
type: array
23032303
type: object
2304+
exporters:
2305+
description: The names of exporters that should send metrics.
2306+
items:
2307+
type: string
2308+
minItems: 1
2309+
type: array
2310+
x-kubernetes-list-type: set
23042311
perDBMetricTargets:
23052312
description: User defined databases to target for default
23062313
per-db metrics

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12146,6 +12146,13 @@ spec:
1214612146
type: string
1214712147
type: array
1214812148
type: object
12149+
exporters:
12150+
description: The names of exporters that should send metrics.
12151+
items:
12152+
type: string
12153+
minItems: 1
12154+
type: array
12155+
x-kubernetes-list-type: set
1214912156
perDBMetricTargets:
1215012157
description: User defined databases to target for default
1215112158
per-db metrics

internal/collector/naming.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const DebugExporter = "debug"
99
const LogsBatchProcessor = "batch/logs"
1010
const OneSecondBatchProcessor = "batch/1s"
1111
const SubSecondBatchProcessor = "batch/200ms"
12-
const Prometheus = "prometheus"
12+
const Prometheus = "prometheus/cpk-monitoring"
1313
const PrometheusPort = 9187
1414
const PGBouncerMetrics = "metrics/pgbouncer"
1515
const PostgresMetrics = "metrics/postgres"

internal/collector/patroni.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,22 @@ func EnablePatroniMetrics(ctx context.Context,
168168
},
169169
}
170170

171+
// If there are exporters to be added to the metrics pipelines defined
172+
// in the spec, add them to the pipeline.
173+
exporters := []ComponentID{Prometheus}
174+
if inCluster.Spec.Instrumentation.Metrics != nil &&
175+
inCluster.Spec.Instrumentation.Metrics.Exporters != nil {
176+
exporters = append(exporters, inCluster.Spec.Instrumentation.Metrics.Exporters...)
177+
}
178+
171179
// Add Metrics Pipeline
172180
outConfig.Pipelines[PatroniMetrics] = Pipeline{
173181
Receivers: []ComponentID{Prometheus},
174182
Processors: []ComponentID{
175183
SubSecondBatchProcessor,
176184
CompactingProcessor,
177185
},
178-
Exporters: []ComponentID{Prometheus},
186+
Exporters: exporters,
179187
}
180188
}
181189
}

internal/collector/pgbouncer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,22 @@ func EnablePgBouncerMetrics(ctx context.Context, inCluster *v1beta1.PostgresClus
187187
"queries": slices.Clone(pgBouncerMetricsQueries),
188188
}
189189

190+
// If there are exporters to be added to the metrics pipelines defined
191+
// in the spec, add them to the pipeline.
192+
exporters := []ComponentID{Prometheus}
193+
if inCluster.Spec.Instrumentation.Metrics != nil &&
194+
inCluster.Spec.Instrumentation.Metrics.Exporters != nil {
195+
exporters = append(exporters, inCluster.Spec.Instrumentation.Metrics.Exporters...)
196+
}
197+
190198
// Add Metrics Pipeline
191199
config.Pipelines[PGBouncerMetrics] = Pipeline{
192200
Receivers: []ComponentID{SqlQuery},
193201
Processors: []ComponentID{
194202
SubSecondBatchProcessor,
195203
CompactingProcessor,
196204
},
197-
Exporters: []ComponentID{Prometheus},
205+
Exporters: exporters,
198206
}
199207
}
200208
}

internal/collector/postgres_metrics.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,22 @@ func EnablePostgresMetrics(ctx context.Context, inCluster *v1beta1.PostgresClust
171171
"queries": slices.Clone(fiveMinuteMetricsClone),
172172
}
173173

174+
// If there are exporters to be added to the metrics pipelines defined
175+
// in the spec, add them to the pipeline.
176+
exporters := []ComponentID{Prometheus}
177+
if inCluster.Spec.Instrumentation.Metrics != nil &&
178+
inCluster.Spec.Instrumentation.Metrics.Exporters != nil {
179+
exporters = append(exporters, inCluster.Spec.Instrumentation.Metrics.Exporters...)
180+
}
181+
174182
// Add Metrics Pipeline
175183
config.Pipelines[PostgresMetrics] = Pipeline{
176184
Receivers: []ComponentID{FiveSecondSqlQuery, FiveMinuteSqlQuery},
177185
Processors: []ComponentID{
178186
SubSecondBatchProcessor,
179187
CompactingProcessor,
180188
},
181-
Exporters: []ComponentID{Prometheus},
189+
Exporters: exporters,
182190
}
183191

184192
// Add custom queries and per-db metrics if they are defined in the spec

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ type InstrumentationMetricsSpec struct {
117117
// +optional
118118
CustomQueries *InstrumentationCustomQueriesSpec `json:"customQueries,omitempty"`
119119

120+
// The names of exporters that should send metrics.
121+
// ---
122+
// +kubebuilder:validation:MinItems=1
123+
// +listType=set
124+
// +optional
125+
Exporters []string `json:"exporters,omitempty"`
126+
120127
// User defined databases to target for default per-db metrics
121128
// ---
122129
// +optional

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.

0 commit comments

Comments
 (0)