From 3d59b342b0a648f03942d1d6f96660c5e78c7ca1 Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Mon, 22 Mar 2021 17:31:56 +0000 Subject: [PATCH] Propagate registration error (#34) --- internal/setup/setup.go | 6 +++--- sql/collector.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/setup/setup.go b/internal/setup/setup.go index 72a0b8a..cdec817 100644 --- a/internal/setup/setup.go +++ b/internal/setup/setup.go @@ -55,7 +55,7 @@ func (f *File) Register(c *sql.Collector) error { logx.Debug.Println("Unregister:", ok) if !ok { // This is a fatal error. If the - return fmt.Errorf("Failed to unregister %q", f.Name) + return fmt.Errorf("failed to unregister %q", f.Name) } f.c = nil } @@ -65,10 +65,10 @@ func (f *File) Register(c *sql.Collector) error { // While collector Update could fail transiently, this may be a fatal error. return err } - logx.Debug.Println("Register: success:", f.Name) + logx.Debug.Println("Register:", f.Name, c.RegisterErr) // Save the registered collector. f.c = c - return nil + return c.RegisterErr } // Update runs the collector query again. diff --git a/sql/collector.go b/sql/collector.go index fe1f127..3f01188 100644 --- a/sql/collector.go +++ b/sql/collector.go @@ -51,6 +51,9 @@ type Collector struct { metrics []Metric // mux locks access to types above. mux sync.Mutex + + // RegisterErr contains any error during registration. This should be considered fatal. + RegisterErr error } // NewCollector creates a new BigQuery Collector instance. @@ -76,6 +79,7 @@ func (col *Collector) Describe(ch chan<- *prometheus.Desc) { err := col.Update() if err != nil { log.Println(err) + col.RegisterErr = err } col.setDesc() }