diff options
author | Romain <romdum@users.noreply.github.com> | 2021-10-04 00:46:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-03 18:46:44 -0400 |
commit | fc5ee1edf90eb826a67921bb8d5c6b3e8c746225 (patch) | |
tree | 92f9987a5ecab529f23f17f07bf52a1cd9a35e08 /modules | |
parent | 89ddbe9699aa2471af34d0e093e6631711482d89 (diff) | |
download | gitea-fc5ee1edf90eb826a67921bb8d5c6b3e8c746225.tar.gz gitea-fc5ee1edf90eb826a67921bb8d5c6b3e8c746225.zip |
Add metrics to get issues by label (#17201)
* Add metrics to get issues by label
* Add comment on IssueByLabelCount
* Code review - Unify "AS" in SQL (#17201)
* Code review - Remove useless join (#17201)
* Code review - Disable issue_by_label by default in settings (#17201)
* use e
* restore empty line
* update docs
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: techknowlogick <matti@mdranta.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/metrics/collector.go | 17 | ||||
-rw-r--r-- | modules/setting/setting.go | 10 |
2 files changed, 22 insertions, 5 deletions
diff --git a/modules/metrics/collector.go b/modules/metrics/collector.go index 29374583d6..dcc147631b 100755 --- a/modules/metrics/collector.go +++ b/modules/metrics/collector.go @@ -24,6 +24,7 @@ type Collector struct { Issues *prometheus.Desc IssuesOpen *prometheus.Desc IssuesClosed *prometheus.Desc + IssuesByLabel *prometheus.Desc Labels *prometheus.Desc LoginSources *prometheus.Desc Milestones *prometheus.Desc @@ -45,6 +46,7 @@ type Collector struct { // NewCollector returns a new Collector with all prometheus.Desc initialized func NewCollector() Collector { + return Collector{ Accesses: prometheus.NewDesc( namespace+"accesses", @@ -81,6 +83,11 @@ func NewCollector() Collector { "Number of Issues", nil, nil, ), + IssuesByLabel: prometheus.NewDesc( + namespace+"issues_by_label", + "Number of Issues", + []string{"label"}, nil, + ), IssuesOpen: prometheus.NewDesc( namespace+"issues_open", "Number of open Issues", @@ -177,7 +184,6 @@ func NewCollector() Collector { nil, nil, ), } - } // Describe returns all possible prometheus.Desc @@ -189,6 +195,7 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) { ch <- c.Follows ch <- c.HookTasks ch <- c.Issues + ch <- c.IssuesByLabel ch <- c.IssuesOpen ch <- c.IssuesClosed ch <- c.Labels @@ -249,6 +256,14 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, float64(stats.Counter.Issue), ) + for _, il := range stats.Counter.IssueByLabel { + ch <- prometheus.MustNewConstMetric( + c.IssuesByLabel, + prometheus.GaugeValue, + float64(il.Count), + il.Label, + ) + } ch <- prometheus.MustNewConstMetric( c.IssuesClosed, prometheus.GaugeValue, diff --git a/modules/setting/setting.go b/modules/setting/setting.go index afd1e49aed..bdb3b1fd7b 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -390,11 +390,13 @@ var ( // Metrics settings Metrics = struct { - Enabled bool - Token string + Enabled bool + Token string + EnabledIssueByLabel bool }{ - Enabled: false, - Token: "", + Enabled: false, + Token: "", + EnabledIssueByLabel: false, } // I18n settings |