Skip to content

Commit 8c27e97

Browse files
Do not try to return metric descriptors in Describe (prometheus-community#416)
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 c55a3b3 commit 8c27e97

File tree

1 file changed

+0
-23
lines changed

1 file changed

+0
-23
lines changed

cmd/postgres_exporter/postgres_exporter.go

-23
Original file line numberDiff line numberDiff line change
@@ -1236,29 +1236,6 @@ func (e *Exporter) setupInternalMetrics() {
12361236

12371237
// Describe implements prometheus.Collector.
12381238
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
1239-
// We cannot know in advance what metrics the exporter will generate
1240-
// from Postgres. So we use the poor man's describe method: Run a collect
1241-
// and send the descriptors of all the collected metrics. The problem
1242-
// here is that we need to connect to the Postgres DB. If it is currently
1243-
// unavailable, the descriptors will be incomplete. Since this is a
1244-
// stand-alone exporter and not used as a library within other code
1245-
// implementing additional metrics, the worst that can happen is that we
1246-
// don't detect inconsistent metrics created by this exporter
1247-
// itself. Also, a change in the monitored Postgres instance may change the
1248-
// exported metrics during the runtime of the exporter.
1249-
metricCh := make(chan prometheus.Metric)
1250-
doneCh := make(chan struct{})
1251-
1252-
go func() {
1253-
for m := range metricCh {
1254-
ch <- m.Desc()
1255-
}
1256-
close(doneCh)
1257-
}()
1258-
1259-
e.Collect(metricCh)
1260-
close(metricCh)
1261-
<-doneCh
12621239
}
12631240

12641241
// Collect implements prometheus.Collector.

0 commit comments

Comments
 (0)