debian-mirror-gitlab/lib/gitlab/usage/metrics/instrumentations/aggregated_metric.rb
2023-01-12 18:35:48 +00:00

62 lines
1.6 KiB
Ruby

# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
# Usage example
#
# In metric YAML definition:
#
# instrumentation_class: AggregatedMetric
# data_source: redis_hll
# options:
# aggregate:
# operator: OR
# attribute: user_id
# events:
# - 'incident_management_alert_status_changed'
# - 'incident_management_alert_assigned'
# - 'incident_management_alert_todo'
# - 'incident_management_alert_create_incident'
class AggregatedMetric < BaseMetric
FALLBACK = -1
def initialize(metric_definition)
super
@source = metric_definition[:data_source]
@aggregate = options.fetch(:aggregate, {})
end
def value
alt_usage_data(fallback: FALLBACK) do
Aggregates::Aggregate
.new(Time.current)
.calculate_count_for_aggregation(
aggregation: aggregate_config,
time_frame: time_frame
)
end
end
def suggested_name
Gitlab::Usage::Metrics::NameSuggestion.for(:alt)
end
private
attr_accessor :source, :aggregate
def aggregate_config
{
source: source,
events: options[:events],
operator: aggregate[:operator]
}
end
end
end
end
end
end