diff options
Diffstat (limited to 'doc/development/service_ping/metrics_instrumentation.md')
-rw-r--r-- | doc/development/service_ping/metrics_instrumentation.md | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/doc/development/service_ping/metrics_instrumentation.md b/doc/development/service_ping/metrics_instrumentation.md index 61a1ff828be..8ad1ae9cce2 100644 --- a/doc/development/service_ping/metrics_instrumentation.md +++ b/doc/development/service_ping/metrics_instrumentation.md @@ -11,7 +11,7 @@ This guide describes how to develop Service Ping metrics using metrics instrumen ## Nomenclature - **Instrumentation class**: - - Inherits one of the metric classes: `DatabaseMetric`, `RedisHLLMetric` or `GenericMetric`. + - Inherits one of the metric classes: `DatabaseMetric`, `RedisMetric`, `RedisHLLMetric` or `GenericMetric`. - Implements the logic that calculates the value for a Service Ping metric. - **Metric definition** @@ -24,7 +24,7 @@ This guide describes how to develop Service Ping metrics using metrics instrumen A metric definition has the [`instrumentation_class`](metrics_dictionary.md) field, which can be set to a class. -The defined instrumentation class should have one of the existing metric classes: `DatabaseMetric`, `RedisHLLMetric`, or `GenericMetric`. +The defined instrumentation class should have one of the existing metric classes: `DatabaseMetric`, `RedisMetric`, `RedisHLLMetric`, or `GenericMetric`. Using the instrumentation classes ensures that metrics can fail safe individually, without breaking the entire process of Service Ping generation. @@ -51,6 +51,26 @@ module Gitlab end ``` +## Redis metrics + +[Example of a merge request that adds a `Redis` metric](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66582). + +Count unique values for `source_code_pushes` event. + +Required options: + +- `event`: the event name. +- `counter_class`: one of the counter classes from the `Gitlab::UsageDataCounters` namespace; it should implement `read` method or inherit it from `BaseCounter`. + +```yaml +time_frame: all +data_source: redis +instrumentation_class: 'RedisMetric' +options: + event: pushes + counter_class: SourceCodeCounter +``` + ## Redis HyperLogLog metrics [Example of a merge request that adds a `RedisHLL` metric](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61685). @@ -60,7 +80,7 @@ Count unique values for `i_quickactions_approve` event. ```yaml time_frame: 28d data_source: redis_hll -instrumentation_class: 'Gitlab::Usage::Metrics::Instrumentations::RedisHLLMetric' +instrumentation_class: 'RedisHLLMetric' options: events: - i_quickactions_approve @@ -86,13 +106,29 @@ module Gitlab end ``` +## Support for instrumentation classes + +There is support for: + +- `count`, `distinct_count`, `estimate_batch_distinct_count` for [database metrics](#database-metrics). +- [Redis metrics](#redis-metrics). +- [Redis HLL metrics](#redis-hyperloglog-metrics). +- [Generic metrics](#generic-metrics), which are metrics based on settings or configurations. + +Currently, there is no support for: + +- `add`, `sum`, `histogram` for database metrics. + +You can [track the progress to support these](https://gitlab.com/groups/gitlab-org/-/epics/6118). + ## Creating a new metric instrumentation class To create a stub instrumentation for a Service 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`. +- `--type=TYPE` Required. Indicates the metric type. It must be one of: `database`, `generic`, `redis`. +- `--operation` Required for `database` type. It must be one of: `count`, `distinct_count`, `estimate_batch_distinct_count`. - `--ee` Indicates if the metric is for EE. ```shell |