Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user label to PR metric #101

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions exporter/metrics.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package exporter

import "github.com/prometheus/client_golang/prometheus"
import "strconv"
import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
)

// AddMetrics - Add's all of the metrics to a map of strings, returns the map.
func AddMetrics() map[string]*prometheus.Desc {
Expand All @@ -21,7 +24,7 @@ func AddMetrics() map[string]*prometheus.Desc {
APIMetrics["PullRequestCount"] = prometheus.NewDesc(
prometheus.BuildFQName("github", "repo", "pull_request_count"),
"Total number of pull requests for given repository",
[]string{"repo"}, nil,
[]string{"repo", "user"}, nil,
)
APIMetrics["Watchers"] = prometheus.NewDesc(
prometheus.BuildFQName("github", "repo", "watchers"),
Expand Down Expand Up @@ -85,7 +88,7 @@ func (e *Exporter) processMetrics(data []*Datum, rates *RateLimits, ch chan<- pr
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)

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

// Set Rate limit stats
Expand Down
2 changes: 1 addition & 1 deletion test/github_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGithubExporter(t *testing.T) {
Assert(bodyContains(`github_rate_remaining 60`)).
Assert(bodyContains(`github_rate_reset 1.566853865e+09`)).
Assert(bodyContains(`github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 10`)).
Assert(bodyContains(`github_repo_pull_request_count{repo="myRepo"} 3`)).
Assert(bodyContains(`github_repo_pull_request_count{repo="myRepo",user="myOrg"} 3`)).
Assert(bodyContains(`github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 2`)).
Assert(bodyContains(`github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 946`)).
Assert(bodyContains(`github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="myRepo",user="myOrg"} 120`)).
Expand Down
Loading