From 9bbb25e3c7c4cc5cd355edb3a122f8c7812e32db Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Sat, 5 Dec 2020 10:55:14 +0000 Subject: [PATCH] Fix a bug that caused the services list to keep growing This patch changes the code which looks up service and appends them to the Exporter's list. It previously would create an endless list and cause a memory leak. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- gateway/metrics/exporter.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gateway/metrics/exporter.go b/gateway/metrics/exporter.go index c3e5c0a3..b46d1b3d 100644 --- a/gateway/metrics/exporter.go +++ b/gateway/metrics/exporter.go @@ -92,8 +92,11 @@ func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions Metri log.Println(err) } + services := []types.FunctionStatus{} + + // Providers like Docker Swarm for instance have no namespaces. if len(namespaces) == 0 { - services, err := e.getFunctions(endpointURL, e.FunctionNamespace) + services, err = e.getFunctions(endpointURL, e.FunctionNamespace) if err != nil { log.Println(err) continue @@ -101,15 +104,17 @@ func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions Metri e.services = services } else { for _, namespace := range namespaces { - services, err := e.getFunctions(endpointURL, namespace) + nsServices, err := e.getFunctions(endpointURL, namespace) if err != nil { log.Println(err) continue } - e.services = append(e.services, services...) + services = append(services, nsServices...) } } + e.services = services + break case <-quit: return