Skip to content

Commit b03ae31

Browse files
Ensure repos aren't processed twice (#126)
1 parent 6be3c1d commit b03ae31

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.0.1
1+
v2.0.2

exporter/metrics.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,16 @@ func AddMetrics(cfg *config.Config) map[string]*prometheus.Desc {
8787

8888
// processMetrics - processes the response data and sets the metrics using it as a source
8989
func (e *Exporter) processMetrics(data []*Datum, rates *[]RateLimit, ch chan<- prometheus.Metric) error {
90+
processed := make(map[string]struct{})
9091

91-
// APIMetrics - range through the data slice
9292
for _, x := range data {
93+
// Check if we've already processed this repo
94+
repo := fmt.Sprintf("%s/%s", x.Owner.Login, x.Name)
95+
if _, ok := processed[repo]; ok {
96+
continue
97+
}
98+
processed[repo] = struct{}{}
99+
93100
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Stars"], prometheus.GaugeValue, float64(x.Stars), x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
94101
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Forks"], prometheus.GaugeValue, float64(x.Forks), x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
95102
ch <- prometheus.MustNewConstMetric(e.APIMetrics["Watchers"], prometheus.GaugeValue, float64(x.Watchers), x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)

0 commit comments

Comments
 (0)