From fa0fe1b538b2abd326f02762cec1be64591aebcb Mon Sep 17 00:00:00 2001 From: Stnby Date: Wed, 27 Jul 2022 12:20:54 +0300 Subject: [PATCH] Filter non Free plan zones from graphql metrics (#70) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Laurynas Četyrkinas --- cloudflare.go | 9 +++++++++ prometheus.go | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cloudflare.go b/cloudflare.go index abd5aa6..39ebd3b 100644 --- a/cloudflare.go +++ b/cloudflare.go @@ -598,3 +598,12 @@ func extractZoneIDs(zones []cloudflare.Zone) []string { return IDs } + +func filterNonFreePlanZones(zones []cloudflare.Zone) (filteredZones []cloudflare.Zone) { + for _, z := range zones { + if z.Plan.ZonePlanCommon.ID != "0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee" { + filteredZones = append(filteredZones, z) + } + } + return +} diff --git a/prometheus.go b/prometheus.go index a1110b4..1b8fe6e 100644 --- a/prometheus.go +++ b/prometheus.go @@ -228,7 +228,11 @@ func fetchZoneColocationAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) { if cfgFreeTier { return } - zoneIDs := extractZoneIDs(zones) + + zoneIDs := extractZoneIDs(filterNonFreePlanZones(zones)) + if len(zoneIDs) == 0 { + return + } r, err := fetchColoTotals(zoneIDs) if err != nil { @@ -256,7 +260,10 @@ func fetchZoneAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) { return } - zoneIDs := extractZoneIDs(zones) + zoneIDs := extractZoneIDs(filterNonFreePlanZones(zones)) + if len(zoneIDs) == 0 { + return + } r, err := fetchZoneTotals(zoneIDs) if err != nil { @@ -389,7 +396,10 @@ func fetchLoadBalancerAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) { return } - zoneIDs := extractZoneIDs(zones) + zoneIDs := extractZoneIDs(filterNonFreePlanZones(zones)) + if len(zoneIDs) == 0 { + return + } l, err := fetchLoadBalancerTotals(zoneIDs) if err != nil {