Skip to content

Commit 64d16af

Browse files
Merge pull request #101 from marctc/fix_user_label
Add user label to PR metric
2 parents 880f5bb + dee44bf commit 64d16af

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

exporter/metrics.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package exporter
22

3-
import "github.com/prometheus/client_golang/prometheus"
4-
import "strconv"
3+
import (
4+
"strconv"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
)
58

69
// AddMetrics - Add's all of the metrics to a map of strings, returns the map.
710
func AddMetrics() map[string]*prometheus.Desc {
@@ -21,7 +24,7 @@ func AddMetrics() map[string]*prometheus.Desc {
2124
APIMetrics["PullRequestCount"] = prometheus.NewDesc(
2225
prometheus.BuildFQName("github", "repo", "pull_request_count"),
2326
"Total number of pull requests for given repository",
24-
[]string{"repo"}, nil,
27+
[]string{"repo", "user"}, nil,
2528
)
2629
APIMetrics["Watchers"] = prometheus.NewDesc(
2730
prometheus.BuildFQName("github", "repo", "watchers"),
@@ -85,7 +88,7 @@ func (e *Exporter) processMetrics(data []*Datum, rates *RateLimits, ch chan<- pr
8588
ch <- prometheus.MustNewConstMetric(e.APIMetrics["OpenIssues"], prometheus.GaugeValue, (x.OpenIssues - float64(prCount)), x.Name, x.Owner.Login, strconv.FormatBool(x.Private), strconv.FormatBool(x.Fork), strconv.FormatBool(x.Archived), x.License.Key, x.Language)
8689

8790
// prCount
88-
ch <- prometheus.MustNewConstMetric(e.APIMetrics["PullRequestCount"], prometheus.GaugeValue, float64(prCount), x.Name)
91+
ch <- prometheus.MustNewConstMetric(e.APIMetrics["PullRequestCount"], prometheus.GaugeValue, float64(prCount), x.Name, x.Owner.Login)
8992
}
9093

9194
// Set Rate limit stats

test/github_exporter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestGithubExporter(t *testing.T) {
4242
Assert(bodyContains(`github_rate_remaining 60`)).
4343
Assert(bodyContains(`github_rate_reset 1.566853865e+09`)).
4444
Assert(bodyContains(`github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 10`)).
45-
Assert(bodyContains(`github_repo_pull_request_count{repo="myRepo"} 3`)).
45+
Assert(bodyContains(`github_repo_pull_request_count{repo="myRepo",user="myOrg"} 3`)).
4646
Assert(bodyContains(`github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 2`)).
4747
Assert(bodyContains(`github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 946`)).
4848
Assert(bodyContains(`github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 120`)).

0 commit comments

Comments
 (0)