Skip to content

Commit 0923698

Browse files
Do not try to return metric descriptors in Describe
Since we cannot know in advance the metrics which the exporter will generate, the workaround is to run a Collect and return the metric descriptors. This is problematic when the connection to the PostgreSQL instance cannot be established straight from the start. This patch makes Describe return no descriptors, effectively turning the collector in an unchecked one, which we're in the typical use case here: https://pkg.go.dev/github.com/prometheus/client_golang/prometheus?tab=doc#hdr-Custom_Collectors_and_constant_Metrics. Signed-off-by: Yann Soubeyrand <[email protected]>
1 parent 91c5150 commit 0923698

File tree

1 file changed

+0
-23
lines changed

1 file changed

+0
-23
lines changed

cmd/postgres_exporter/postgres_exporter.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,29 +1147,6 @@ func (e *Exporter) setupInternalMetrics() {
11471147

11481148
// Describe implements prometheus.Collector.
11491149
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
1150-
// We cannot know in advance what metrics the exporter will generate
1151-
// from Postgres. So we use the poor man's describe method: Run a collect
1152-
// and send the descriptors of all the collected metrics. The problem
1153-
// here is that we need to connect to the Postgres DB. If it is currently
1154-
// unavailable, the descriptors will be incomplete. Since this is a
1155-
// stand-alone exporter and not used as a library within other code
1156-
// implementing additional metrics, the worst that can happen is that we
1157-
// don't detect inconsistent metrics created by this exporter
1158-
// itself. Also, a change in the monitored Postgres instance may change the
1159-
// exported metrics during the runtime of the exporter.
1160-
metricCh := make(chan prometheus.Metric)
1161-
doneCh := make(chan struct{})
1162-
1163-
go func() {
1164-
for m := range metricCh {
1165-
ch <- m.Desc()
1166-
}
1167-
close(doneCh)
1168-
}()
1169-
1170-
e.Collect(metricCh)
1171-
close(metricCh)
1172-
<-doneCh
11731150
}
11741151

11751152
// Collect implements prometheus.Collector.

0 commit comments

Comments
 (0)