Class: Gitlab::Usage::Metrics::Instrumentations::RedisMetric
- Inherits:
-
BaseMetric
- Object
- BaseMetric
- Gitlab::Usage::Metrics::Instrumentations::RedisMetric
- Includes:
- Gitlab::UsageDataCounters::RedisCounter
- Defined in:
- lib/gitlab/usage/metrics/instrumentations/redis_metric.rb
Overview
Usage example
In metric YAML definition:
instrumentation_class: RedisMetric options:
event: pushes
prefix: source_code
Direct Known Subclasses
Constant Summary collapse
- USAGE_PREFIX =
"USAGE_"
- OPTIONS_PREFIX_KEY =
:prefix
Constants included from TimeFrame
TimeFrame::ALL_TIME_TIME_FRAME_NAME, TimeFrame::DEFAULT_TIMESTAMP_COLUMN, TimeFrame::SEVEN_DAYS_TIME_FRAME_NAME, TimeFrame::TWENTY_EIGHT_DAYS_TIME_FRAME_NAME
Constants included from Gitlab::Utils::UsageData
Gitlab::Utils::UsageData::DISTRIBUTED_HLL_FALLBACK, Gitlab::Utils::UsageData::FALLBACK, Gitlab::Utils::UsageData::HISTOGRAM_FALLBACK, Gitlab::Utils::UsageData::MAX_BUCKET_SIZE
Instance Attribute Summary
Attributes inherited from BaseMetric
#events, #options, #time_frame
Instance Method Summary collapse
- #include_usage_prefix? ⇒ Boolean
-
#initialize(metric_definition) ⇒ RedisMetric
constructor
A new instance of RedisMetric.
- #metric_event ⇒ Object
- #prefix ⇒ Object
- #redis_key ⇒ Object
- #validate_options! ⇒ Object
- #value ⇒ Object
Methods included from Gitlab::UsageDataCounters::RedisCounter
#increment, #increment_by, #total_count
Methods inherited from BaseMetric
available?, #available?, #instrumentation
Methods included from TimeFrame
#monthly_time_range, #monthly_time_range_db_params, #weekly_time_range, #weekly_time_range_db_params
Methods included from Gitlab::Utils::UsageData
#add, #add_metric, #alt_usage_data, #average, #count, #distinct_count, #estimate_batch_distinct_count, #histogram, #maximum_id, #measure_duration, #minimum_id, #redis_usage_data, #sum, #track_usage_event, #with_finished_at, #with_metadata, #with_prometheus_client
Constructor Details
#initialize(metric_definition) ⇒ RedisMetric
Returns a new instance of RedisMetric.
22 23 24 25 26 |
# File 'lib/gitlab/usage/metrics/instrumentations/redis_metric.rb', line 22 def initialize(metric_definition) super end |
Instance Method Details
#include_usage_prefix? ⇒ Boolean
41 42 43 |
# File 'lib/gitlab/usage/metrics/instrumentations/redis_metric.rb', line 41 def include_usage_prefix? .fetch(:include_usage_prefix, true) end |
#metric_event ⇒ Object
33 34 35 |
# File 'lib/gitlab/usage/metrics/instrumentations/redis_metric.rb', line 33 def metric_event [:event] end |
#prefix ⇒ Object
37 38 39 |
# File 'lib/gitlab/usage/metrics/instrumentations/redis_metric.rb', line 37 def prefix [OPTIONS_PREFIX_KEY] end |
#redis_key ⇒ Object
51 52 53 54 55 56 |
# File 'lib/gitlab/usage/metrics/instrumentations/redis_metric.rb', line 51 def redis_key key = metric_event.dup key.prepend("#{prefix}_") if prefix key.prepend(USAGE_PREFIX) if include_usage_prefix? key.upcase end |
#validate_options! ⇒ Object
28 29 30 31 |
# File 'lib/gitlab/usage/metrics/instrumentations/redis_metric.rb', line 28 def raise ArgumentError, "'event' option is required" unless metric_event.present? raise ArgumentError, "'prefix' option is required" unless .has_key?(OPTIONS_PREFIX_KEY) end |
#value ⇒ Object
45 46 47 48 49 |
# File 'lib/gitlab/usage/metrics/instrumentations/redis_metric.rb', line 45 def value redis_usage_data do total_count(redis_key) end end |