diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-17 00:09:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-17 00:09:48 +0300 |
commit | 9b8433e5ecd54f93ee8df3bb9d9038e978d57afc (patch) | |
tree | b94758d475fe9ffe547eb838fbf15b3910234426 /doc/development/service_ping/implement.md | |
parent | dbfedde341ef6434d40c4c2495f2be751f8bb973 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/service_ping/implement.md')
-rw-r--r-- | doc/development/service_ping/implement.md | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/doc/development/service_ping/implement.md b/doc/development/service_ping/implement.md index 049ca11b3a1..6948eb20e00 100644 --- a/doc/development/service_ping/implement.md +++ b/doc/development/service_ping/implement.md @@ -46,7 +46,7 @@ boards: add_metric('CountBoardsMetric', time_frame: 'all'), There are several types of counters for metrics: -- **[Batch counters](#batch-counters)**: Used for counts and sums. +- **[Batch counters](#batch-counters)**: Used for counts, sums, and averages. - **[Redis counters](#redis-counters):** Used for in-memory counts. - **[Alternative counters](#alternative-counters):** Used for settings and configurations. @@ -111,9 +111,23 @@ Method: add_metric('JiraImportsTotalImportedIssuesCountMetric') ``` +#### Average batch operation + +Average the values of a given `ActiveRecord_Relation` on given column and handles errors. + +Method: + +```ruby +add_metric('CountIssuesWeightAverageMetric') +``` + +Examples: + +Examples using `usage_data.rb` have been [deprecated](usage_data.md). We recommend to use [instrumentation classes](metrics_instrumentation.md). + #### Grouping and batch operations -The `count`, `distinct_count`, and `sum` batch counters can accept an `ActiveRecord::Relation` +The `count`, `distinct_count`, `sum`, and `average` batch counters can accept an `ActiveRecord::Relation` object, which groups by a specified column. With a grouped relation, the methods do batch counting, handle errors, and returns a hash table of key-value pairs. @@ -128,6 +142,9 @@ distinct_count(Project.group(:visibility_level), :creator_id) sum(Issue.group(:state_id), :weight)) # returns => {1=>3542, 2=>6820} + +average(Issue.group(:state_id), :weight)) +# returns => {1=>3.5, 2=>2.5} ``` #### Add operation |