Skip to content

Commit 60adb5c

Browse files
authored
Merge pull request #176 from aw/cf-fix-race
Fix race condition where Add was run within the callee instead of caller
2 parents 73c3896 + 574ce1e commit 60adb5c

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,19 @@ func fetchMetrics() {
108108
accounts := fetchAccounts()
109109

110110
for _, a := range accounts {
111+
wg.Add(1)
111112
go fetchWorkerAnalytics(a, &wg)
113+
114+
wg.Add(1)
112115
go fetchLogpushAnalyticsForAccount(a, &wg)
116+
117+
wg.Add(1)
113118
go fetchR2StorageForAccount(a, &wg)
119+
120+
wg.Add(1)
114121
go fetchLoadblancerPoolsHealth(a, &wg)
122+
123+
wg.Add(1)
115124
go fetchZeroTrustAnalyticsForAccount(a, &wg)
116125
}
117126

@@ -126,19 +135,33 @@ func fetchMetrics() {
126135

127136
zoneCount := len(filteredZones)
128137
if zoneCount > 0 && zoneCount <= cfgraphqlreqlimit {
138+
wg.Add(1)
129139
go fetchZoneAnalytics(filteredZones, &wg)
140+
141+
wg.Add(1)
130142
go fetchZoneColocationAnalytics(filteredZones, &wg)
143+
144+
wg.Add(1)
131145
go fetchLoadBalancerAnalytics(filteredZones, &wg)
146+
147+
wg.Add(1)
132148
go fetchLogpushAnalyticsForZone(filteredZones, &wg)
133149
} else if zoneCount > cfgraphqlreqlimit {
134150
for s := 0; s < zoneCount; s += cfgraphqlreqlimit {
135151
e := s + cfgraphqlreqlimit
136152
if e > zoneCount {
137153
e = zoneCount
138154
}
155+
wg.Add(1)
139156
go fetchZoneAnalytics(filteredZones[s:e], &wg)
157+
158+
wg.Add(1)
140159
go fetchZoneColocationAnalytics(filteredZones[s:e], &wg)
160+
161+
wg.Add(1)
141162
go fetchLoadBalancerAnalytics(filteredZones[s:e], &wg)
163+
164+
wg.Add(1)
142165
go fetchLogpushAnalyticsForZone(filteredZones[s:e], &wg)
143166
}
144167
}

prometheus.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ func mustRegisterMetrics(deniedMetrics MetricsSet) {
496496
}
497497

498498
func fetchLoadblancerPoolsHealth(account cfaccounts.Account, wg *sync.WaitGroup) {
499-
wg.Add(1)
500499
defer wg.Done()
501500

502501
pools := fetchLoadblancerPools(account)
@@ -531,7 +530,6 @@ func fetchLoadblancerPoolsHealth(account cfaccounts.Account, wg *sync.WaitGroup)
531530
}
532531

533532
func fetchWorkerAnalytics(account cfaccounts.Account, wg *sync.WaitGroup) {
534-
wg.Add(1)
535533
defer wg.Done()
536534

537535
r, err := fetchWorkerTotals(account.ID)
@@ -560,7 +558,6 @@ func fetchWorkerAnalytics(account cfaccounts.Account, wg *sync.WaitGroup) {
560558
}
561559

562560
func fetchLogpushAnalyticsForAccount(account cfaccounts.Account, wg *sync.WaitGroup) {
563-
wg.Add(1)
564561
defer wg.Done()
565562

566563
if viper.GetBool("free_tier") {
@@ -585,7 +582,6 @@ func fetchLogpushAnalyticsForAccount(account cfaccounts.Account, wg *sync.WaitGr
585582
}
586583

587584
func fetchR2StorageForAccount(account cfaccounts.Account, wg *sync.WaitGroup) {
588-
wg.Add(1)
589585
defer wg.Done()
590586

591587
r, err := fetchR2Account(account.ID)
@@ -607,7 +603,6 @@ func fetchR2StorageForAccount(account cfaccounts.Account, wg *sync.WaitGroup) {
607603
}
608604

609605
func fetchLogpushAnalyticsForZone(zones []cfzones.Zone, wg *sync.WaitGroup) {
610-
wg.Add(1)
611606
defer wg.Done()
612607

613608
if viper.GetBool("free_tier") {
@@ -636,7 +631,6 @@ func fetchLogpushAnalyticsForZone(zones []cfzones.Zone, wg *sync.WaitGroup) {
636631
}
637632

638633
func fetchZoneColocationAnalytics(zones []cfzones.Zone, wg *sync.WaitGroup) {
639-
wg.Add(1)
640634
defer wg.Done()
641635

642636
// Colocation metrics are not available in non-enterprise zones
@@ -666,7 +660,6 @@ func fetchZoneColocationAnalytics(zones []cfzones.Zone, wg *sync.WaitGroup) {
666660
}
667661

668662
func fetchZoneAnalytics(zones []cfzones.Zone, wg *sync.WaitGroup) {
669-
wg.Add(1)
670663
defer wg.Done()
671664

672665
// None of the below referenced metrics are available in the free tier
@@ -818,7 +811,6 @@ func addHTTPAdaptiveGroups(z *zoneResp, name string, account string) {
818811
}
819812

820813
func fetchLoadBalancerAnalytics(zones []cfzones.Zone, wg *sync.WaitGroup) {
821-
wg.Add(1)
822814
defer wg.Done()
823815

824816
// None of the below referenced metrics are available in the free tier
@@ -872,7 +864,6 @@ func addLoadBalancingRequestsAdaptive(z *lbResp, name string, account string) {
872864
}
873865

874866
func fetchZeroTrustAnalyticsForAccount(account cfaccounts.Account, wg *sync.WaitGroup) {
875-
wg.Add(1)
876867
defer wg.Done()
877868

878869
addCloudflareTunnelStatus(account)

0 commit comments

Comments
 (0)