summaryrefslogtreecommitdiff
path: root/doc/development/usage_ping/metrics_instrumentation.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/development/usage_ping/metrics_instrumentation.md')
-rw-r--r--doc/development/usage_ping/metrics_instrumentation.md40
1 files changed, 26 insertions, 14 deletions
diff --git a/doc/development/usage_ping/metrics_instrumentation.md b/doc/development/usage_ping/metrics_instrumentation.md
index 2cb24fab6cc..ff0dbf99a09 100644
--- a/doc/development/usage_ping/metrics_instrumentation.md
+++ b/doc/development/usage_ping/metrics_instrumentation.md
@@ -26,7 +26,7 @@ A metric definition has the [`instrumentation_class`](metrics_dictionary.md) fie
The defined instrumentation class should have one of the existing metric classes: `DatabaseMetric`, `RedisHLLMetric`, or `GenericMetric`.
-Using the instrumentation classes ensures that metrics can fail safe individually, without breaking the entire
+Using the instrumentation classes ensures that metrics can fail safe individually, without breaking the entire
process of Usage Ping generation.
We have built a domain-specific language (DSL) to define the metrics instrumentation.
@@ -53,20 +53,17 @@ end
## Redis HyperLogLog metrics
-[Example of a merge request that adds a `RedisHLL` metric](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60089/diffs).
+[Example of a merge request that adds a `RedisHLL` metric](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61685).
-```ruby
-module Gitlab
- module Usage
- module Metrics
- module Instrumentations
- class CountUsersUsingApproveQuickActionMetric < RedisHLLMetric
- event_names :i_quickactions_approve
- end
- end
- end
- end
-end
+Count unique values for `i_quickactions_approve` event.
+
+```yaml
+time_frame: 28d
+data_source: redis_hll
+instrumentation_class: 'Gitlab::Usage::Metrics::Instrumentations::RedisHLLMetric'
+options:
+ events:
+ - i_quickactions_approve
```
## Generic metrics
@@ -88,3 +85,18 @@ module Gitlab
end
end
```
+
+## Creating a new metric instrumentation class
+
+To create a stub instrumentation for a Usage Ping metric, you can use a dedicated [generator](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/generators/gitlab/usage_metric_generator.rb):
+
+The generator takes the class name as an argument and the following options:
+
+- `--type=TYPE` Required. Indicates the metric type. It must be one of: `database`, `generic`, `redis_hll`.
+- `--ee` Indicates if the metric is for EE.
+
+```shell
+rails generate gitlab:usage_metric CountIssues --type database
+ create lib/gitlab/usage/metrics/instrumentations/count_issues_metric.rb
+ create spec/lib/gitlab/usage/metrics/instrumentations/count_issues_metric_spec.rb
+```