diff --git a/collector/artifactregistry.go b/collector/artifactregistry.go index 8fcffbd..1e6a88a 100644 --- a/collector/artifactregistry.go +++ b/collector/artifactregistry.go @@ -89,7 +89,11 @@ func (c *ArtifactRegistryCollector) Collect(ch chan<- prometheus.Metric) { // Probably (!) Artifact Registry API has not been enabled for Project (p) return } + + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } + log.Println(err) return } diff --git a/collector/cloudrun.go b/collector/cloudrun.go index 59ad9fb..5654f7b 100644 --- a/collector/cloudrun.go +++ b/collector/cloudrun.go @@ -95,7 +95,11 @@ func (c *CloudRunCollector) Collect(ch chan<- prometheus.Metric) { // Probably (!) Cloud Run Admin API has not been used in this project return } + + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } + log.Println(err) return } @@ -143,7 +147,11 @@ func (c *CloudRunCollector) Collect(ch chan<- prometheus.Metric) { // Probably (!) Cloud Run Admin API has not been used in this project return } + + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } + log.Println(err) return } diff --git a/collector/endpoints.go b/collector/endpoints.go index a60c69e..80d258e 100644 --- a/collector/endpoints.go +++ b/collector/endpoints.go @@ -75,8 +75,11 @@ func (c *EndpointsCollector) Collect(ch chan<- prometheus.Metric) { // Probably Service Management API has not been enabled for Project (p) return } + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } + log.Println(err) return } diff --git a/collector/eventarc.go b/collector/eventarc.go index d533967..319af4e 100644 --- a/collector/eventarc.go +++ b/collector/eventarc.go @@ -9,7 +9,6 @@ import ( "github.com/DazWilkin/gcp-exporter/gcp" "github.com/prometheus/client_golang/prometheus" - "google.golang.org/api/cloudresourcemanager/v1" "google.golang.org/api/eventarc/v1" "google.golang.org/api/googleapi" ) @@ -70,7 +69,7 @@ func (c *EventarcCollector) Collect(ch chan<- prometheus.Metric) { // Channels wg.Add(1) - go func(p *cloudresourcemanager.Project) { + go func() { defer wg.Done() rqst := eventarcService.Projects.Locations.Channels.List(parent) @@ -81,7 +80,9 @@ func (c *EventarcCollector) Collect(ch chan<- prometheus.Metric) { // Probably (!) Eventarc API has not enabled in this Project return } - log.Printf("Google API Error: %d (%s)", e.Code, e.Message) + + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } log.Println(err) @@ -102,11 +103,11 @@ func (c *EventarcCollector) Collect(ch chan<- prometheus.Metric) { }..., ) } - }(p) + }() // Triggers wg.Add(1) - go func(p *cloudresourcemanager.Project) { + go func() { defer wg.Done() rqst := eventarcService.Projects.Locations.Triggers.List(parent) @@ -117,7 +118,9 @@ func (c *EventarcCollector) Collect(ch chan<- prometheus.Metric) { // Probably (!) Eventarc API has not enabled in this Project return } - log.Printf("Google API Error: %d (%s)", e.Code, e.Message) + + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } log.Println(err) @@ -152,7 +155,7 @@ func (c *EventarcCollector) Collect(ch chan<- prometheus.Metric) { }..., ) } - }(p) + }() } wg.Wait() } diff --git a/collector/functions.go b/collector/functions.go index f325ddd..24ba819 100644 --- a/collector/functions.go +++ b/collector/functions.go @@ -96,8 +96,11 @@ func (c *FunctionsCollector) Collect(ch chan<- prometheus.Metric) { // Probably (!) Cloud Functions API has not been enabled for Project (p) return } + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } + log.Println(err) return } diff --git a/collector/kubernetes.go b/collector/kubernetes.go index f1b67a1..1724dc7 100644 --- a/collector/kubernetes.go +++ b/collector/kubernetes.go @@ -72,7 +72,9 @@ func (c *KubernetesCollector) Collect(ch chan<- prometheus.Metric) { // Probably (!) Kubernetes Engine API has not been enabled for Project (p) return } + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return } log.Println(err) diff --git a/collector/scheduler.go b/collector/scheduler.go index 057e923..47270d0 100644 --- a/collector/scheduler.go +++ b/collector/scheduler.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "net/http" "sync" "github.com/DazWilkin/gcp-exporter/gcp" @@ -11,6 +12,7 @@ import ( cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1" cloudscheduler "google.golang.org/api/cloudscheduler/v1" + "google.golang.org/api/googleapi" ) var ( @@ -77,12 +79,27 @@ func (c *SchedulerCollector) Collect(ch chan<- prometheus.Metric) { // } return nil }); err != nil { + if e, ok := err.(*googleapi.Error); ok { + log.Printf("Google API Error: %d [%s]", e.Code, e.Message) + return nil + } + log.Println(err) return nil } } return nil }); err != nil { + if e, ok := err.(*googleapi.Error); ok { + if e.Code == http.StatusForbidden { + // Probably (!) Cloud Scheduler API has not been enabled for Project (p) + return + } + + log.Printf("Googe API Error: %d (%s)", e.Code, e.Message) + return + } + log.Println(err) return }