From 26a34fb449d3fa11c1d78580c5c4e287b27a3559 Mon Sep 17 00:00:00 2001 From: Pureewat Kaewpoi Date: Fri, 5 Jan 2024 16:27:40 +0700 Subject: [PATCH 1/2] checking for datastore is being deleted --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 5dc08e1..c8966e1 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "net/http" "os" + "regexp" "strconv" "time" @@ -491,6 +492,17 @@ func (e *Exporter) getDatastoreMetric(datastore Datastore, ch chan<- prometheus. // check if status code is 200 if resp.StatusCode != 200 { + if resp.StatusCode == 400 { + // check if + isBeingDeleted, err := regexp.MatchString("(?i)datastore is being deleted", string(body[:])) + if err != nil { + return err + } + if isBeingDeleted { + log.Printf("INFO: Datastore: %s is being deleted, Skip scrape datastore metric", datastore.Store) + return nil + } + } return fmt.Errorf("ERROR: --Status code %d returned from endpoint: %s", resp.StatusCode, e.endpoint) } From aa2a43ff93506202fe24f282d6edcc2779e6fbcb Mon Sep 17 00:00:00 2001 From: Pureewat Kaewpoi Date: Fri, 5 Jan 2024 16:33:44 +0700 Subject: [PATCH 2/2] fix typo --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index c8966e1..1e6686d 100644 --- a/main.go +++ b/main.go @@ -493,7 +493,7 @@ func (e *Exporter) getDatastoreMetric(datastore Datastore, ch chan<- prometheus. // check if status code is 200 if resp.StatusCode != 200 { if resp.StatusCode == 400 { - // check if + // check if datastore is being deleted isBeingDeleted, err := regexp.MatchString("(?i)datastore is being deleted", string(body[:])) if err != nil { return err